English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The mysqli_init() function initializes MySQLi and returns a resource type value, which can be used as an argument for the mysqli_real_connect() function
mysqli_init()Function is used to initialize the mysqli object. The result of this function can be passed as one of the parameters tomysqli_real_connect()Function.
mysqli_init($con);
Number | Parameters and Description |
---|---|
1 | con(Required) This is an object representing the connection with the MySQL Server. |
This function returns a mysqli object.
This function was first introduced in PHP version5introduced and can be used in all higher versions.
The following examples demonstratemysqli_init()Usage of the Function (Procedural Style)-
<?php $db = mysqli_init(); print_r($db); ?>
Output Result
mysqli Object ( [client_info] => mysqlnd 7.4.5 [client_version] => 70405 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => )
Here is another example of this function $ minus;
<?php $db = mysqli_init(); //Establish Connection $con = mysqli_real_connect($db, "localhost","root","password","test"); if($con){ print("Connection established successfully"); } print("Connection failed "); } ?>
Output Result
Connection established successfully
Example of using the mysqli_init() function:
<?php $connection_mysql = mysqli_init(); if (!$connection_mysql){ die("mysqli_init failed"); } if (!mysqli_real_connect($connection_mysql,"localhost","root","password","mydb")){ die("Connection error: ". mysqli_connect_error()); } mysqli_close($connection_mysql); print("Connection established successfully....."); ?>
Output Result
Connection established successfully.....