MySQL Select Database

Source: Internet
Author: User
Tags php script reserved

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

[[email protected]]# mysql -u root -penter password:******mysql> use  runoob;database changedmysql> 

after executing the above command, you have successfully selected the Runoob database, which will be executed in the RUNOOB 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 mysqli_select_db to select a database. The function returns TRUE after execution succeeds, otherwise FALSE is returned.

Grammar
mysqli_select_db (connection,dbname); 
parameter description
required. Specifies the MySQL connection to use.
dbname Required to specify the default database to use.
Instance

The following example shows how to use the mysqli_select_db function to select a database:

Select Database

<?php$dbhost = 'localhost:3306'; //MySQL server host address$dbuser = 'Root'; //MySQL user name$dbpass = '123456'; //mysql user name password$conn = Mysqli_connect($dbhost, $dbuser, $dbpass);if(! $conn ){     die('Connection failed:' . Mysqli_error($conn));}Echo 'Connection Successful';mysqli_select_db($conn, 'Runoob' );Mysqli_close($conn);?>


MySQL Select Database

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.