Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP mysqli_options() Function.
The PHP mysqli_options() function is used for setting extra connection option. If you want to set multiple options then you need to invoke the PHP function multiple times.
The PHP mysqli_options() function is used for setting extra connection option. If you want to set multiple options then you need to invoke the PHP function multiple times.
Syntax
Following below is the syntax to use this function -
mysqli_options($con, $option, $value)
Parameter Details
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 Value
This built-in PHP function returns true on success and false on failure.
PHP Version
This PHP function was first introduced in PHP version 5 and it works in all the later versions.
Example1
The following example illustrates the usage of the built-in mysqli_options() function (in a 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 "); } ?>
Output
When the above code is executed, it will produce the following result -
Connection Established Successfully
Example2
In an object oriented style the syntax of this built-in PHP function is $con->options(); The following is the example of this function in an 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 "); } ?>
Output
When the above code is executed, it will produce the following result -
Connection Established Successfully
Example3
The following below is another example of the built-in PHP mysqli_options() function in an 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"); } ?>
Output
When the above code is executed, it will produce the following result -
Connection was successful
Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the PHP mysqli_ping() Function.
Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Do follow us on our various social media handles available and also subscribe to our newsletter to get our tutorial posts delivered directly to your emails.
Thanks for reading and bye for now.
Do feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Do follow us on our various social media handles available and also subscribe to our newsletter to get our tutorial posts delivered directly to your emails.
Thanks for reading and bye for now.