Home >Backend Development >PHP Tutorial >Why Does mysqli_select_db() Throw a 'Parameter Mismatch' Warning in PHP?
Parameter Mismatch in mysqli_select_db()
When working with PHP and MySQL, you may encounter an error message stating "Warning: mysqli_select_db() expects exactly 2 parameters, 1 given." This error arises when using the mysqli_select_db() function to switch to a database within a PHP script.
Understanding the Error
The mysqli_select_db() function requires two parameters: the connection link and the database name. The connection link is established using the mysqli_connect() function, and the database name represents the database you wish to access.
Solution
To resolve this error, ensure that you provide both the connection link and the database name as parameters to the mysqli_select_db() function. For instance, in the provided code:
$con = mysqli_connect('localhost', 'root', 'PwdSQL5'); mysqli_select_db($con, 'phpcadet') or die($connect_error);
In this example, $con represents the connection link, and phpcadet is the database name. By providing these two parameters, mysqli_select_db() will correctly establish a connection to the desired database.
The above is the detailed content of Why Does mysqli_select_db() Throw a 'Parameter Mismatch' Warning in PHP?. For more information, please follow other related articles on the PHP Chinese website!