[PHP] LOAD INFILE
Hi I want to upload a .csv file from my local pc to a mysql server. My local machine is XP2. I have used the following but the file does not upload. When using php MyAdmin it returns the error 'file not found'. Can anyone help? ?php // Include our login information include('db_login_master.php'); // Connect - note: 'false' is 'no new link use existing' parameter and '128' enables LOAD DATA $connection = mysql_connect($db_host, $db_username, $db_password,false,128); if (!$connection){ die (Could not connect to the database: br /. mysql_error()); } // Select the database $db_select=mysql_select_db($db_database); if (!$db_select) { die (Could not select the database: br /. mysql_error()); } // Import new avaiability data from local CSV file $sql2 = 'LOAD DATA LOCAL INFILE \'C:EXPORT.CSV\' INTO TABLE `availability` FIELDS TERMINATED BY \';\' ENCLOSED BY \'\' ESCAPED BY \'\' LINES TERMINATED BY \'\\r\\n\''; // echo $sql2; mysql_query($sql2); echo 'p align=centerfont face=Verdana color=#FF'; mysql_query($sql0); printf(Records added: %d\n, mysql_affected_rows()); echo 'p align=centerBUPDATE COMPLETE/B/p'; ? -- John UK -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] LOAD INFILE
John Boy wrote: Hi I want to upload a .csv file from my local pc to a mysql server. My local machine is XP2. I have used the following but the file does not upload. When using php MyAdmin it returns the error 'file not found'. Can anyone help? ?php // Include our login information include('db_login_master.php'); // Connect - note: 'false' is 'no new link use existing' parameter and '128' enables LOAD DATA $connection = mysql_connect($db_host, $db_username, $db_password,false,128); if (!$connection){ die (Could not connect to the database: br /. mysql_error()); } // Select the database $db_select=mysql_select_db($db_database); if (!$db_select) { die (Could not select the database: br /. mysql_error()); } // Import new avaiability data from local CSV file $sql2 = 'LOAD DATA LOCAL INFILE \'C:EXPORT.CSV\' INTO TABLE `availability` FIELDS TERMINATED BY \';\' ENCLOSED BY \'\' ESCAPED BY \'\' LINES TERMINATED BY \'\\r\\n\''; // echo $sql2; mysql_query($sql2); echo 'p align=centerfont face=Verdana color=#FF'; mysql_query($sql0); printf(Records added: %d\n, mysql_affected_rows()); echo 'p align=centerBUPDATE COMPLETE/B/p'; ? Are you only passing the path to the C:EXPORT.CSV local file inside the query? You first need to upload the file. Either through a form or bu using FTP, SSH or something similar. More info about uploading files with PHP: http://php.net/manual/en/features.file-upload.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] LOAD INFILE
Thijs Lensselink wrote: John Boy wrote: Hi I want to upload a .csv file from my local pc to a mysql server. My local machine is XP2. I have used the following but the file does not upload. When using php MyAdmin it returns the error 'file not found'. Can anyone help? Why not just use phpmyadmin to import it? It can read csv files. ?php // Include our login information include('db_login_master.php'); // Connect - note: 'false' is 'no new link use existing' parameter and '128' enables LOAD DATA $connection = mysql_connect($db_host, $db_username, $db_password,false,128); if (!$connection){ die (Could not connect to the database: br /. mysql_error()); } // Select the database $db_select=mysql_select_db($db_database); if (!$db_select) { die (Could not select the database: br /. mysql_error()); } // Import new avaiability data from local CSV file $sql2 = 'LOAD DATA LOCAL INFILE \'C:EXPORT.CSV\' INTO TABLE `availability` FIELDS TERMINATED BY \';\' ENCLOSED BY \'\' ESCAPED BY \'\' LINES TERMINATED BY \'\\r\\n\''; // echo $sql2; mysql_query($sql2); echo 'p align=centerfont face=Verdana color=#FF'; mysql_query($sql0); printf(Records added: %d\n, mysql_affected_rows()); echo 'p align=centerBUPDATE COMPLETE/B/p'; ? Are you only passing the path to the C:EXPORT.CSV local file inside the query? You first need to upload the file. Either through a form or bu using FTP, SSH or something similar. To expand on that, LOAD DATA reads the file from the database server, not from your computer or any other server. Once you've uploaded it, put the right path in (eg /home/username/export.csv) and it should work. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php