I can't create a DB connection


#1

I have this code:

<?php

/**
 * A class file to connect to database
 */
class DB_CONNECT {

    // constructor
    function __construct() {
        // connecting to database
        $this->connect();
    }

    // destructor
    function __destruct() {
        // closing db connection
        $this->close();
    }

    /**
     * Function to connect with database
     */
    function connect() {
        // import database connection variables
        require_once __DIR__ . '/db_config.php';
        echo "conect";
       
        
        
        // Connecting to mysql database
        $con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());
        echo $con;
        
        echo "select";

        // Selecing database
        $db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
        echo $db;
        // returing connection cursor
        return $con;
    }

    /**
     * Function to close db connection
     */
    function close() {
        // closing db connection
        mysql_close();
    }

}

?>

But the connection isn’t work. Can someone help me?


#2

Hi !

mysql_* set is deprecated. We encourage you to use mysqli_* instead.

If you still want to make use of mysql_* set, please lower your PHP version to 5.6 from Settings > General


#3

I put mysqli_* instead of mysql_* but it isn’t work.


#4

What errors do you get?