Change the default database for the connection: in PHP

Description

The following code shows how to change the default database for the connection:.

Example


/*w ww .j  a v  a 2 s.c om*/
<?php
     $con=mysqli_connect("localhost","root","","test");
     // Check connection
     if (mysqli_connect_errno()){
         echo "Failed to connect to MySQL: " . mysqli_connect_error();
     }

     // ...some PHP code for database "my_db"...

     // Change database to "test"
     mysqli_select_db($con,"test");

     // ...some PHP code for database "test"...

     mysqli_close($con);
?>




















Home »
  PHP Tutorial »
    MySQL »




MySQLi
MySQLi Object Oriented