w3resource

PHP MySQLi: options() function

mysqli_options() function / mysqli::options

The mysqli_options() function / mysqli::options sets extra connect options and affect behavior for a connection.

This function can be called several times to set several options.

Syntax:

Object oriented style

bool mysqli::options ( int $option , mixed $value )

Procedural style

bool mysqli_options ( mysqli $link , int $option , mixed $value )

Parameter:


Name Description Required/Optional
link A link identifier returned by mysqli_connect() or mysqli_init() Required for procedural style only and Optional for Object oriented style
option The option that you want to set. It can be one of the following values: Required for procedural style only and Optional for Object oriented style
Name Description
MYSQLI_OPT_CONNECT_TIMEOUT connection timeout in seconds (supported on Windows with TCP/IP since PHP 5.3.1)
MYSQLI_OPT_LOCAL_INFILE enable/disable use of LOAD LOCAL INFILE
MYSQLI_INIT_COMMAND command to execute after when connecting to MySQL server
MYSQLI_READ_DEFAULT_FILE Read options from named option file instead ofmy.cnf
MYSQLI_READ_DEFAULT_GROUP Read options from the named group from my.cnfor the file specified with MYSQL_READ_DEFAULT_FILE.
MYSQLI_SERVER_PUBLIC_KEY RSA public key file used with the SHA-256 based authentication.
MYSQLI_OPT_NET_CMD_BUFFER_SIZE The size of the internal command/network buffer. Only valid for mysqlnd.
MYSQLI_OPT_NET_READ_BUFFER_SIZE Maximum read chunk size in bytes when reading the body of a MySQL command packet. Only valid for mysqlnd.
MYSQLI_OPT_INT_AND_FLOAT_NATIVE Convert integer and float columns back to PHP numbers. Only valid for mysqlnd.
MYSQLI_OPT_SSL_VERIFY_SERVER_CERT
value The value for the option. Required for procedural style only and Optional for Object oriented style

Usage: Procedural style

mysqli_options(connection,option,value);

Parameter:

Name Description
connection Specifies the MySQL connection to use
option Specifies the option to set. Can be one of the following values:
  • MYSQLI_OPT_CONNECT_TIMEOUT - connection timout in seconds
  • MYSQLI_OPT_LOCAL_INFILE - enable/disable use of LOAD LOCAL INFILE
  • MYSQLI_INIT_COMMAND - command to execute after connecting to MySQL server
  • MYSQLI_READ_DEFAULT_FILE - read options from named file instead of my.cnf
  • MYSQLI_READ_DEFAULT_GROUP - read options from named group from my.cnf or the file specified in MYSQLI_READ_DEFAULT_FILE
  • MYSQLI_SERVER_PUBLIC_KEY - RSA public key file used with SHA-256 based authentication
value Specifies the value for the option

Return value:

Returns TRUE on success or FALSE on failure.

Version: PHP 5, PHP 7

Example:

<?php
$con=mysqli_init();
if (!$con){
  die("mysqli_init failed");
}

mysqli_options($con,MYSQLI_READ_DEFAULT_FILE,"w3r.cnf");

if (!mysqli_real_connect($con,"localhost","user1","datasoft123","hr")){
  die("Connect Error: " . mysqli_connect_error());
}

mysqli_close($con);
?>

See also

PHP Function Reference

Previous: next_result
Next: ping



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/php/function-reference/mysqli_options.php