PHP mysqli_options()Functions
Examples
Open a new connection to the MySQL server:
<?php
$con=mysqli_init();
if (!$con)
{
die("mysqli_init failed");
}
mysqli_options($con,MYSQLI_READ_DEFAULT_FILE,"myfile.cnf");
if (!mysqli_real_connect($con,"localhost","my_user","my_password","my_db"))
{
die("Connection error: " . mysqli_connect_error());
}
mysqli_close($con);
?>
$con=mysqli_init();
if (!$con)
{
die("mysqli_init failed");
}
mysqli_options($con,MYSQLI_READ_DEFAULT_FILE,"myfile.cnf");
if (!mysqli_real_connect($con,"localhost","my_user","my_password","my_db"))
{
die("Connection error: " . mysqli_connect_error());
}
mysqli_close($con);
?>
Definition and Usage
The mysqli_options() function sets additional connection options to affect connection behavior.
The mysqli_options() function can be called multiple times to set several options.
Note:The mysqli_options() function can be called aftermysqli_init()and beforemysqli_real_connect()being called.
Syntax
mysqli_options(connection,option,value);
| Parameters | Description |
|---|---|
| connection | Required. Specifies the MySQL connection to use. |
| option | Required. Specifies the option to set. Can be one of the following values:
|
| value | Required. Specifies theoptionvalue of. |
Technical Details
| Return value: | Returns TRUE on success, or FALSE on failure. |
|---|---|
| PHP Version: | 5+ |
| Changelog: | The MYSQLI_SERVER_PUBLIC_KEY option was added in PHP 5.5. |
PHP MySQLi Reference Manual Other Extensions