Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You agree that you want "want the raw data (e.g.: as CSV) rather than any form of INSERT statements" - but the answer you've accepted does precisely the latter, using e.g. this line of code:</p> <pre><code>$return.= 'INSERT INTO '.$table.' VALUES('; </code></pre> <p>Which is fine if that's really what you want, but if I were you I would then just make a system call to mysqldump instead. You can get mysqldump to just generate a set of INSERT INTO statements in a safe, robust way without worrying about "did I close that double quote? Should there be an extra comma here?" etc.</p> <p>I don't know why you don't want to export the schema as well - if you specify --add-drop-table then your database dump becomes a nice, neat restore of your whole db if the worst happens - but if you just want to export your data, and you can make a system call to mysqldump in your PHP script, <a href="http://chriswa.wordpress.com/2008/02/20/mysqldump-data-only/" rel="nofollow">you could run</a>:</p> <pre><code>mysqldump --skip-triggers --compact --no-create-info db_name | gzip -c &gt; /tmp/db_name_backup.sql.gz </code></pre> <p>--no-create-info excludes all the CREATE TABLE statements; but as I say, I would rather include both CREATE and DROP IF EXISTS, so you have a complete backup of data and schema.</p> <p>I really recommend backing up using mysqldump's generated SQL - which MySQL innately understands, and which handles encoding, whitespace etc. properly - rather than something like CSV - which AFAIK isn't actually any kind of internationally recognized standard, and can't be piped back into mysql to restore your database at a later date:</p> <pre><code>gunzip -c &lt; /tmp/db_name_backup.sql.gz | mysql db_name </code></pre> <p>If your backup was instead a separate CSV file for every single table, restoring that backup becomes a far more difficult task. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload