I need to be able to load the data from a CSV file from my local machine into my MySQL database on the remote server by way of a php page. I have seen some code, but nothing that really works well.
I created a form to upload the data <form action="import.php" method="post" enctype="multipart/form-data">
<input name="file" type="file" size="15">
<input type="submit" value="Submit">
</form>
...and here is the import.php (the relevent part) $result = mysql_query("LOAD DATA LOCAL INFILE '$file' INTO TABLE schedule" or die(mysql_error());
I keep getting the same error I did with other scripts: File 'chpuploadtempphp24.tmp' not found (Errcode: 2)
What I would really like to do is something similar to what PHPMyAdmin does. Just read the data from the (local) file and insert it into the database. Is that not possible?
That would be the part of my earlier post which reads: One is reading the file in through PHP, constructing a SQL statement from the values in the file, then executing each constructed SQL query in turn.
So you will program PHP to break down the file and then insert the data, yes.
I still recommend using LOAD DATA INFILE. It sounds to me that figuring out a path or permissions problem with the temporary file would be easier than writing the code to create umpteen SQL statements.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.