mysqli::real_connect
(mysqli_real_connect) Open the connection to the mysql server
The real_connect()
/ mysqli_real_connect()
function opens a new MySQL server connection.
The difference between this function and connect()
is that:
real_connect()
requires a valid object created by init()
real_connect()
can be used with options()
to set different options for connectionsreal_connect()
has a flag parameterOpen a new MySQL server connection and 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" ) ; ?>
Open a new MySQL server connection and 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" ) ; ?>