Change the default database for connections:
Delete database
<?php // Assume database username: root, password: 123456, database: CODERCTO $con = mysqli_connect ( " localhost " , " root " , " 123456 " , " CODERCTO " ) ; if ( mysqli_connect_errno ( $con ) ) { echo " Failed to connect to MySQL: " . mysqli_connect_error ( ) ; } // ...query some PHP code for the "CODERCTO" database... // Modify the database to "test" mysqli_select_db ( $con , " test " ) ; // ...some PHP code to query the "test" database... mysqli_close ( $con ) ; ?> Definition and usage
The mysqli_select_db() function is used to change the default database for a connection.
grammar
mysqli_select_db( connection,dbname ) ;
parameter | describe |
---|
connection | Required. Specifies the MySQL connection to use. |
dbname | Required, specifies the default database to use. |
technical details
Return value: | Returns TRUE if successful and FALSE if failed. |
---|
PHP version: | 5+ |
---|