English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
After you connect to the MySQL database, there may be multiple databases available for operation, so you need to select the database you want to operate.
You can easily select a specific database in the mysql> prompt window. You can use SQL commands to select the specified database.
The following examples select the database w3codebox:
[root@host]# mysql -u root -p Enter password:****** mysql> use w3codebox; Database changed mysql>
After executing the above command, you have successfully selected w3The codebox database, in subsequent operations, will be in the w3Executed in the codebox database.
Note:All database names, table names, and table fields are case-sensitive. Therefore, you need to enter the correct names when using SQL commands.
PHP provides the function mysqli_select_db to select a database. The function returns TRUE on success, otherwise it returns FALSE.
mysqli_select_db(connection,dbname);
Parameters | Description |
---|---|
connection | Required. Specify the MySQL connection to use. |
dbname | Required, specify the default database to use. |
The following example demonstrates how to use the mysqli_select_db function to select a database:
<?php $dbhost = 'localhost'; // MySQL Server Host Address $dbuser = 'root'; // MySQL Username $dbpass = '123456'; // MySQL Username and Password $conn = mysqli_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Connection Failed: ' . mysqli_error($conn)); } echo 'Connection Successful'; mysqli_select_db($conn, 'w3codebox' ); mysqli_close($conn); ?>