-1

I am getting an error when running a certain method in PHP. I looked into it and it seems I need the mysqlnd driver. I understand I have to configure this in the php.ini file but since I have shared hosting with GoDaddy, I don't have access to the ini file. I called GoDaddy and they basically said, you have to create your own. My question is, where is the ini file placed in my case? would I need to create a php.ini file or a php5.ini. Also, how would I write the settings in the file, I have never worked with an ini file and I don't really know how it looks.

DB_Functions.php code:

<?php

class DB_Functions {

    private $con;

    function __construct() {
        require_once 'DB_Connect.php';

        $db = new DB_Connect();
        $this->con = $db->connect();
    }

    function __destruct() {

    }

    public function storeUser($name, $email, $password) {
        $uuid = uniqid('', true);
        $hash = $this->hashSSHA($password);
        $encrypted_password = $hash['encrypted'];
        $salt = $hash['salt'];

        $stmt = $this->con->prepare("INSERT INTO users(unique_id, name, email, encrypted_password, salt, created_at) VALUES(?, ?, ?, ?, ?, NOW())");
        $stmt->bind_param('sssss', $uuid, $name, $email, $encrypted_password, $salt);
        $result = $stmt->execute();
        $stmt->close();

        if ($result) {
            $stmt = $this->con->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;
        }
    }

    public function getUserByEmailAndPassword($email, $password) {
        $stmt = $this->con->prepare("SELECT * FROM users WHERE email = ?");

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

        if ($stmt->execute()) {
            $user = $stmt->get_result()->fetch_assoc();
            $stmt->close();

            $salt = $user['salt'];
            $encrypted_password = $user['encrypted_password'];
            $hash = $this->checkhashSSHA($salt, $password);

            if ($encrypted_password == $hash) {
                return $user;
            }
        } else {
            return NULL;
        }
    }

    public function getUserByNameAndPassword($name, $password) {
        $stmt = $this->con->prepare("SELECT * FROM users WHERE name = ?");

        $stmt->bind_param('s', $name);

        if ($stmt->execute()) {
            $user = $stmt->get_result()->fetch_assoc();
            $stmt->close();

            $salt = $user['salt'];
            $encrypted_password = $user['encrypted_password'];
            $hash = $this->checkhashSSHA($salt, $password);

            if ($encrypted_password == $hash) {
                return $user;
            }
        } else {
            return NULL;
        }
    }

    public function doesUserEmailExist($email) {
        $stmt = $this->con->prepare("SELECT email FROM users WHERE email = ?");

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

        $stmt->execute();

        $stmt->store_result();

        if ($stmt->num_rows > 0) {
            $stmt->close();
            return true;
        } else {
            $stmt->close();
            return false;
        }
    }

    public function doesUserNameExist($name) {
        $stmt = $this->con->prepare("SELECT name FROM users WHERE name = ?");

        $stmt->bind_param('s', $name);

        $stmt->execute();

        $stmt->store_result();

        if ($stmt->num_rows > 0) {
            $stmt->close();
            return true;
        } else {
            $stmt->close();
            return false;
        }
    }

    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;
    }

    public function checkhashSSHA($salt, $password) {
        $hash = base64_encode(sha1($password . $salt, true) . $salt);

        return $hash;
    }

}

?>

I am getting error on two lines that use the same code.

$user = $stmt->get_result()->fetch_assoc();
Alexiz Hernandez
  • 609
  • 2
  • 9
  • 31

3 Answers3

0

The location of php.ini will depend on the type of hosting account you have. According to GoDaddy:

enter image description here

See https://www.godaddy.com/help/what-filename-does-my-php-initialization-file-need-to-use-8913 for more details.

If mysqlnd is not already compiled and installed by GoDaddy, however, you will most likely not be able to solve anything by having a local php.ini file. You can see what modules are installed by creating a small PHP file (for example test.php) that contains this:

<?php phpinfo(); ?>

Put that in your HTML docroot, load the file's URL in your browser, and it will tell you what PHP modules are available.

If mysqlnd is actually available, there are a few (not many) options you can configure with a local php.ini file. See here: http://php.net/manual/en/mysqlnd.config.php

David White
  • 1,763
  • 2
  • 16
  • 27
0

you can create php.ini file like so :

  1. if you're a windows user fire-up a new blank notepad file write something and 'save as' php.ini

  2. if you're a mac user, fire-up text-edit write something go to the "format" menu then choose "make plain text" then save as 'php.ini

typical content looks like this:

display_errors = Off error_reporting = 0

In your case you might need to set a path depending on the exact error message. What is the error message you get?

mysql.default_socket="/your/path/to/mysql.sock"

save changes and upload to your website root e.g. public_html

Replace:

$user = $stmt->get_result()->fetch_assoc();

With:

$stmt->bind_result();
$user = $stmt->fetch();
Sean
  • 63
  • 1
  • 2
  • 10
  • The error that I am getting in my log file is: PHP Fatal error: Call to undefined method mysqli_stmt::get_result() in /home/user/public_html/include/DB_Functions.php on line 33. – Alexiz Hernandez Mar 10 '16 at 23:57
  • Can you post the Db_Functions.php code that you're using or at least the complete method in and around line 33 from this file. mysqli_stmt::get_result() is only available at PHP v5.3.0 or above. – Sean Mar 11 '16 at 00:17
  • Also, have you verified that the MySQL Native Driver (mysqlnd) driver is installed on your Godaddy host by looking at the phpinfo file? – Sean Mar 11 '16 at 00:23
  • Yes, I will edit question to provide DB_Functions.php code. I had seen that question before and saw that PHP v5.3.0 is needed and I am running v5.4.0. And I did run the phpinfo file and I did notice that it says that mysqlnd is available. – Alexiz Hernandez Mar 11 '16 at 06:23
  • I updated my answer few days ago - please let me know if this worked for you. Also please up/down vote if possible. Good luck! – Sean Mar 16 '16 at 13:35
0

it sounds like you are getting "Fatal error: Call to undefined method mysqli_stmt::get_result()"

if so, you have to make sure that you do have "mysqlnd" enabled, the easiest way to know that by building a php info page enter link description here it should be like this: enter image description here

from Godaddy Cpanel, make sure that you are using the latest php version. from there "php Extensions" make sure to enable "-mysqlnd & -nd_mysql & -nd_mysqli & -nd_pdo_mysql"

that way you will get rid of the fatal error and your script should work fine!

Saeed
  • 1