PHP mysqli_select_db() Function

Definition

The mysqli_select_db() function changes the default database.

Syntax

PHP mysqli_select_db() Function has the following syntax.

mysqli_select_db(connection,dbname);

Parameter

ParameterIs RequiredDescription
connectionRequired.MySQL connection to use
dbnameRequired.Default database to use

Return

It returns TRUE on success. FALSE on failure.

Example

Change the default database


<?php//www .j  a v a  2s  . c o  m
    $con=mysqli_connect("localhost","my_user","my_password","my_db");
    if (mysqli_connect_errno($con)){
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }
    
    // Change database to "test"
    mysqli_select_db($con,"test");
    
    
    mysqli_close($con);
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions