php - Replicate mysqldump functionality using only queries -


how backup mysql database using queries? mean, php's system() function disables security reasons, cannot invoke mysqldump.

for table structure use this:

show create table table_name 

but how table data? predefined sql command exist? tried select ... var_list, cannot work (select ... outfile not suitable me, db host different server have access to).

thanks help, , sorry being such noob, first question here! :)

it should pretty straightforward create insert statements in php code select * table query. here's example:

$db = new pdo('mysql:dbname=database;host=host', 'user', 'password'); $result = $db->query('select * table');  $columns = array(); for($i = 0; $i < $result->columncount(); $i++) {   $column = $result->getcolumnmeta($i);   $columns[] = sprintf('`%s`', $column['name']); } $colstring = implode(',', $columns);  $rows = $result->fetchall(pdo::fetch_num); $inserts = array(); foreach($rows $r) {   $values = array_map(function($e) use ($db) {       return $db->quote($e);     },     $r);   $valstring = implode(',', $values);   $inserts[] = sprintf('insert table (%s) values (%s)',                        $colstring,                        $valstring); } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -