Home  >  Article  >  Database  >  Tutorial on selecting database files using mysql_select_db() function

Tutorial on selecting database files using mysql_select_db() function

PHPz
PHPzOriginal
2017-03-12 13:26:072299browse

In PHP, after establishing a connection with the MySQL server, we need to determine the database to be connected. At this time, we can use the mysql_select_db function. This function is used to select the database that needs to be operated. Friends in need can refer to Next

mysql_select_db introduction

mysql_select_db function has two parameters:

mysql_select_db(database,connection)

If successful, the function returns true. If failed, returns false.

Parameters Description
database Required. A database needs to be selected.
connection Optional. MySQL connection. If this parameter is not set, it indicates that the previous mysql database connection is used.

mysql_select_db instance

<?php
 $host="mysql153.secureserver.net";
 $uname="root";
 $pass="password";
 
 $connection= mysql_connect ($host, $uname, $pass);
 
 if (!$connection) {
   die ("mysql连接失败"); 
 }
 
 $result=mysql_select_db ("manongjc");
 
 if (! $result) {
   die ("没有选择任何数据库");
 }
   
 echo "数据库manongjc已经选择,可以使用该数据库了";
?>

The above is the detailed content of Tutorial on selecting database files using mysql_select_db() function. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn