[Solution] How to print connection object in PHP with Example : Complete clarification, explained in a simple way and step by step include simple example.

With the help below example you come to know that how and way to create object for printing the connection.

Please follow the code given below where first function named connectnDB created and then inside that used mysqli by passing parameter.

The parameter are “$host,$user,$password,$database”.

Complete [Solution] How to print connection object in PHP with Example

For MYSQLi connection object returned via below given PHP function (PHP version 5.3.10, MYSQL version 5.5.24):

$host = "hostname";$user = "username";$password = "password"$database = "databasename"function connectnDB(){ $con=new mysqli($host,$user,$password,$database); return $con;}

The function is called as defined below:

$mycon=connectnDB();

The instance of connection object created using below given method is not the same comparing to the one created directly without a function:

$mycon=new mysqli($host,$user,$password,$database);

Output :

echo $mycon->host_infodetail;