PHP Tutorial - PHP mysqli_init() Function






Definition

The mysqli_init() function initializes MySQLi and returns an object to use with the mysqli_real_connect() function.

Syntax

PHP mysqli_init() Function has the following syntax.

Object oriented style

mysqli mysqli::init ( void )

Procedural style

mysqli mysqli_init ( void )

Example

The following code uses of the mysqli_init() function to create an object for mysqli_real_connect() function.


<?php//w w  w .jav a2s.  co m
$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);
?>