-2

I am working on a project where I have a DB_Functions.php file to store all needed PHP functions.

Here is one of them:

public function getUserByEmailAndPassword($email, $password) {

      $stmt = $this->conn->prepare("SELECT id,  email, encrypted_password, salt,imagen,nombre,apellidos,created_at,unique_id,nivel_usuario,verified,cel_verificado,tel FROM users WHERE email = ?");

      $stmt->bind_param("s", $email);

      if ($stmt->execute()) {
        $stmt-> bind_result($token1,$token3,$token4,$token5,$token6,$token7,$token8,$token9, $token10,$token11,$token12,$token13,$token14);

        while ( $stmt-> fetch() ) {
          $user["id"] = $token1;
         
          $user["email"] = $token3;
          $user["encrypted_password"] = $token4;
          $user["salt"] = $token5;
          $user["imagen"] = $token6;
          $user["nombre"] = $token7;
          $user["apellidos"] = $token8;
          $user["created_at"] = $token9;
          $user["unique_id"] = $token10;
          $user["nivel_usuario"] = $token11;
          $user["verified"] = $token12;
          $user["cel_verificado"] = $token13;
          $user["tel"] = $token14;
          

        }

            // verifying user password

        $encrypted_password = $user['encrypted_password'];

            // check for password equality
        if (password_verify($password, $encrypted_password)) {
                // user authentication details are correct
          return $user;
        }
      } else {
        return NULL;
      }
    }

I am using the same file DB_Functions.php on two different servers.

Server 1 is a hosted web server with PHP 7.4 (ea-php74). Server 2 is a AWS Ubuntu instance with PHP 7.4.11 (Zend).

On server 1 I am not getting any error using above mentioned function.

On server 2 I am getting following error:

PHP Fatal error:  Uncaught Error: Call to a member function bind_param() on bool in /var/www/html/android_api/include/DB_Functions.php:1942\nStack trace:\n#0 /var/www/html/android_api/login.php(17): DB_Functions->getUserByEmailAndPassword()\n#1 {main}\n  thrown in /var/www/html/android_api/include/DB_Functions.php on line 1942

What should I do to get the function working on server 2?

mvasco
  • 4,965
  • 7
  • 59
  • 120

1 Answers1

-2

Have a look to what does method mysqli::prepare return https://www.php.net/manual/fr/mysqli.prepare.php

"mysqli_prepare() returns a statement object or FALSE if an error occurred."

Error says that $smtp is a bool and you are trying to use bind_param method on a bool. Have a look to the last $smtp assignation. Regarding what does the prepare method can return, it look like the method returned false. So there were an error while trying to prepare the statement.

magrigry
  • 405
  • 2
  • 8