Home >Backend Development >PHP Tutorial >Why Does mysqli_select_db() Show 'Warning: mysqli_select_db() expects exactly 2 parameters, 1 given'?
Error: Missing Parameter in mysqli_select_db()
In a PHP script, the mysqli_select_db() function requires two parameters: the connection link and the database name to connect to. However, many developers encounter the error "Warning: mysqli_select_db() expects exactly 2 parameters, 1 given" when using this function.
Upon examination, the issue arises from a misunderstanding of the required parameters. In the example provided:
mysqli_select_db('phpcadet') or die($connect_error);
Only one parameter is being passed to the mysqli_select_db() function, which is the database name. To resolve this error, the correct usage should be:
mysqli_select_db($con, 'phpcadet');
Here, $con represents the connection link established using mysqli_connect(), and 'phpcadet' is the target database. By providing both parameters, the mysqli_select_db() function can successfully establish the connection to the specified database, allowing the script to proceed without the error.
The above is the detailed content of Why Does mysqli_select_db() Show 'Warning: mysqli_select_db() expects exactly 2 parameters, 1 given'?. For more information, please follow other related articles on the PHP Chinese website!