Current Location: Home> Function Categories> mysqli::options

mysqli::options

(mysqli_options) Setting options
Name:mysqli::options
Category:MySQLi
Programming Language:php
One-line Description:Set additional connection options and affect the behavior of the connection.

Definition and usage

options() / mysqli_options() function is used to set additional connection options and affect the behavior of the connection.

Note: This function should be called after init() and before real_connect() .

Example

Example 1 - Object-Oriented Style

Set additional connection options:

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

// Specify the connection timeout
$con -> options ( MYSQLI_OPT_CONNECT_TIMEOUT , 10 ) ;

// Specify the option to read from named files instead of my.cnf
$con -> options ( MYSQLI_READ_DEFAULT_FILE , "myfile.cnf" ) ;

$con -> real_connect ( "localhost" , "my_user" , "my_password" , "my_db" ) ;
?>

Example 2 - Procedural Style

Set additional connection options:

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

// Specify the connection timeout
mysqli_options ( $con , MYSQLI_OPT_CONNECT_TIMEOUT , 10 ) ;

// Specify the option to read from named files instead of my.cnf
mysqli_options ( $con , MYSQLI_READ_DEFAULT_FILE , "myfile.cnf" ) ;

mysqli_real_connect ( $con , "localhost" , "my_user" , "my_password" , "my_db" ) ;
?>
Similar Functions