PhpMyAdmin and PHP is wrong tools for this purposes. Use command line shell. Something like this:
mysqldump -u root -p database1 > database1.sql
mysql -u root -p database < database1.sql
It will work in 10 times more faster, I'm guarantee it. Also, database will take care about data consistency instead of you.
If you are realy want to do it in PHP, use php command line shell.
If you are still want to do it in PHP WITHOUT command line shell, I can suggest to do this kind of trick:
$query = "show tables from source_database";
$tables = $dbSource->getColumn($query)//get one column from database
foreach($tables as $tableName) {
$query = "show create table ".$tableName;//← it will return query to clone table structure
$createTableSchema = $dbSource->getRow($query);//← get assoc array of one row
$dbTarget->query($createTableSchema['Create Table']);//← here is your silver bullet
}
PS and also, when (if) you will copy data from one table to another table, you should know that statement
insert into table () values (values1), (values2), (values3);
much more faster than
insert into table () values (values1);
insert into table () values (values2);
insert into table () values (values3);
But insert multy rows is related to max_allowed_packet
propery field. In case, when your query will more large than this field (yes, query string can allocate 1 gb of memory), MySQL will throw exception. So, to build Insert multy query you should get max_allowed_packet
and generate this query according to this size. Also to speed up performance you can disable keys
from target table. (do not forgot to enable keys
, lol)