If so no need "disable foreign key checks" on export.
<?php
$query=mysql_list_tables($db,$dbid);
for($i=0;$i<mysql_num_rows($query);$i++)
$tables[current(mysql_fetch_row($query))]=0;
mysql_free_result($query);
$query=mysql_query("
SELECT `REFERENCED_TABLE_NAME`,`TABLE_NAME`
FROM `$schema`.`KEY_COLUMN_USAGE`
WHERE `TABLE_SCHEMA` = '$db' AND `REFERENCED_TABLE_SCHEMA` IS NOT NULL AND `TABLE_NAME` <> `REFERENCED_TABLE_NAME`
ORDER BY `REFERENCED_TABLE_NAME`
",$dbid);
for($i=0;$i<mysql_num_rows($query);$i++)
$constraints[current($t=mysql_fetch_assoc($query))][]=next($t);
mysql_free_result($query);
$again=true;
while($again)
if(!$again=false)
foreach($constraints as $table=>$rel)
foreach($rel as $t)
if(($tables[$table]<=$tables[$t])&&($tables[$table]++)&&($again=true))
break;
asort($tables);
$i=0;
foreach($tables as $k=>$v)$tables[$k]=$i++;unset($k);unset($v);unset($i);
$tables=array_flip($tables);
mysql_close($dbid);
?>
$tables ordered for deleting
for create and update in reverse order
As of now phpMyAdmin add constraints at the very end of export. So I do not see a requirement to order tables by their constraints.