Php :- Import CSV data to mysql database

Php :- Import CSV data to mysql database


Hey guys i will show you how to import data from a csv file to mysql database, it can be very helpful while creating professional scripts for business needs
Closed Caption:

hey whats up guys welcome back to the
too late . com today i will be showing
you how do you see a speed functionality
into your PHP script because if you will
ever work for a business client i
believe 90 portion of them will ask you
to integrate csv files into your PHP
script so that they can do the csv file
to upload the data to the minus tool
data pins are they can you know get the
data from a database and exploded to csv
file so that what I'm going to show you
today so very first I have a phoner out
here with the name of CSP and i have
created a dummy csv file with the name
of a docsis and next thing would be
doing it would be creating a PHP file to
write our PHP script inside it
okay i'm going to open it with my text
editor and we're just normal PHP tags on
the top and you're on the bottom i'm
going to open the HTML tags nice here
first we need a farm from where we can
actually upload the csv file so i want
to create a farm that would be post
action would be to this particular file
itself and one more thing we need that
would be the eat-in c-type without this
you cannot upload any faults to your
sober so you always need it while
dealing with on image upload a file
notes and this means to be equal to x
art form data so that's where you're
from as compatible to upload any kind of
files next thing would be to create
input section that would be the type
would be equal to file name with the
equal to file
well you would be nothing then i'm going
to give a break tag and actual subject
buddy
with the summit and give this value on
something that's one
ok this is what we have so go ahead and
launch this paper file and let's see
what happens is a local host from me or
I'm gonna browse to folder or cs3 over
here we have now we can actually upload
files from this particular input town be
next thing we have to do is we have to
write the PHP in order to organize the
files which has been uploaded and then
use the data which is already inside
this particular csv file and send it to
a mysql database so very first be on a
set of a database for that I'm gonna
need it to csb as well here we will
create a table let's name it to chest
where 24 fields and we can have ID field
then we can have a name we can have
email that's a first name last name and
email
ok like this first and i'm going to have
asking and the email they all would be
were charmed
what's a name 200 last name 280 male
250r ID would be an auto incremented and
a primary t1 equipment and a primary key
we can finally save this pretty girl
table so we have a database with the
name of CSP and we have a table name
test so right now we will be writing
anything out here we will write to this
particular file we will upload it and
that followed automatically transfer
data to our database so you can imagine
if you have 20,000 customers already
understands we file and you want to
import them to your database you don't
have to do manual entries you can just
upload one file and everything would be
done in a black ops against so what we
need as to build a connection with this
database
I'm gonna say . account will be equal to
mysql commit this is the my school
function to connect to any database so
I'm going to see my host is localhost
you my user is root and I don't have any
password because it's on my local server
or die if you're not able to connect
just really was a mysql error i'm going
to say is you will select TV and the
database is see as we and use the
connection which was connected like that
connection to build that connection next
thing as we have to take the file name
from here the actual five-part in order
to know from where the file is coming
and that is really really easy guys
so what I'm gonna so too because if the
set daughter post submit that means that
the person is reading this topic
then go ahead and create a variable and
put that variable equal to dollar falls
the name of this field that is file that
what I'm going to put out here and the
temporary name of the file because
anytime guys you will upload a file it
will be uploaded with a temporary name
and that temporary name would be equal
to the actual part of the file so don't
worry i'm just going to show you right
now codified so we can upload a file and
see the name will get the name of the
fall so first I want to refresh it
yeah so for now upload this particular
image and submit it says each time
ewww Tom PHP 5 p-9 town so this is the
actual part of the file right now so
what we need to do is we don't have to
wait out we have to use this particular
part in order to upload the data to our
CSV file so I'm gonna say if F gets no
that would be if you get see as we
believe so i'm not sure you know if get
CS weak dollar file and after the
following we need to have the numbers
i'm gonna explain it to you guys just
give me a second with living what write
the entire line that would be the
developmental is not equal defaults
ok everything seems pretty good here we
can create to file open something like
this would be nice so very first once we
got the temporary name we need to open
this fall so how we can do it I can
create a handle father i'm going to say
a variable handle that would be equal to
F open this is a PHP function if you
guys are not sure about all these are
PHP file functions are recommend you to
go to php.net and read from you
so which file to open that would be the
file being uploaded that is in this
particular variable daughter file and
open it in a read mode
okay open the fall in the read mode and
here i'm going to say daughter handle ok
so what I'm saying is once you are able
to open that file
go ahead and get the data from the csv
file this is the PHP function again this
will help you getting the data from the
csv file you so which data to get the
file which we open all you get data from
that file and read maximum hundred
digits are over 200 narrows from one
line and break every self with a car so
let's come here let me say name to name
last name to last name email to email
again these three things we have so what
it what it going to do if this
particular field would be more than
thousand correctors letters it is not
going to read because we only give
thousand out here but i can i'm pretty
sure not even a single you can be more
than thousand characters then we wanted
every cell so this is 1 so this is the
second one so we want every cell to be
breaking down with a comma
ok and until and unless you are able to
get the data in the same format then
follow the same followed you
functions began to write out here
otherwise don't follow

Video Length: 09:11
Uploaded By: tutlage
Published: 9/7/2011
View Count: 65,931

Related Software Products
Excel-to-MySQL
Excel-to-MySQL

Published By:
Intelligent Converters

Description:
Excel-to-MySQL is a program to convert MS Excel spreadsheet into MySQL database. Each worksheet becomes a table, each row becomes a record and each cell becomes a field. License Information Single-User License allows clients to install the software product on exactly one (1) computer system. Client can store a backup copy of the software but cannot use two copies of the software at any one time. Single-User License does NOT allow to make use of the software through a corporate network. ...

MySQL-to-Excel
MySQL-to-Excel

Published By:
Intelligent Converters

Description:
MySQL-to-Excel is a program to represent MySQL databases as MS Excel spreadsheet. Each MySQL table becomes a worksheet, each record becomes a row. All MySQL data types are supported. The program has easy-to-use wizard style interface and works with Unix and Windows MySQL servers. License Information Single-User License allows clients to install the software product on exactly one (1) computer system. Client can store a backup copy of the software but cannot use two copies of the software at any ...


Related Videos
Import Excel to MySQL Database
Import Excel to MySQL Database

Video Length: 10:53
Uploaded By: Michael Lively (5/27/2008)
View Count: 648,101

Connecting SQL Tables and data in Excel spreadsheets
Connecting SQL Tables and data in Excel spreadsheets

Video Length: 03:08
Uploaded By: techytube (8/4/2012)
View Count: 329,857

Import / export database data from / to Excel using ASP.NET and C#
Import / export database data from / to Excel using ASP.NET and C#

Video Length: 41:27
Uploaded By: sourav mondal (11/17/2013)
View Count: 238,285

How to import data from Excel to MySQL database
How to import data from Excel to MySQL database

Video Length: 01:16
Uploaded By: sqldeveloper (9/16/2008)
View Count: 136,188

C# Tutorial 29:How to Export Data from Database To Excel File By using C#
C# Tutorial 29:How to Export Data from Database To Excel File By using C#

Video Length: 13:12
Uploaded By: ProgrammingKnowledge (4/16/2013)
View Count: 97,544

Import data from Excel into MySQL using Python
Import data from Excel into MySQL using Python

Video Length: 07:05
Uploaded By: Michael Herman (10/1/2012)
View Count: 96,022

How to Easily Convert an Excel Spreadsheet to MySQL
How to Easily Convert an Excel Spreadsheet to MySQL

Video Length: 03:55
Uploaded By: SQLConverter (12/9/2011)
View Count: 85,213

How to Set ODBC MySQL Driver
How to Set ODBC MySQL Driver

Video Length: 02:09
Uploaded By: Internet Services and Social Networks Tutorials from HowTech
View Count: 78,110

Visualizing Data using MySQL and Excel 2013
Visualizing Data using MySQL and Excel 2013

Video Length: 05:46
Uploaded By: Michael Herman (9/6/2012)
View Count: 47,300

Exporting MySQL Database Table to Excel
Exporting MySQL Database Table to Excel

Video Length: 03:54
Uploaded By: Michael Lively (3/10/2008)
View Count: 46,916

Copyright © 2026, Ivertech. All rights reserved.