PHP login database connection error
<p>I am using following code to connect to an <strong>sql database on a web hosting server</strong>.
I am facing the error       </p>

<blockquote>
  <p>Warning: mysqli::mysqli(): (HY000/2002): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in /srv/disk7/2067595/www/envoycc.atwebpages.com/DB_Connect.php on line 10</p>
</blockquote>

<p>The 10th line is <code>$this-&gt;conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);</code></p>

<p>My overall code is</p>

<p>config.php</p>

<pre><code> &lt;?php

 /**
 * Database config variables
 */
define("DB_HOST", "localhost");
define("DB_USER", "2067595_android");
define("DB_PASSWORD", "password");
define("DB_DATABASE", "2067595_android");
?&gt;
</code></pre>

<p>DB_Connect.php</p>

<pre><code>&lt;?php
class DB_Connect {
private $conn;

// Connecting to database
public function connect() {
    require_once 'config.php';

    // Connecting to mysql database
    $this-&gt;conn = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);

    // return database handler
    return $this-&gt;conn;
}
}

?&gt;
</code></pre>

<p>DB_Functions.php</p>

<pre><code>&lt;?php

class DB_Functions {

    private $conn;

    // constructor
    function __construct() {
        require_once 'DB_Connect.php';
        // connecting to database
        $db = new Db_Connect();
        $this-&gt;conn = $db-&gt;connect();
    }

    // destructor
    function __destruct() {

    }

    /**
     * Storing new user
     * returns user details
     */
    public function storeUser($name, $email, $password) {
        $uuid = uniqid('', true);
        $hash = $this-&gt;hashSSHA($password);
        $encrypted_password = $hash["encrypted"]; // encrypted password
        $salt = $hash["salt"]; // salt

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

        // check for successful store
        if ($result) {
            $stmt = $this-&gt;conn-&gt;prepare("SELECT * FROM users WHERE email = ?");
            $stmt-&gt;bind_param("s", $email);
            $stmt-&gt;execute();
            $user = $stmt-&gt;get_result()-&gt;fetch_assoc();
            $stmt-&gt;close();

            return $user;
        } else {
            return false;
        }
    }

    /**
     * Get user by email and password
     */
    public function getUserByEmailAndPassword($email, $password) {

        $stmt = $this-&gt;conn-&gt;prepare("SELECT * FROM users WHERE email = ?");

        $stmt-&gt;bind_param("s", $email);

        if ($stmt-&gt;execute()) {
            $user = $stmt-&gt;get_result()-&gt;fetch_assoc();
            $stmt-&gt;close();
            return $user;
        } else {
            return NULL;
        }
    }

    /**
     * Check user is existed or not
     */
    public function isUserExisted($email) {
        $stmt = $this-&gt;conn-&gt;prepare("SELECT email from users WHERE email = ?");

        $stmt-&gt;bind_param("s", $email);

        $stmt-&gt;execute();

        $stmt-&gt;store_result();

        if ($stmt-&gt;num_rows &gt; 0) {
            // user existed 
            $stmt-&gt;close();
            return true;
        } else {
            // user not existed
            $stmt-&gt;close();
            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" =&gt; $salt, "encrypted" =&gt; $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;
    }

}

?&gt;
</code></pre>

<p>login.php</p>

<pre><code>&lt;?php
require_once 'DB_Functions.php';
$db = new DB_Functions();

// json response array
$response = array("error" =&gt; FALSE);

if (isset($_POST['email']) &amp;&amp; isset($_POST['password'])) {

    // receiving the post params
    $email = $_POST['email'];
    $password = $_POST['password'];

    // get the user by email and password
    $user = $db-&gt;getUserByEmailAndPassword($email, $password);

    if ($user != false) {
        // use is found
        $response["error"] = FALSE;
        $response["uid"] = $user["unique_id"];
        $response["user"]["name"] = $user["name"];
        $response["user"]["email"] = $user["email"];
        $response["user"]["created_at"] = $user["created_at"];
        $response["user"]["updated_at"] = $user["updated_at"];
        echo json_encode($response);
    } else {
        // user is not found with the credentials
        $response["error"] = TRUE;
        $response["error_msg"] = "Login credentials are wrong. Please try again!";
        echo json_encode($response);
    }
} else {
    // required post params is missing
    $response["error"] = TRUE;
    $response["error_msg"] = "Required parameters email or password is missing!";
    echo json_encode($response);
}
?&gt;
</code></pre>