cerom Posted March 28, 2013 Share Posted March 28, 2013 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> 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 Fastest way is to use LOAD DATA INFILE http://dev.mysql.com/doc/refman/5.6/en/load-data.html 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
Archived
This topic is now archived and is closed to further replies.