Reputation: 13
i recently did lots of changes to a site i was working on and went thru the entire project replacing the old mysql_ methods of interacting with the database. in this certain script im having trouble getting it to work the same.
the old code is
$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);
and my new code is
$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();
now its simply not setting my array for the rest of the code... please point out my stupidity! thanks
Upvotes: 1
Views: 42
Reputation: 41885
By using ->fetch_row()
, it already does fed the first row. Since you explicitly set LIMIT 1
, the next fetch invocation resulted into NULL
.
Change it to ->num_rows
instead:
$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();
Upvotes: 3