最近,我对一个正在开发的站点做了很多修改,并完成了整个项目,替换了与数据库交互的旧mysql_u方法。在这个特定的脚本中,我很难让它同样工作。
旧密码是

$checkinfo = mysql_query("SELECT * FROM `myusers` WHERE `userid` = '$uid' LIMIT 1") or die(mysql_error());

if(mysql_num_rows($checkinfo) < 1){ //log and die if user isnt in db
  die("Incident has been logged!"); }

$myinfo = mysql_fetch_assoc($checkinfo);

我的新密码是
$checkinfo = $mysqli->query("SELECT * FROM `myusers` WHERE `userid` = '$uid' LIMIT 1") or die('Error : ('. $mysqli->errno .') '. $mysqli->error);

if($checkinfo->fetch_row() < 1){
    die("Incident has been logged!"); }

$myinfo = $checkinfo->fetch_assoc();

现在它只是没有为剩下的代码设置数组。。。请指出我的愚蠢!谢谢

最佳答案

通过使用->fetch_row(),它已经为第一行提供了数据。由于显式设置了LIMIT 1,下一个fetch调用将导致NULL
改为->num_rows

$checkinfo = $mysqli->query("SELECT * FROM `myusers` WHERE `userid` = '$uid' LIMIT 1") or die('Error : ('. $mysqli->errno .') '. $mysqli->error);

if($checkinfo->num_rows < 1){
    die("Incident has been logged!"); // change this to something more meaningful.
}

$myinfo = $checkinfo->fetch_assoc();

10-06 03:35