Search code examples
phppdophpass

Call to undefined method PDOStatement::bind_result()?


I keep getting this error message and don't know why. It is a login script and I copied form here because I didn't know how to do the login using PHPASS. Here is my code:

$email      = ($_POST['email']);
$pass       = ($_POST['pass']);

require 'connect.php';
require 'PasswordHash.php';
$hash = '*';
    $login = $con->prepare("SELECT password FROM basicuserinfo WHERE email=:email");
    $login->bindParam(':email', $email);
    $login->execute();
    $login->bind_result($hash);
    if (!$login->fetch() && $con->errno)
        die();
    if ($hasher->CheckPassword($pass, $hash)) {
        $what = 'Authentication succeeded';
    } else {
        $what = 'Authentication failed';
    }
    unset($hasher);

Solution

  • In the link that you have given, they are using MySQLi connection for MySQL related tasks. The method bind_result is one of them methods in mysqli.

    This is neither needed nor necessary in method of MySQL connections. Here's a list of valid methods/constructors and classes etc. for PDO.


    What you should instead use here is:

    $hash = $login->fetchColumn();
    

    where fetchColumn returns a single column from the next row of a result set.