PHP mysqli_real_connect() Function
Example
Open a new connection to the MySQL server:
Definition and Usage
The mysqli_real_connect() function opens a new connection to the MySQL server.
The mysqli_real_connect() function differs from mysqli_connect() in the following ways:
- mysqli_real_connect() requires a valid object created by mysqli_init() .
- mysqli_real_connect() can be used together with mysqli_options() to set different connection options.
- mysqli_real_connect() has a flag parameter.
Syntax
mysqli_real_connect(
connection,host,username,password,dbname,port,socket,flag
)
;
| Parameters | Description |
|---|---|
| connection | Required. Specifies the MySQL connection to use. |
| host | Optional. Specifies the hostname or IP address. |
| username | Optional. Specifies the MySQL username. |
| password | Optional. Specifies the MySQL password. |
| dbname | Optional. Specifies the default database to use. |
| port | Optional. Specifies the port number to use when attempting to connect to the MySQL server. |
| socket | Optional. Specifies the socket or named pipe to use. |
| flag | Optional. Specifies different connection options. Possible values: |
Technical Details
| Return Value: | Returns TRUE on success, FALSE on failure. |
|---|---|
| PHP Version: | 5+ |
PHP MySQLi Reference Manual