按创建时间排序数据库表


order database tables by creation time

嗨,我想列出数据库中所有的表并按时间排序,我怎么能做到呢目前我可以列出数据库中所有的表但我不能按时间排序;

$dbname = "album";
if (!mysql_connect("localhost", "root", "")) {
echo "Could not connect to mysql";
exit;
}
$sql = "SHOW TABLES FROM $dbname";
$result = mysql_query($sql);
if (!$result) {
echo "DB Error, could not list tables'n";
echo "MySQL Error: " . mysql_error();
exit;
}
$sorts = array();
while ($row = mysql_fetch_row($result)) {
echo "Table: {$row[0]}"."<br>";
}
mysql_free_result($result);

这可能对你有帮助:

$sql = "
SELECT create_time, table_name
FROM information_schema.tables 
WHERE table_schema = '$dbname'
ORDER BY create_time
";

也改变while循环的内部部分,如下所示:

while ($row = mysql_fetch_array($result)) {
    echo "Table: {$row['table_name']} - {$row['create_time']} <br/>";
}

使用information_schema表

select * from information_schema.columns
order by create_time, column_name, table_name;

或者如果你想要一个更窄的结果集:

select column_name, table_name, data_type, character_maximum_length,
is_nullable, column_default, create_time
from information_schema.columns
order by create_time, column_name, table_name;

这可能是解决方案

select * from information_schema.columns
order by create_time, column, table;