Definition and usage
The mysql_connect () function opens a non-persistent MySQL connection.
Grammar
Mysql_connect (Server,user,pwd,newlink,clientflag)
| parameter |
description |
| server |
Optional. Specifies the server to connect to.
Can include a port number, such as "Hostname:port", or a path to a local socket, such as ":/path/to/socket" for localhost.
If PHP directive mysql.default_host is undefined (by default), the default value is ' localhost:3306 '. |
| user |
is optional. User name. The default value is the user name of the server process owner. |
| pwd |
is optional. Password. The default value is a blank password. |
| newlink |
Optional. If you call mysql_connect () for the second time with the same parameters, no new connection will be made and the connection ID that is already open will be returned. The parameter New_link changes this behavior and causes mysql_connect () to always open a new connection, even when mysql_connect () was previously called with the same parameters. |
| clientflag |
Optional. The Client_flags parameter can be a combination of the following constants:
-
Mysql_client_ssl-using SSL encryption
-
Mysql_client_comp RESS-Use compression protocol
-
Mysql_client_ignore_space-interval after function name
-
Mysql_client_interactive- Allow interaction timeout before closing a connection inactivity time
|
return value
If successful, returns a MySQL connection ID, which fails to return FALSE.
Hints and Notes
Note: At the end of the script, the connection to the server is closed, unless Mysql_close () has been explicitly called before.
Tip: To create a persistent connection, use the Mysql_pconnect () function.
Example
<?php$con = mysql_connect ("localhost", "Mysql_user", "mysql_pwd"), if (! $con) {die (' Could not connect: ') mysql_error ( )); }//some code ... mysql_close ($con);? >
PHP mysql_connect () function