English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
mysqli_options() function sets options
mysqli_options()This feature is used to set extended options for a connection, which can change the behavior of this connection.
If you need to set multiple options, you can call this function multiple times.
The mysqli_options() function must be called after mysqli_init() and before mysqli_real_connect().
mysqli_options($con, $option, $value)
Serial Number | Parameters and Description |
---|---|
1 | con(Necessary) This is an object representing the connection to the MySQL Server. |
2 | option(Necessary) Represents the connection options to be set. It can be one of the following:
|
3 | value(Necessary) This is an integer value representing the value of the selected option. |
This function returns a boolean value, and returnstrue, and returnsfalse.
This function was originally introduced in PHP version5introduced and can be used in all higher versions.
The following examples demonstratemysqli_options()Function usage (procedural style)-
<?php //Establish connection $con = mysqli_connect("localhost", "root", "password", "test"); mysqli_options($con, MYSQLI_OPT_NET_CMD_BUFFER_SIZE, 15); if($con){ print("Connection established successfully"); }else{ print("Connection failed "); } ?>
Output result
Connection established successfully
In the object-oriented style, the syntax of this function is$con-> options();.The following is an example of this function in object-oriented style;
<?php //Establish connection $con = new mysqli("localhost", "root", "password", "test"); $con->options(MYSQLI_OPT_NET_CMD_BUFFER_SIZE, 15); if($con){ print("Connection established successfully"); }else{ print("Connection failed "); } ?>
Output result
Connection established successfully
In the object-oriented style, the syntax of this function is$con-> options();.The following is an example of this function in object-oriented style;
<?php $connection_mysql = mysqli_init(); if (!$connection_mysql){ die("mysqli_init failed"); } mysqli_options($connection_mysql, MYSQLI_OPT_CONNECT_TIMEOUT, 10); mysqli_options($connection_mysql, MYSQLI_READ_DEFAULT_FILE, "configure.cnf"); $connection_mysql = mysqli_real_connect($connection_mysql, "localhost", "root", "password", "mydb"); if (!$connection_mysql){ print("Connection error: " . mysqli_connect_error()); }else{ print("Connection successful"); } ?>
Output result
Connection successful