-2

I am getting this error

H01215: PHP Warning: mysqli_select_db() expects parameter 1 to be mysqli string given in

from my website when I try to change from MYSQL to MYSQLI, why is this I am missing. I am changing every mysql_ to mysqli_

// Do we have a valid database connection and have we selected a database?
public function databaseSelected()
{
    if(!$this->isConnected()) return false;
    $result = mysql_list_tables($this->name, $this->db);
    return is_resource($result);
}

public function connect()
{
    $this->db = @mysql_connect($this->host, $this->username, $this->password) or $this->notify('Failed connecting to the database with the supplied connection details. Please check the details are correct and your MySQL user has permissions to access this database.<br/><br/>(host: '.$this->host.', user: '.$this->username.', pass: ********)');
    if($this->db === false) return false;
    mysql_select_db($this->name, $this->db) or $this->notify();             if($this->isConnected())
    {
        mysql_set_charset('UTF-8', $this->db);
        $this->query("SET NAMES utf8"); 
    }

    return $this->isConnected();
}
thadeuszlay
  • 2,787
  • 7
  • 32
  • 67
Michael JS
  • 23
  • 6

2 Answers2

1

mysqli_select_db expects first parameter to be a mysqli object.

you need to change the order of your parameters so the first parameter is a mysqli object.

mysqli_select_db($this->db, $this->name);
keune
  • 5,779
  • 4
  • 34
  • 50
  • A reference to the method documentation would make the answer even better... – arkascha Mar 16 '19 at 16:45
  • 1
    @arkascha updated. – keune Mar 16 '19 at 16:53
  • so let's say if i have this **$this->result = mysql_query($sql, $this->db) or $this->notify();** if i change it to **$this->result = mysql_query($this->db, $sql) or $this->notify();** it would work? – Michael JS Mar 16 '19 at 17:25
  • 1
    off the top of my head, yes(but with mysqli_, not mysql_), but why don't you try and see for yourself? – keune Mar 16 '19 at 17:32
0

My first observation on your code is that you are having a mysqli error while your code is mysql

The other observation is that you have missed up the parameter order for the database connection. The param order for mysql_select_db is different from mysqli_select_db Sample below:

For mysql_select_db

mysql_select_db('db_name', $con);

For mysqli_select_db

mysqli_select_db($con,"db_name");
ABODE
  • 958
  • 2
  • 15
  • 13