How to use PHP & Convert CSV to MySQL Learn / tutorial php programming how to usingĀ PHP import csv to mysql
ShotDev Focus:
- PHP Import CSV to MySQL.
Example
php_csv_write.php
<html> <head> <title>ShotDev.Com Tutorial</title> </head> <body> <? $objConnect = mysql_connect("localhost","root","root") or die(mysql_error()); // Conect to MySQL $objDB = mysql_select_db("mydatabase"); $objCSV = fopen("shotdev/customer.csv", "r"); while (($objArr = fgetcsv($objCSV, 1000, ",")) !== FALSE) { $strSQL = "INSERT INTO customer "; $strSQL .="(CustomerID,Name,Email,CountryCode,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 Done."; ?> </body> </html>
Create a php file and save to path root-path/myphp/
Run
http://localhost/myphp/php_csv_mysql.php
Screenshot