MySQL Select database use and mysql_select_db using the detailed

Source: Internet
Author: User
Tags php script

From the command prompt, select the MySQL database:

It is very simple to select a specific database mysql> prompt. Select a specific database, and you can use the SQL command.

Example:
The following is an example of selecting a database 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 tutorial database and all subsequent operations will be done.

Note: All database names, table names, and field names in the table are case-sensitive. So you will have to use the Prpoer name and give any SQL commands.

use PHP script to select MySQL database :

PHP provides a function mysql_select_db select a database. Returns true successfully, otherwise returns false.

Here is an example showing how to select a database.

The code is as follows Copy Code

<title>selecting MySQL database-by www.111cn.net</title>
<body>
<?php
$dbhost = ' localhost:3036 ';
$dbuser = ' guest ';
$dbpass = ' guest123 ';
$conn = mysql_connect ($dbhost, $dbuser, $dbpass);
if (! $conn)
{
Die (' Could not connect: '. Mysql_error ());
}
Echo ' Connected successfully ';
mysql_select_db (' tutorials ');
Mysql_close ($conn);
?>
</body>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.