-2

So this is the error message:

PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead

This is the affected piece of code:

class wdClient {

    var $dbLink;                // The database link
    var $prefix;                // Table prefix
    var $script;                // The script running

    /**
     * Construct a new directory object.
     */
    function wdClient() {
        error_reporting(E_ALL ^ E_NOTICE);

        $this->prefix = WDDBPREFIX;

        // Connect to the database
        $this->dbLink = mysql_connect(WDDBHOST, WDDBUSER, WDDBPASSWD);

        // Select the database
        mysql_select_db(WDDBNAME, $this->dbLink) or die('Sorry, The site is currently unavailable!');
    }

where WDDBPREFIX, WDDBHOST, WDDBUSER, WDDBPASSWD, WDDBNAME are already defined in a config file.

I have tried simply using mysqli_connect instead of mysql_connect but it's not working.

Don Cruickshank
  • 5,641
  • 6
  • 48
  • 48
  • 4
    The solution is to do what it says, and switch to using MySQLi or PDO... but you have to change your queries, etc as well – Mark Baker Aug 20 '17 at 13:14
  • 1
    Switch over to `MySqli` OR `PDO` – Alive to die - Anant Aug 20 '17 at 13:16
  • See this question (https://stackoverflow.com/questions/1390607/how-could-i-change-this-mysql-to-mysqli) for more information. – Schwesi Aug 20 '17 at 13:17
  • 1
    *"Simply using mysqli_connect instead of mysql_connect it's not working."* - Depends on "how" you're using it. Maybe you used the same syntax for the parameters, or didn't pass the connection to it at all, or mixing different mysql apis. We don't know that, *you* do. – Funk Forty Niner Aug 20 '17 at 13:18
  • The problem is that I don't know how to properly use mysqli for this wdClient class. Could anyone help me? Thanks. – robertgombos Aug 20 '17 at 13:52

2 Answers2

0

well, as pointed in here http://php.net/manual/en/function.mysqli-connect.php , you should make something like this:

$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");

Apparently, in your case it will look like this:

$link = mysqli_connect(WDDBHOST, WDDBUSER, WDDBPASSWD, WDDBNAME);

And then you can continue with your code...

if (!link){
    die('Sorry, The site is currently unavailable!');
} else{
    // write your SQL here and fetch it
}
Anchor_Chisel
  • 166
  • 1
  • 8
0

Note: Never use MySQL, use this method!

//MySQLi information

        $db_host     = "localhost";
        $db_username = "username";
        $db_password = "password";

        //connect to mysqli database (Host/Username/Password)
        $connection = mysqli_connect($db_host, $db_username, $db_password) or die("Error " . mysqli_error());

        //select MySQLi dabatase table
        $db = mysqli_select_db($connection, "table") or die("Error " . mysqli_error());

Good luck!

Mr Pro Pop
  • 666
  • 5
  • 19