I am connecting to the amazon aws server. in one class my DBConnect class is working while in other, the same class is giving
Warning: mysqli::__construct(): (HY000/2002):No such file or directory
The class code is below;
<?php
class DBConnect {
private $hostname;
private $username;
private $password;
private $dbname;
public function __construct ($conn_cred) {
$this->hostname = $conn_cred['hostname'];
$this->username = $conn_cred['username'];
$this->password = $conn_cred['password'];
$this->dbname = $conn_cred['dbname'];
}
public static function connect($dbname) {
// Include connection credentials
$conn_cred = require_once 'constants/'.$dbname.'.credentials.php';
// Set object
$conn_obj = new self($conn_cred);
// Establish Connection
return $conn_obj->establish_connection();
}
private function establish_connection () {
// Create connection
$conn = new mysqli($this->hostname, $this->username, $this->password, $this->dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
// echo "Connected";
return $conn;
}
}
}
The class invoking line is
$dbObj = DBConnect::connect('cloudDBone');
cloudDBone.credentials.php
<?php
return array(
"driver" => "mysql",
"hostname" => "prodcloud.cshtaf5aoiog.ap-south-1.rds.amazonaws.com",
"username" => "<-- myusername -->",
"password" => "<-- mypwd -->",
"dbname" => "<-- mydbname -->"
);
I am stuck in this. Any kind of help would be highly appreciated. Thanks