"what is the difference between mysqli::real_connect and new mysqli object in connecting database?" Code Answer

1

its just another way of connecting to your database. if you use mysqli_init() it will initialize the mysqli object first. then using the object you will call real_connect() to connect to the database. but when you use new mysqli() you are initializing the mysqli object by passing in the connection values as parameters, so it does initialization and connection at the same time.

note: calling the constructor with no parameters is the same as calling mysqli_init().

in your first case you are getting the connection object as the return value because you are calling mysqli() constructor with parameters. so you can run queries on it. but in your second case you need to store the connection like this,

$con = $this->_con->real_connect($this->_db['server'],$this->_db['user'],$this->_db['pass'],$this->_db['db']);

then run queries on $con

By Langley on March 2 2022

Answers related to “what is the difference between mysqli::real_connect and new mysqli object in connecting database?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.