PHP mysqli_options() Function
Definition and Usage
The mysqli_options() function used to set extra connection option. If you want to set multiple options you need to invoke this function multiple times.
Syntax
mysqli_options($con, $option, $value)
Parameters
Sr.No | Parameter & Description |
---|---|
1 | con(Mandatory) This is an object representing a connection to MySQL Server. |
2 | option(Mandatory) This is an integer value representing the connection option you want to set. It can be one of the following −
|
3 | value(Mandatory) This is an integer value representing the value of the selected option. |
Return Values
This function returns the boolean value which is true if successful and false incase of a failure.
PHP Version
This function was first introduced in PHP Version 5 and works works in all the later versions.
Example
Following example demonstrates the usage of the mysqli_options() function (in procedural style) −
<?php
//Creating the 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 ");
}
?>
This will produce following result −
Connection Established Successfully
Example
In object oriented style the syntax of this function is $con-> options(); Following is the example of this function in object oriented style $minus;
<?php
//Creating the 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 ");
}
?>
This will produce following result −
Connection Established Successfully
Example
In object oriented style the syntax of this function is $con-> options(); Following is the example of this function in object oriented style $minus;
<?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("Connect Error: " . mysqli_connect_error());
}else{
print("Connection was successful");
}
?>
This will produce following result −
Connection was successful