PHP must first connect to the specified database to operate the database. You can use the PHP mysql_connect function to connect to the database. This article introduces how to use the mysql_connect function and examples. Friends who need it can refer to it
Introduction to mysql_connect
php mysql_connect is used to connect to the mysql server. This function has multiple parameters, but we generally only need to understand the following three parameters:
mysql_connect(server,user,pwd)
Parameter introduction:
server -- mysql server address
user -- server user name
pwd -- Server login password
If the connection is successful, a MySQL connection ID will be returned. If the connection fails, FALSE will be returned.
mysql_connect instance
<?php $host="mysql153.secureserver.net"; $uname="root"; $pass="password"; $connection= mysql_connect ($host, $uname, $pass); if (! $connection) { die ("mysql服务器连接失败"); } else { echo "恭喜你!mysql服务器连接成功"; } ?>
The above is the entire content of this article, I hope it will be helpful to everyone's learning.
Related recommendations:
How predis implements the pconnect method of phpredis
Recommended 10 articles about php connection_aborted() function
php mysqli operation mysqli_connect Detailed explanation of connecting to database instance
The above is the detailed content of php mysql operation mysql_connect connects to the database. For more information, please follow other related articles on the PHP Chinese website!