Mysql_connect () for establishing and disabling database connections in PHP ()
Resource mysql_connect
([String hostname
[: Port] [:/path/to/socket]
[, String username] [, string password])
All parameters are optional.
Example:
- @mysql_connect("localhost"
, "user", "password")
- or die("Could not connect
to mysql server!");
Note: The @ symbol indicates any error message caused by a failed attempt. You will see the error message specified in die.
Note: When connecting to multiple mysql databases, you must specify the link ID of each connection, as shown below:
- $link1 = @mysql_connect
("server1", "user", "password")
- or die("Could not connect to
mysql server!");
- $link2 = @mysql_connect
("server2", "user", "password")
- or die("Could not
connect to mysql server!");
-
Mysql_pconnect () for establishing and disabling database connections in PHP ()
- resource mysql_pconnect
([string hostname [:port]
[:/path/to/socket][,string
username] [,string password]])
Different from mysql_connect (), the existing link is first searched for and is created only when the link does not exist.
Note that you do not need to display the close connection (mysql_close (), because the connection will be placed in the pool, it is called a persistent connection.
Mysql_close () for establishing and disabling database connections in PHP ()
- boolean mysql_close
([resource link_id])
Closing the connection is not required because it can be handled by mysql garbage collection.
If link_id is not specified, the latest link is closed.