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: 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:
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- JavaScript String Exercises
- JavaScript HTML Form Validation
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- JavaScript functions Exercises
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises
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