PHP – Import CSV file to mysql database Using LOAD DATA INFILE

If you’d do echo($sql); before you execute it you’d see that syntax of your query is incorrect for following reasons: Filename should be enclosed in quotes rather than backticks because it’s a string literal not an identifier. There is absolutely no need to call mysql_escape_string() to specify a delimiter in FIELDS TERMINATED BY and ENCLOSED … Read more

Easy way to export a SQL table without access to the server or phpMyADMIN

You could use SQL for this: $file=”backups/mytable.sql”; $result = mysql_query(“SELECT * INTO OUTFILE ‘$file’ FROM `##table##`”); Then just point a browser or FTP client at the directory/file (backups/mytable.sql). This is also a nice way to do incremental backups, given the filename a timestamp for example. To get it back in to your DataBase from that … Read more

Import CSV to MySQL

You can have MySQL set values for certain columns during import. If your id field is set to auto increment, you can set it to null during import and MySQL will then assign incrementing values to it. Try putting something like this in the SQL tab in phpMyAdmin: LOAD DATA INFILE ‘path/to/file.csv’ INTO TABLE your_table … Read more