Select a simple example for MySQL database connection.
Once the connection to the MySQL server is obtained, You need to select a specific database. This is because the MySQL server may have more than one database.
From the command prompt, select MySQL database:
This is very easy to choose a specific database mysql> prompt. Select a specific database and use SQL commands.
Example:
The following is an example. The database is called TUTORIALS:
[root@host]# mysql -u root -pEnter password:******mysql> use TUTORIALS;Database changedmysql>
Now you have selected the tutorial database and all subsequent operations will be performed.
Note: All Database names, table names, and field names in the table are case sensitive. Therefore, you will have to use the prpoer name and give any SQL command.
Use the PHP script to select the MySQL database:
PHP provides the function mysql_select_db to select a database. TRUE is returned. Otherwise, FALSE is returned.
Syntax:
bool mysql_select_db( db_name, connection );
Example:
The following example shows how to select a database.