MySQL Select Database
After you connect to the MySQL database, there may be multiple databases that you can manipulate, so you need to select the database you want to manipulate.
Select MySQL database from the command Prompt window
In the Mysql> prompt window, you can easily select a specific database. You can use the SQL command to select the specified database.
Instance
[[email protected]]# mysql -u root -penter password:******mysql> use runoob;database changedmysql>
after executing the above command, you have successfully selected the Runoob database, which will be executed in the RUNOOB database in subsequent operations.
Note: All database names, table names, and field fields are case-sensitive. So you need to enter the correct name when using SQL commands.
Select MySQL Database using PHP script
PHP provides a function mysqli_select_db to select a database. The function returns TRUE after execution succeeds, otherwise FALSE is returned.
Grammar
mysqli_select_db (connection,dbname);
parameter |
description |
required. Specifies the MySQL connection to use. |
dbname |
Required to specify the default database to use. |
Instance
The following example shows how to use the mysqli_select_db function to select a database:
Select Database
<?php$dbhost = 'localhost:3306'; //MySQL server host address$dbuser = 'Root'; //MySQL user name$dbpass = '123456'; //mysql user name password$conn = Mysqli_connect($dbhost, $dbuser, $dbpass);if(! $conn ){ die('Connection failed:' . Mysqli_error($conn));}Echo 'Connection Successful';mysqli_select_db($conn, 'Runoob' );Mysqli_close($conn);?>
MySQL Select Database