I have a db in sql, and I need a php/mysql query/command to copy the entire db (schema and data) to a new db. I know how to do this with a table, but I can not figure out how to do this with a whole db. I also know that I could do it using mysql dump, but I don't want to have to run a shell command.
You'll need to do it with PHP...
Here's one method...
<?php
//connect to database $database = 'xxx'; //name of database to copy $ndatabase = 'yyy'; //name of new database
mysql_query("CREATE DATABASE $ndatabase");
$rs = mysql_query("SHOW TABLES FROM $database");
while($r = mysql_fetch_row($rs))
{
mysql_select_db($database);
$rs2 = mysql_query("SHOW CREATE TABLE {$r[0]}");
$ctable = myqsl_result($rs,0);
mysql_select_db($ndatabase);
mysql_query($ctable);
mysql_query("INSERT INTO {$r[0]} SELECT * FROM {$database}.{$r[0]}");
}
?>Untested... but should work (when run as a user with suitable permissions). :)
-- ---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals – www.phparch.com
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

