MySQL Select Database

Source: Internet
Author: User
Tags php script

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

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.