Home > Backend Development > PHP Tutorial > Why Does mysqli_select_db() Show 'Warning: mysqli_select_db() expects exactly 2 parameters, 1 given'?

Why Does mysqli_select_db() Show 'Warning: mysqli_select_db() expects exactly 2 parameters, 1 given'?

Barbara Streisand
Release: 2024-11-29 10:54:14
Original
851 people have browsed it

Why Does mysqli_select_db() Show

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);
Copy after login

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');
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template