Forum Moderators: coopster
I'm trying to insert data from a csv file into a mysql database. Here's what I got so far.
$csvfle = "phgrades.csv";
$opnfle = fopen($csvfle, "r");
$inscsv = "insert into phgrades (gradecode, grade, gradeclass, gradepoint, grouping, rank) VALUES ('$row[0]','$row[1]','$row[2]','$row[3]','$row[4]','$row[5]','$row[6]')";
while(!feof($opnfle)){
$row = fgetcsv($opnfle, 1024, ";");
$rslt = mysql_query($inscsv);
}
Is there anything I'm missing? Thanks
fintan.
You need to grab the row, then assign the values.
If queries aren't working, echo them before querying
echo $inscsv;
$rslt = mysql_query($inscsv);
I suspect that if you do this, you'll find that your query is not what you think.
If you get it so the query looks good and still doesn't work, I prefer to debug in the mysql client rather than through php. That way you know exactly what query you're using and can more easily figure out how to debug.
Tom
I see what you mean. I tried this instead
while(!feof($opnfle))
{
$row = fgetcsv($opnfle, 1028 , ";");$inscsv = "insert into phgrades (gradecode, grade, gradeclass, gradepoint, grouping, rank) VALUES ('$row[0]','$row[1]','$row[2]','$row[3]','$row[4]','$row[5]','$row[6]')";
mysql_query($inscsv);
echo $inscsv."<br><br>\n\n";
}
I guess I made a boo boo. Thanks
fintan.
I'm trying to insert data from a csv file into a mysql database.
Just a question -- Is there a reason you need to get PHP involved in this import? mysqlimport is faster and pretty easy.
[dev.mysql.com...]