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.

PHP: Tips of the Day

To use the constant simply use its name:

Example:

if (EARTH_IS_FLAT) {
 print "Earth is flat";
}
print APP_ENV_UPPERCASE; 

Output:


or if you don't know the name of the constant in advance, use the constant function:

// this code is equivalent to the above code
$const1 = "EARTH_IS_FLAT";
$const2 = "APP_ENV_UPPERCASE";
if (constant($const1)) {
 print "Earth is flat";
}
print constant($const2);

Output:


 





We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook