gpt4 book ai didi

php - 列出所有 MySQL 表并排除特定的表

转载 作者:可可西里 更新时间:2023-11-01 06:43:40 27 4
gpt4 key购买 nike


我尝试从数据库中返回所有 MySQL 表并排除特定的表,例如用户。我使用以下代码打印我的表名:

function findTables() {
global $conn;
global $DB;

$query = "SHOW TABLES FROM $DB ";
$showTablesFromDb = mysqli_query($conn, $query);
while($row = mysqli_fetch_row($showTablesFromDb)) {
echo "<li><a href='admin.php?show={$row[0]}'>{$row[0]}</a></li>";
}
}

最佳答案

解决方案是:

show tables where tables_in_$DB not like 'a%';

下面是一些演示:

mysql> show tables;
+-----------------+
| Tables_in_test3 |
+-----------------+
| a1 |
| t1 |
| t2 |
+-----------------+
3 rows in set (0.00 sec)

-- LIKE is simpler than NOT LIKE
mysql> show tables like 'a%';
+----------------------+
| Tables_in_test3 (a%) |
+----------------------+
| a1 |
+----------------------+
1 row in set (0.00 sec)

-- `show tables not like 'a%'` is not working,
-- use the following way for NOT LIKE matching
mysql> show tables where tables_in_test3 not like 'a%';
+-----------------+
| Tables_in_test3 |
+-----------------+
| t1 |
| t2 |
+-----------------+
2 rows in set (0.01 sec)

关于php - 列出所有 MySQL 表并排除特定的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36034078/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com