Josh Potter
Josh Potter

Reputation: 1719

Going from MySQL to MySQLi

I recently have started coding PHP again and I have noticed that the function MySQL is now deprecated and I can either use PDO or MySQLi. Well I've been using this script http://evolt.org/PHP-Login-System-with-Admin-Features/ and I am very confused. I moved everything from MySQL_ to MySQLi_ and I now have this errors:

Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\wamp\www\website\include\database.php on line 25

And here is my code

$this->connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysqli_error());
mysqli_select_db(DB_NAME, $this->connection) or die(mysqli_error());

I don't see anything wrong with my code either, very confusing...

Upvotes: 1

Views: 112

Answers (1)

pavel
pavel

Reputation: 27082

You switched parameters of mysqli_select_db function, see the Manual.

First has to be mysqli link, second DB name.

mysqli_select_db($this->connection, DB_NAME);

In Mysqli you can pass DB_NAME directly in mysqli_connect as a fourth parameter too.

mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);

Upvotes: 3

Related Questions