<p>I need to do a dump of a table on a remote server, but I can't access the server directly. The only access I have is through PHP scripts.</p>

<p>Is there some way in which MySQL will return an </p>

<pre><code>INSERT INTO `table_name` (`field1`, `field2`) VALUES ('a', 'b'), ('c', 'd')
</code></pre>

<p>statement, like what <code>mysqldump</code> will return?</p>

<p>I don't have access to phpMyAdmin, and I preferably don't want to use <code>exec</code>, <code>system</code> or <code>passthru</code>.</p>

<p>See <a href="https://stackoverflow.com/questions/81934/easy-way-to-export-a-sql-table-without-access-to-the-server-or-phpmyadmin">this question</a> for another export method</p>

[{'answer_id': 63405, 'author': 'UnkwnTech', 'author_id': 115, 'author_profile': 'https://Stackoverflow.com/users/115', 'pm_score': 4, 'selected': True, 'text': '<p>1) can you run mysqldump from exec or passthru<br />\n2) take a look at this: <a href="http://www.php-mysql-tutorial.com/perform-mysql-backup-php.php" rel="noreferrer">http://www.php-mysql-tutorial.com/perform-mysql-backup-php.php</a></p>\n'}, {'answer_id': 63419, 'author': 'Espo', 'author_id': 2257, 'author_profile': 'https://Stackoverflow.com/users/2257', 'pm_score': 0, 'selected': False, 'text': '<p>If you can use php-scripts on the server i would recommend <a href="http://www.phpmyadmin.net/home_page/index.php" rel="nofollow noreferrer">phpmyadmin</a>. Then you can do this from the web-interface.</p>\n'}, {'answer_id': 63420, 'author': 'Astra', 'author_id': 5862, 'author_profile': 'https://Stackoverflow.com/users/5862', 'pm_score': 0, 'selected': False, 'text': '<p>You should check out <a href="http://phpmyadmin.sourceforge.net" rel="nofollow noreferrer">PHPMyAdmin</a>, it is a php based MySQL administration tool.  It supports backups and recovery for the database as well as a \'GUI\' to the database server.  It works very well.</p>\n'}, {'answer_id': 63424, 'author': 'David Thibault', 'author_id': 5903, 'author_profile': 'https://Stackoverflow.com/users/5903', 'pm_score': 0, 'selected': False, 'text': '<p>I\'m pretty sure <a href="http://www.phpmyadmin.net/" rel="nofollow noreferrer">phpMyAdmin</a> will <a href="http://www.phpmyadmin.net/documentation/#faqexport" rel="nofollow noreferrer">do this for you</a>.</p>\n'}, {'answer_id': 63431, 'author': 'agnul', 'author_id': 6069, 'author_profile': 'https://Stackoverflow.com/users/6069', 'pm_score': 0, 'selected': False, 'text': "<p>This</p>\n\n<pre><code>select 'insert into table table_name (field1, field2) values'\n       || table_name.field1 || ', ' || table_field2 || ');'\nfrom   table_name\n</code></pre>\n\n<p>should get you started. Replace || with the string concatenation operator for your db flavour. If field1 or field2 are strings you will have to come up with some trick for quoting/escaping.</p>\n"}, {'answer_id': 63468, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 0, 'selected': False, 'text': '<p>Here is one approach generating a lot of separate query statements.  You can also use implode to more efficiently combine the strings, but this is easier to read for starters and derived from this you can come up with a million other approaches.</p>\n\n<pre><code>$results = mysql_query("SELECT * FROM `table_name`");\nwhile($row = mysql_fetch_assoc($results)) {\n\n    $query = "INSERT INTO `table_name` ";\n    $fields = \'(\';\n    $values = \'(\'; \n\n    foreach($row as $field=&gt;$value) {\n        $fields .= "\'".$field."\',";\n        $values .= "\'".mysql_escape_string($value)."\',";\n    }\n\n    //drop the last comma off\n    $fields = substr($fields,0,-1);\n    $values = substr($values,0,-1);\n\n    $query .= $fields . " VALUES " . $values;\n\n    //your final result\n    echo $query;\n}\n</code></pre>\n\n<p>See if that gets you started    </p>\n'}]
['https://Stackoverflow.com/questions/63399', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/6681/']