edgardoburgos
asked on
Import csv into Mysql with PHP Script
I urgently need a script that would read a csv file that i exported from filemaker pro and import it into Mysql using php. I search the web for days and found a few scripts but none of them worked. Thank you ahead of time for your time.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
$link = mysql_connect("localhost", "username", "password") or die("Could not connect: ".mysql_error());
$db = mysql_select_db("db_name") or die(mysql_error());
$query = "LOAD DATA INFILE './data_file.csv' INTO TABLE table_name(`field1`, `field2`,.....)";
$result = mysql_query($query)
or die("Invalid query: " . mysql_error());
fclose ($handle);
If number of fields in table match the number of data columns in file, you can skip the field list part, i.e.
$query = "LOAD DATA INFILE './data_file.csv' INTO TABLE table_name";
REMEMBER : the data file should be in the same directory as mysql table.
$db = mysql_select_db("db_name")
$query = "LOAD DATA INFILE './data_file.csv' INTO TABLE table_name(`field1`, `field2`,.....)";
$result = mysql_query($query)
or die("Invalid query: " . mysql_error());
fclose ($handle);
If number of fields in table match the number of data columns in file, you can skip the field list part, i.e.
$query = "LOAD DATA INFILE './data_file.csv' INTO TABLE table_name";
REMEMBER : the data file should be in the same directory as mysql table.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER