Tutorial: Solve mysqli_select_db method expects different type than given string (PHP)

Solve mysqli_select_db method expects different type than given string

As many people noticed in the tutorial on how to solve deprecated MySQL extension issues, I want to explain now how to solve the typical PHP error Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given now.










How to solve the warning?


Currently your code most likely looks like that:

<?php
// Database connection code
mysql_select_db('database_name', $link);


The correct way to call this PHP method to select the wished MySQL database is to reverse the order of the parameters. The connection link identifier passed from your connection method needs to be the first parameter, as second parameter the database name is required in the procedural style.
The correct way would look like that:

<?php
// Database connection code
// Correct way in procedural style
mysql_select_db($link, 'database_name');

In case you're using the OOP way of using the PHP methods it would look like that:

<?php
// Database connection code
// Correct way in OOP style
$link->select_db('database_name');

If you have any further questions: Just leave them below in the comment section.


Source: PHP Manual


Published by on 01. December 2016