Check if user exist with mysqli doesn't work

2014-02-17 php mysqli
$stmt = $db->prepare("SELECT * FROM user WHERE name='Steve Job'");
$stmt->execute();
if($stmt->num_rows){
    echo "1";
}

it return blank in my ajax callback. I've debugging for hours.

Answers

$stmt = $db->prepare("SELECT * FROM user WHERE name='Steve Job'");
$stmt->execute();
$stmt->store_result();
$numRows = $stmt->num_rows;
if($numRows > 0){
    echo "1";
}

You need to use store_result before working with num_rows

Related