Wu Yuxiong - natural born MySQL study notes: MySQL database selection

After connecting to the MySQL database, there may be multiple databases can operate, so you need to select the database you want to operate. 
Select the MySQL database from the command prompt window 
in MySQL > prompt window can be very simple to select a specific database. You can use SQL commands to select the specified database. 
The following examples selected database RUNOOB: 
[root @ Host] # MySQL -u root -p 
the Enter password: ****** 
MySQL > use RUNOOB; 
Database changed 
MySQL > 

After executing the above command, has successfully chosen RUNOOB database, RUNOOB are performed in subsequent database operations. 
Note: All database names, table names, table fields are case sensitive. Therefore, when using the SQL commands required to enter the correct name.
MySQL database using PHP script to select 
PHP provides functions mysqli_select_db to select a database. After performing the function returns TRUE if successful, otherwise FALSE. 
Syntax 
mysqli_select_db (connection, dbname);

 

 

The following example shows how to use mysqli_select_db function to select a database:
 < PHP? 
$ Dbhost = ' localhost: 3306 ' ; // MySQL server host address 
$ dbuser = ' root ' ; // MySQL username 
$ dbpass = ' 123456 ' ; // MySQL username and password 
$ Conn = mysqli_connect ($ dbHost, dbuser $, $ dbpass);
 IF ($ Conn!) 
{ 
    Die ( ' connection failed: ' . mysqli_error ($ Conn)); 
} 
echo ' successful connection '  ;
mysqli_select_db ($ conn,'RUNOOB' );
mysqli_close($conn);
?>

 

Guess you like

Origin www.cnblogs.com/tszr/p/12113006.html