Re: LOAD INFILE

From: Date: Mon, 30 Mar 2009 22:00:52 +0000
Subject: Re: LOAD INFILE
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-290867@lists.php.net to get a copy of this message
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="center"><font face="Verdana" color="#0000FF">'; mysql_query($sql0); printf("Records added: %d\n", mysql_affected_rows()); echo '<p align="center"><B>UPDATE 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/

« previous php.general (#290867) next »