请参阅我已经检查过旧线程但没有帮助。
这是我的代码,似乎还可以,但会出错:Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given
代码:
function getPnr()
{
$con = mysqli_connect('127.0.0.1', 'root', '', 'safari');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
return;
}
$pnr = mt_rand(1111111111, 99999999999);
$result = mysqli_query($con,"SELECT pnr from tbl_user where pnr = '".$pnr."'");
if(mysqli_num_rows($result)>0)
echo "emtpy";//getPnr();
else
echo $pnr;
}
这里有什么问题?
更新的代码:
function getPnr()
{
$con = mysqli_connect('127.0.0.1', 'root', '', 'safari');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
return;
}
$pnr = mt_rand(1111111111, 99999999999);
$result = mysqli_query($con,"SELECT user_pnr from tbl_user where user_pnr = '".$pnr."'") or die(mysqli_error($con);
if(mysqli_num_rows($result)>0)
echo "emtpy";//getPnr();
else
echo $pnr;
返回; }
新错误:
Parse error: syntax error, unexpected ';' in F:\wamp\www\safari\REST_APIs_for_RedBus\main.php on line 104
答案 0 :(得分:0)
这意味着您的sql查询无法执行。尝试使用您的代码添加错误处理,然后您将获得明确的错误sql消息
$result = mysqli_query($con,"SELECT pnr from tbl_user where pnr = '".$pnr."'") or die(mysqli_error($con));