我正在尝试运行这个 PHP 函数:
function makeString() {
// Create our random string
$string = "";
$characters = array('a', 'b', 'c', 'd');
for ($i = 0; $i < 4; $i++)
{
$string .= $characters[mt_rand(0, 4)];
}
$sql="SELECT COUNT(*) FROM urls WHERE short_url = '{$string}'";
$rs=mysql_query($sql,$conn);
$result=mysql_fetch_array($rs);
if($result['COUNT(*)'] > 0)
{
// if it already exists, do it again
makeString();
}
else
{
return $string;
//insert the data
}
}
makeString();
但我收到这些错误:
Warning: mysql_query() expects parameter 2 to be resource, null given in /home/charlie/public_html/short/shorten.php on line 15
Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in /home/charlie/public_html/short/shorten.php on line 16
他们的意思是什么?
所有表/数据库列似乎都还可以,并且没有保留字等...