Uncaught Error: Call to undefined method mysqli_stmt::get_result() problem with php srcipt
Uncaught Error: Call to undefined method mysqli_stmt::get_result() problem with php srcipt
I went through all stakoverflow posts about the problem, and everywhere I find only some other procedure how to solve it. I am trying to store data to the database through android application, I had been doing that successfully until yesterday... Then I made some changes in the database and suddenly I cannot use my PHP anymore... Maybe the problem was that I added to column to database? Please help me if you can.
Here are my php files:
DB_Connect.php:
<?php
class DB_Connect
private $conn;
public function connect()
require __DIR__ . "/Config.php";
$this->conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
return $this->conn;
?>
DB_Functions.php:
<?php
class DB_Functions
private $conn;
function __construct()
require __DIR__ . "/DB_Connect.php";
$db = new Db_Connect();
$this->conn = $db->connect();
// destructor
function __destruct()
/**
* Storing new user
* returns user details
*/
public function storeUser($name, $email, $password, $facebook_json)
$uuid = uniqid('', true);
$hash = $this->hashSSHA($password);
$encrypted_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
$stmt = $this->conn->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, salt, facebook_json, created_at) VALUES(?, ?, ?, ?, ?, ?, NOW())");
$stmt->bind_param("ssssss", $uuid, $name, $email, $encrypted_password, $salt, $facebook_json);
$result = $stmt->execute();
$stmt->close();
// check for successful store
if ($result)
$stmt = $this->conn->prepare("SELECT * FROM users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$user = $stmt->get_result()->fetch_assoc();
$stmt->close();
return $user;
else
return false;
/**
* Get user by email
*/
public function getUserByEmail($email)
$stmt = $this->conn->prepare("SELECT * FROM `users` WHERE `email` = ? ");
$stmt->bind_param("s", $email);
if ($stmt->execute())
$user = $stmt->get_result()->fetch_assoc();
$stmt->close();
return $user;
else
return NULL;
/**
* Check user is existed or not
*/
public function isUserExisted($email)
$stmt = $this->conn->prepare("SELECT email from users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0)
// user existed
$stmt->close();
return true;
else
// user not existed
$stmt->close();
return false;
/**
* Updating facebook_json field
*/
public function updateFacebookJson($email, $facebook_json)
$stmt = $this->conn->prepare("UPDATE users SET facebook_json = ?, updated_at = NOW() WHERE email = ?");
$stmt->bind_param("ss",$facebook_json, $email);
$stmt->execute();
$stmt->store_result();
/**
* Updating password for facebook_login first time
*/
public function updatePasswordFacebook($email, $password)
$stmt = $this->conn->prepare("SELECT * FROM users WHERE email = ?");
$stmt->bind_param("s", $email);
if ($stmt->execute())
$user = $stmt->get_result()->fetch_assoc();
$stmt->close();
$hash = $this->hashSSHA($password);
$encrypted_password = $hash["encrypted"];
$salt = $hash["salt"];
$stmt = $this->conn->prepare("UPDATE users SET encrypted_password=?, salt=?, updated_at = NOW() WHERE email = ?");
$stmt->bind_param("sss",$encrypted_password, $salt, $email);
$result = $stmt->execute();
$stmt->store_result();
$stmt->close();
if($result)
return true;
else
return false;
else
return false;
/**
* Encrypting password
* @param password
* returns salt and encrypted password
*/
public function hashSSHA($password)
$salt = sha1(rand());
$salt = substr($salt, 0, 10);
$encrypted = base64_encode(sha1($password . $salt, true) . $salt);
$hash = array("salt" => $salt, "encrypted" => $encrypted);
return $hash;
/**
* Decrypting password
* @param salt, password
* returns hash string
*/
public function checkhashSSHA($salt, $password)
$hash = base64_encode(sha1($password . $salt, true) . $salt);
return $hash;
?>
register.php:
<?php
require_once __DIR__ .'/include/DB_Functions.php';
$db = new DB_Functions();
// json response array
$response = array("error" => FALSE);
if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['password']))
// receiving the post params
$name = $_POST['name'];
$email = $_POST['email'];
$password = $_POST['password'];
$facebook_json = NULL;
if(isset($_POST['facebook_json']))
$facebook_json = $_POST['facebook_json'];
// check if user is already existed with the same email
if ($db->isUserExisted($email))
// user already existed
if(!($facebook_json === NULL))
$db->updateFacebookJson($email, $facebook_json);
$user = $db->getUserByEmail($email);
$response["error"] = TRUE;
$response["error_msg"] = "User already existed with " . $email;
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["facebook_json"] = $user["facebook_json"];
$response["user"]["created_at"] = $user["created_at"];
$response["user"]["updated_at"] = $user["updated_at"];
echo json_encode($response);
else
// create a new user
$user = $db->storeUser($name, $email, $password, $facebook_json);
if ($user)
// user stored successfully
$response["error"] = FALSE;
$response["uid"] = $user["unique_id"];
$response["user"]["name"] = $user["name"];
$response["user"]["email"] = $user["email"];
$response["user"]["facebook_json"] = $user["facebook_json"];
$response["user"]["created_at"] = $user["created_at"];
$response["user"]["updated_at"] = $user["updated_at"];
echo json_encode($response);
else
// user failed to store
$response["error"] = TRUE;
$response["error_msg"] = "Unknown error occurred in registration!";
echo json_encode($response);
else
$response["error"] = TRUE;
$response["error_msg"] = "Required parameters (name, email or password) is missing!";
echo json_encode($response);
?>
Exact error: Uncaught Error: Call to undefined method mysqli_stmt::get_result()
in register.php at this line: $user = $stmt->get_result()->fetch_assoc();
I am using it with android application, I am not sure if those features are supported in android application
– ddph
Sep 13 '18 at 21:28
This is specifically in regards to the PHP side of things which is not part of your Android app, but the server-side code.
– tadman
Sep 13 '18 at 21:31
Are we absolutely sure that we are using the mysqlnd native driver? The
get_result
function is available only in the native driver, it's not available (not defined) in libmysql driver. [The reported error is the behavior we expect if we we aren't using the native driver and attempt to d a get_result. [And big kudos to using prepared statements with bind placeholders!]– spencer7593
Sep 13 '18 at 21:46
get_result
Yes I am using it. I am hosting on GoDaddy and it is already included. I don't know what happened, it was working 2 days ago ...
– ddph
Sep 13 '18 at 22:09
0
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
📎: "It looks like you're writing your own ORM. Have you considered using one that's already written, tested, and widely supported like RedBeanPHP, Doctrine, Propel or Eloquent?"
– tadman
Sep 13 '18 at 21:25