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

Tutorial on selecting database files using mysql_select_db() function

PHPz
Release: 2017-03-12 13:26:07
Original
2320 people have browsed it

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)
Copy after login

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

ParametersDescription
databaseRequired. A database needs to be selected.
connectionOptional. 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已经选择,可以使用该数据库了";
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template