I'm trying to create a Mysqli to get data from database using OOP. And I can't get any data from the database, and when I check the connection, it returns null
Here's my DatabaseHelper class.
class DatabaseHelper
{
private $servername;
private $username;
private $password;
private $dbname;
public function connect()
{
$this->servername = "localhost";
$this->username = "root";
$this->password = "";
$this->name = "test";
$conn = new mysqli($this->servername, $this->username, $this->password, $this->dbname);
echo '<pre>';
var_export($conn);
echo '</pre>';
}
}
And here's the connection data.
mysqli::__set_state(array(
'affected_rows' => NULL,
'client_info' => NULL,
'client_version' => NULL,
'connect_errno' => NULL,
'connect_error' => NULL,
'errno' => NULL,
'error' => NULL,
'error_list' => NULL,
'field_count' => NULL,
'host_info' => NULL,
'info' => NULL,
'insert_id' => NULL,
'server_info' => NULL,
'server_version' => NULL,
'sqlstate' => NULL,
'protocol_version' => NULL,
'thread_id' => NULL,
'warning_count' => NULL,
))
Is there anything wrong in my code above that makes the connection returns null?