I have this function or method in my class, but it doesn't return number of rows when I insert an email into it. I have tested the mysql connection etc, they all are working. Also note that the email that I am passing through the method already exist in database. my plan is to get the number of the rows and if it is bigger than zero, it means we already have this email in database.
public function userExist($email) {
$query = "SELECT email FROM " . USER_TABLE . " WHERE email = ?";
$stmt = $this->_db->prepare($query);
$stmt->bind_param("s", $email);
if ($stmt->execute()) {
$stmt->store_result();
return $stmt->num_rows;
}
return false;
}
public function userExist($email) {
$query = "SELECT COUNT(*) AS num_rows FROM " . USER_TABLE . " WHERE email = ?";
$stmt = $this->_db->prepare($query);
$stmt->bind_param("s", $email);
if ($stmt->execute()) {
$stmt->store_result();
return $stmt->num_rows;
}
return false;
}
there you go, notice SELECT COUNT(*) AS num_rows
(I used num_rows so you wouldn't have to change your code, this could be anything so long as you reference it like $stmt->VAR_NAME
after you execute the query.)