In mysql, If we select to directly use in command mode and switch to the database, we can select mysql_select_db for data in php. I will introduce it below.
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:
The Code is as follows: |
Copy code |
[Root @ host] # mysql-u root-p Enter password :****** Mysql> use TUTORIALS; Database changed Mysql> |
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 a PHP script to select a MySQL database:
PHP provides the function mysql_select_db to select a database. TRUE is returned. Otherwise, FALSE is returned.
The following example shows how to select a database.
The Code is as follows: |
Copy code |
<Html> <Head> <Title> Selecting MySQL Database-by www.111cn.net </title> </Head> <Body> <? Php $ Dbhost = 'localhost: 3036 '; $ Dbuser = 'guest '; $ Dbpass = 'guest123 '; $ Conn = mysql_connect ($ dbhost, $ dbuser, $ dbpass ); If (! $ Conn) { Die ('could not connect: '. mysql_error ()); } Echo 'ccted successfully '; Mysql_select_db ('tutorial '); Mysql_close ($ conn ); ?> </Body> </Html> |