Home >Backend Development >PHP Tutorial >Why Does mysqli_select_db() Throw a 'Warning: mysqli_select_db() expects exactly 2 parameters, 1 given' Error?
Problem:
When attempting to connect to a MySQL database using mysqli_select_db(), the following error message appears: "Warning: mysqli_select_db() expects exactly 2 parameters, 1 given." The code being used is:
<?php $connect_error = 'Sorry, we\'re experiencing connection issues.'; $con = mysqli_connect('localhost', 'root', 'PwdSQL5'); mysqli_select_db('phpcadet') or die($connect_error); ?>
Solution:
mysqli_select_db() requires two parameters: the connection link and the database name. The provided code only provides one parameter, the database name, which is why the error message is triggered.
To resolve this, the connection link obtained from mysqli_connect() should be passed as the first parameter to mysqli_select_db(). The correct code is:
mysqli_select_db($con, 'phpcadet');
This will establish the connection to the phpcadet database successfully.
The above is the detailed content of Why Does mysqli_select_db() Throw a 'Warning: mysqli_select_db() expects exactly 2 parameters, 1 given' Error?. For more information, please follow other related articles on the PHP Chinese website!