gpt4 book ai didi

php - MySQLi中如何检查表是否存在?

转载 作者:行者123 更新时间:2023-11-29 08:07:20 27 4
gpt4 key购买 nike

这就是我正在做的事情:

$mysqli = new mysqli($db_host,$db_user,$db_pass,$db_name);
$result = $mysqli->query("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = ".$db_name." AND table_name = users");
$nr = $result->num_rows; // 77 line
var_dump($nr);
$mysqli->close();

但是错误提示:

Notice: Trying to get property of non-object in test.php on line 77
NULL

最佳答案

您还可以使用此语句进行检查 SHOW TABLES LIKE 'tablename';

关于php - MySQLi中如何检查表是否存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22438216/

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