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

Why Does `mysqli_select_db()` Give a 'Warning: mysqli_select_db() expects exactly 2 parameters, 1 given' Error?

Mary-Kate Olsen
Release: 2024-11-30 02:13:10
Original
362 people have browsed it

Why Does `mysqli_select_db()` Give a

mysqli_select_db() Function Parameter Error

The mysqli_select_db() function is used to select a specific database within a MySQL server connection. However, when providing insufficient parameters to this function, you may encounter a warning message: "Warning: mysqli_select_db() expects exactly 2 parameters, 1 given."

To resolve this error, ensure that you provide the correct number of parameters to the mysqli_select_db() function. As the error message suggests, this function expects exactly two parameters:

  • $link: The connection resource (link) established using mysqli_connect()
  • $dbname: The name of the database you wish to select

In your provided code snippet, you have only provided one parameter: the database name. To fix the error, you need to pass both the connection link and the database name as follows:

mysqli_select_db($con, 'phpcadet');
Copy after login

By providing the correct parameters, you will establish a connection to the desired database and prevent the "expects exactly 2 parameters" error.

The above is the detailed content of Why Does `mysqli_select_db()` Give 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!

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