I have a function which works like this
public function get_user_by_email($email)
{
$stmt = $this->con->prepare("SELECT * FROM `user` WHERE `email` = ? ");
$stmt->bind_param("s", $email);
$stmt->execute();
return $stmt->get_result()->fetch_assoc();
}
The problem is whenever I call this function with any email(whether it existed on the database or not) it throws internal server error 500. I'm using a live hosting server and Postman to test this. Can someone help?
Try debugging with the following code:
public function get_user_by_email($email)
{
$stmt = $this->con->prepare("SELECT * FROM `dbname.user` WHERE `email` = ? ");
$stmt->bind_param("s", $email);
$stmt->execute();
$result = $stmt->get_result();
echo "Result Object: ";
echo $result; // If it's OK, it should print "Object ( ... )"
$arr = $result->fetch_assoc();
echo "Fetched Object: ";
echo $arr; // If it's OK, then it'd print "Array ( ... )"
return $arr;
}
I experienced this error as well. It is coming from get_result() -> https://www.php.net/manual/en/mysqli-stmt.get-result.php
I built an app using JS, PHP and MySQL. Everything worked well locally but when I uploaded it to a shared server, I start getting 500 Internal Server error (The server host might have thrown 500 error instead of displaying Fatal Error on screen). This got fixed when I disabled mysqli and enabled nd_mysqli from my hosting's PHP extensions.