gpt4 book ai didi

php - 这是在数据库中查找表的正确查询吗?

转载 作者:行者123 更新时间:2023-11-29 23:46:27 25 4
gpt4 key购买 nike

这是在数据库中查找表的正确查询吗?

$checktable=mysql_query("SELECT DISTINCT $n FROM jma 
WHERE COLUMN_NAME IN('file','recived')");


$userResult=mysql_num_rows($checktable);

move_uploaded_file($_FILES['img']['tmp_name'],$photo);

if ($userResult == 0)
{
echo"table does not exist";
}
else
{
mysql_query("insert into $n (recived) values('$photo')") or die(mysql_error());
echo "Your data is SuccessFully Addedd............";
}

最佳答案

我会使用 MySQL 提供的 SHOW 命令来做到这一点,如下所示:

$result = mysql_query("SHOW tables LIKE 'table_name';");
$exists = mysql_num_rows($result);

if ($exists == 1) {
// Your code here
} else {
// Your code here
}

我还没有测试过,但应该可以正常工作。

问候。

关于php - 这是在数据库中查找表的正确查询吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25909018/

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