我收到警告 - > mysql_fetch_array()期望参数1为resource,boolean
enter code here
$db // database name
$sql1="SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA=".$db." order by create_time desc limit 1";
$res1 = mysql_query($sql1);
if($row = mysql_fetch_array($res1))
echo $row['TABLE_NAME'];
else echo "unable to fetch table name";
答案 0 :(得分:2)
您需要在$db
变量的包含周围加上引号。改变这一行:
$sql1="SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA=".$db." order by create_time desc limit 1";
要:
$sql1="SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA='".$db."' order by create_time desc limit 1";
请注意mysql_* functions are deprecated。使用PDO或mysqli_*与prepared statements一起使用可以避免申请中出现security risks。