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

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

Barbara Streisand
Release: 2024-12-26 02:22:08
Original
170 people have browsed it

Why Does mysqli_select_db() Throw a

PHP Warning: mysqli_select_db() Parameters Confusion

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

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

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!

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