I am having some trouble. So I am trying to connect to my database using MySQLi, but I am getting this error:
Warning: mysqli::mysqli(): (28000/1045): Acces
Usually this means that one of your host
, database
, user
or password
is wrong.
In my case it was the host
, I usually use localhost but this time I saw in my cPanel
> MySQL® Databases
that I should not use localhost and istead I should use mysql5.xxxxxxx.net.
This was the message that helped me:
The mysql server’s address is mysql5.xxxxxxxx.net. When connecting to the mysql server you must specify this host.
The reason of the error is here:
class Routing {
public function __construct($route) {
$this->users = new Users();//<-?
$this->route = $route;
}
You are not passing a parameter to Users.__construct($db)
Define an array with credentials and pass is like this:
class Routing {
public function __construct($route) {
$db = array();
$db['host'] = 'localhost';
$db['user'] = 'venge_main';
$db['pass'] = 'fakepassword';
$db['name'] = 'venge_panel';
$this->users = new Users($db);
$this->route = $route;
}
Or use a global $db variable instead of defining it locally, like I did. But you must pass it to constructor when creating Users object.
$users = new Users($database);
I think, it must be:
$users = new Users($db);
If $db is defined in that file.