cerom Posted March 28, 2013 Share Posted March 28, 2013 (edited) need help ... How replace csv to mysql ... <html> <head> <title>Replace</title> </head> <body> <? copy($_FILES["fileCSV"]["tmp_name"],"shotdev/".$_FILES["fileCSV"]["name"]); // Copy/Upload CSV $objConnect = mysql_connect("localhost","root","root") or die(mysql_error()); // Conect to MySQL $objDB = mysql_select_db("mydatabase"); $objCSV = fopen("shotdev/".$_FILES["fileCSV"]["name"], "r"); while (($objArr = fgetcsv($objCSV, 1000, ",")) !== FALSE) { $strSQL = "INSERT INTO customer "; $strSQL .="(CustomerID,Name,Budget,Used) "; $strSQL .="VALUES "; $strSQL .="('".$objArr[0]."','".$objArr[1]."','".$objArr[2]."' "; $strSQL .=",'".$objArr[3]."','".$objArr[4]."','".$objArr[5]."') "; $objQuery = mysql_query($strSQL); } fclose($objCSV); echo "Import completed."; ?> </body> </html> Edited March 30, 2013 by fenway Quote Link to comment https://forums.phpfreaks.com/topic/276248-how-replace-data-csv-to-mysql/ Share on other sites More sharing options...
Barand Posted March 28, 2013 Share Posted March 28, 2013 (edited) Fastest way is to use LOAD DATA INFILE http://dev.mysql.com/doc/refman/5.6/en/load-data.html Edited March 28, 2013 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/276248-how-replace-data-csv-to-mysql/#findComment-1421567 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.