Learning & Integrating web technology and code help directory

How to use PHP & Import/Convert CSV to MySQL

No comments
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

  1. <html>  
  2. <head>  
  3. <title>ShotDev.Com Tutorial</title>  
  4. </head>  
  5. <body>  
  6. <?  
  7.   
  8. $objConnect = mysql_connect("localhost","root","root"or die(mysql_error()); // Conect to MySQL  
  9. $objDB = mysql_select_db("mydatabase");  
  10.   
  11. $objCSV = fopen("shotdev/customer.csv""r");  
  12. while (($objArr = fgetcsv($objCSV, 1000, ",")) !== FALSE) {  
  13. $strSQL = "INSERT INTO customer ";  
  14. $strSQL .="(CustomerID,Name,Email,CountryCode,Budget,Used) ";  
  15. $strSQL .="VALUES ";  
  16. $strSQL .="('".$objArr[0]."','".$objArr[1]."','".$objArr[2]."' ";  
  17. $strSQL .=",'".$objArr[3]."','".$objArr[4]."','".$objArr[5]."') ";  
  18. $objQuery = mysql_query($strSQL);  
  19. }  
  20. fclose($objCSV);  
  21.   
  22. echo "Import Done.";  
  23. ?>  
  24. </body>  
  25. </html>  
Create a php file and save to path root-path/myphp/
Screenshot
PHP & Import/Convert CSV to MySQL
.

No comments :

Post a Comment