// Connect to Database and execute query ---------
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
@mysql_select_db("$DBName") or die("Unable to select database $DBName");
/* DO MYSQL CONNECTION HERE */
$file = '***.csv'; //file name here
//we read the CSV file here
$lines = file($file);
//now we take each line and explode it then insert to DB
foreach ($lines as $line) {
$cols = explode(';', $line);
mysql_query("INSERT INTO $table (F_name, L_name, S_name, M_name, N_name, street, city, state, zip, country, phone, email, years, participation, notes) VALUES ('$cols[0]', '$cols[1]', '$cols[2]', '$cols[3]', '$cols[4]', '$cols[5]', '$cols[6]', '$cols[7]', '$cols[8]', '$cols[9]', '$cols[10]', '$cols[11]', '$cols[12]', '$cols[13]', '$cols[14]')")or
die(mysql_error());
}
yeah, for some reason it does not like the " ' " and some others. I just went thru and changed them for the time being. Then changed them back when I got into mysql. I am not that experience with all this. Maybe somebody elese can offer a better solution.
This did something but I am not sure what. It worked for a minute and then the browser said done but there was no printout of affected rows. I looked at the table in PHPMyAdmin and it looked like the whole thing was not there and what was there was messed up. Also, I don't think that it could have converted a 40MB database in 1 minute.
I found out more exactly what is going on. It is trying to cram the whole line into one field rather than separating the line by the commas and putting those into each field. What do we do from here?