w3resource

PHP mysqli: init() function

mysqli_init() function / mysqli::init

The mysqli_init() function / mysqli::init -- mysqli_init initializes MySQLi and returns an object to use with the mysqli_real_connect() function.

Syntax:

Object oriented style

mysqli mysqli::init ( void )

Procedural style

mysqli mysqli_init ( void )

Usage: Procedural style

mmysqli_init();

Return value:

Returns an object.

Version: PHP 5, PHP 7

Example:

<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

// Perform queries
$sql1="CREATE TABLE orders LIKE employees";
mysqli_query($con,$sql1);
$sql2="INSERT INTO orders SELECT * FROM oldorders ORDER BY Last_Name LIMIT 10";
mysqli_query($con,$sql2);

// Print info about most recently executed query
echo mysqli_info($con); 

mysqli_close($con);
?>

See also

PHP Function Reference

Previous: info
Next: insert_id



Follow us on Facebook and Twitter for latest update.