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
The following example selects the database tutorials:
[[email protected]]#--pEnter password:* * * * * *mysql> use Tutorials; Database changedmysql>
After executing the above command, you have successfully selected the tutorials database, which will be executed in the tutorials 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 mysql_select_db to select a database. The function returns TRUE after execution succeeds, otherwise FALSE is returned.
Grammar
BOOL mysql_select_db( db_name,);
Parameters |
Description |
Db_name |
Necessary. Specifies the database to select. |
Connection |
Optional. Specify MySQL connection. If not specified, the previous connection is used. |
Instance
The following example shows how to use the mysql_select_db function to select a database:
<title>Selecting MySQL Database</title><body><?Php$dbhost= ' localhost:3036 ';$dbuser= ' Guest ';$dbpass= ' Guest123 ';$conn=Mysql_connect($dbhost,$dbuser,$dbpass);If(! $conn ) { ( ' Could not connect: ' . Mysql_error}echo ' Connected successfully ' mysql_select_db ( ' tutorials ' ); mysql_close ( $conn ?></body>
MySQL Select Database