PHP mysqli_select_db() Function

PHP mysqli_select_db() Function is used to choose database for the connection. Also You can select the default database using 4th parameter in mysqli_connect() function.

PHP Version : PHP 5, PHP 7

Syntax for mysqli_select_db:

According to Procedural

mysqli_select_db($connection, $database_name);

According to Object oriented

$mysqli -> select_db($database_name);
$connection : Required. It is MySQL connection object which is return by mysqli_connect() function.
$database_name : Required. It is database name.

Return values for mysqli_connect:

It returns TRUE on success and  FALSE on failure.

Example for mysqli_connect:

Let's see below example to understand php mysqli_select_db() Function in details.

Example :

$connection = @mysqli_connect("localhost","username","password");
//check connection.
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL server : " . mysqli_connect_error();
@mysqli_select_db($connection, $database_name); // choose database from mysql server


Leave a Reply

Your email address will not be published. Required fields are marked *