PHP provides the mysql_connect() function to open a database connection. This function accepts five parameters and returns a MySQL connection identifier on success and FALSE on failure. The syntax is as follows:
connection mysql_connect(server,user,passwd,new_link,client_flag);
The following table shows the parameters used in the above syntax:
Serial number | Parameters and description |
1 |
Server Optional - The hostname where the database server is running. If not specified, the default is localhost:3306 |
2 |
user Optional - Username to access the database. If not specified, defaults to the name of the user who owns the server process |
3 |
Password Optional - The password of the user accessing the database. If not specified, defaults to an empty password |
##new_link | Optional - If a second call to mysql_connect() is made with the same parameters, no new connection is established; instead the identifier of the already open connection is returned |
client_flags |
Optional - A combination of the following constants:
|
The above is the detailed content of Which is the PHP function used to establish a MySQL database connection using PHP script?. For more information, please follow other related articles on the PHP Chinese website!