Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Export it to a .sql file and import to the new database.</p> <p>In phpMyAdmin click the database you want to export, click <kbd>export</kbd>, check <kbd>save as file</kbd>, then <kbd>go</kbd>.</p> <p>Then upload it to the new database that you want to duplicate the data in.</p> <hr> <p>In a strict PHP sense, the only way I could think to do it would to be use of <code>SHOW TABLES</code> and <code>describe {$table}</code> to return the all the field names and structures of the records, parse that out, create your <code>create table</code> statements, then loop through each table and create <code>insert</code> statements.</p> <p>I'm afraid the best I can do for you is a sort of <strong><em>prototype</em></strong> code that I would imagine would be <em>incredibly</em> server intensive, which is why I recommend you go an alternate route.</p> <p>Something like:</p> <pre><code>&lt;?php // connect to first DB $tables = mysql_query("SHOW TABLES") or die(mysql_error()); while ($row = mysql_fetch_assoc($tables)) { foreach($row as $value) { $aTables[] = $value; } } $i = 0; foreach ($aTables as $table) { $desc = mysql_query("describe " . $table); while ($row = mysql_fetch_assoc($desc)) { $aFields[$i][] = array($row["Field"],$row["Type"],$row["Null"],$row["Key"],$row["Default"],$row["Extra"]); } $i++; } // connect to second DB for ($i = 0; $i &lt; count($aTables); $i++) { // Loop through tables, fields, and rows for create table/insert statements $query = 'CREATE TABLE IF NOT EXISTS {$aTables[$i]} ( //loop through fields { {$aFields[$i][$j][0]} {$aFields[$i][$j][1]} {$aFields[$i][$j][2]} {$aFields[$i][$j][3]} {$aFields[$i][$j][4]} {$aFields[$i][$j][5]}, {$aFields[$i][$j][0]} {$aFields[$i][$j][1]} {$aFields[$i][$j][2]} {$aFields[$i][$j][3]} {$aFields[$i][$j][4]} {$aFields[$i][$j][5]}, {$aFields[$i][$j][0]} {$aFields[$i][$j][1]} {$aFields[$i][$j][2]} {$aFields[$i][$j][3]} {$aFields[$i][$j][4]} {$aFields[$i][$j][5]}, {$aFields[$i][$j][0]} {$aFields[$i][$j][1]} {$aFields[$i][$j][2]} {$aFields[$i][$j][3]} {$aFields[$i][$j][4]} {$aFields[$i][$j][5]}, etc... } )'; //loop through data $query .= 'INSERT INTO {$aTables[$i]} VALUES'; $result = mysql_query("SELECT * FROM " . $aTables[$i]); while ($row = mysql_fetch_assoc($result)) { $query .= '('; foreach ($aFields[$i][0] as $field) { $query .= '"{$row[$field]}",'; } $query .= '),'; } mysql_query($query); } ?&gt; </code></pre> <p>This is based off of <a href="http://pastebin.com/MS9R7TT4">this script</a> which may come in handy for reference.</p> <p>Hopefully that's something to get you started, but I would suggest you look for a non PHP alternative.</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