PHP mysqli_real_connect() Function

Definition

The mysqli_real_connect() function opens a new connection to the MySQL server.

Syntax

PHP mysqli_real_connect() Function has the following syntax.

mysqli_real_connect(connection,host,username,password,dbname,port,socket,flag);

Parameter

ParameterIs RequiredDescription
connectionRequired.MySQL connection to use
hostOptional.Host name or an IP address
usernameOptional.Username
passwordOptional.Password
dbnameOptional.Default database to be used
portOptional.Port number to the MySQL server
socketOptional.Socket or named pipe to be used
flagOptional.Connection options.

Possible values for flag option:

ValueMeaning
MYSQLI_CLIENT_COMPRESSUse compression protocol
MYSQLI_CLIENT_FOUND_ROWSReturn number of matched rows
MYSQLI_CLIENT_IGNORE_SPACEAllow spaces after function names. Make function names reserved words
MYSQLI_CLIENT_INTERACTIVEAllow interactive_timeout seconds of inactivity before closing connection
MYSQLI_CLIENT_SSLUse SSL encryption

Return

It returns TRUE on success and FALSE on failure.

Example

mysqli_real_connect() requires a valid object created by mysqli_init(). It can be used with mysqli_options() to set different options for the connection.


<?php/*from   w ww  .  j a v  a 2 s  . c om*/
$con=mysqli_init();
if (!$con){
  die("mysqli_init failed");
}

if (!mysqli_real_connect($con,"localhost","my_user","my_password","my_db")){
  die("Connect Error: " . mysqli_connect_error());
}

mysqli_close($con);
?>




















Home »
  PHP Tutorial »
    Function reference »




PHP Array Functions
PHP Calendar Functions
PHP Class Functions
PHP Data Type Functions
PHP Date Functions
PHP File Functions
PHP Image Functions
PHP Math Functions
PHP MySQLi Functions
PHP SimpleXML Functions
PHP String Functions
PHP XML Functions
PHP Zip Functions