我有以下代码来显示我数据库中所有表的列表。
$table_count = mysql_query("
SELECT TABLE_NAME
FROM information_schema.tables
WHERE table_schema = 'DB_NAME'
");
$tables = array();
while($row = mysql_fetch_array($table_count))
{
$table = $row["TABLE_NAME"];
}
是否可以更改此查询以显示除某些表之外的所有表?
若有人可以解释/告诉我该怎么做?
答案 0 :(得分:2)
当然可以。您可以选择一些列
SELECT foo, bar, baz from ...
或者您通过AND
或OR
$table_count = mysql_query("
SELECT TABLE_NAME AS tableName, another_complicated_column as niceName
FROM information_schema.tables
WHERE table_schema = 'DB_NAME'
AND another_column NOT LIKE 'FOOBARBAZ'
AND another_another_column != 333
");
答案 1 :(得分:1)
如果更改查询,则可以按名称过滤表格,例如:
$table_count = mysql_query(
"SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = 'DB_NAME' AND TABLE_NAME NOT LIKE 'TMP_%' "
);
这会过滤掉以TMP_
开头的表格,留下所有其他表格。