0

I am new in PHP. I have got one API which have most of functions like below

function getUserByEmail($conn,$email)
    {
        $user = $conn->prepare("SELECT * FROM table_users WHERE email = ?");
        $user->bind_param("s", $email);
        $user->execute();
        $result = $user->get_result();
        $data = $result->fetch_assoc();
        $user->close();
        return $data;
    }

Its working fine in one of my hosting with namecheap which have nd_mysqli enabled. But in my hostgator hosting, its giving error.

Uncaught Error: Call to undefined method mysqli_stmt::get_result() in

I am unable to enable that extension in Hostgator so I want replace it with answers written here or other way.

But I am not getting idea how I can do it.

RN92
  • 1,168
  • 1
  • 12
  • 30
Raju Bhatt
  • 365
  • 4
  • 14

1 Answers1

0

bind result

So if the MySQL Native Driver (mysqlnd) driver is not available, and therefore using bind_result and fetch instead of get_result, the code becomes:

if ($stmt = $mysqli->prepare("SELECT col1,col2 FROM table_users WHERE email = ?")) {
    $stmt->bind_param("s", $email);
    $stmt->execute();

    /* bind variables to prepared statement */
    $stmt->bind_result($col1, $col2);

    /* fetch values */
    while ($stmt->fetch()) {
        printf("%s %s\n", $col1, $col2);
    }

    /* close statement */
    $stmt->close();
 }