Notice: Array to string conversion in C:\xampp\xampp\htdocs\classes\DB.php on line 21
Warning: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: No such host is known. in C:\xampp\xampp\htdocs\classes\DB.php on line 21
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.
It gives me this error when its on XAMPP, but when i put it on a live server it works fine, I know the DB credentials are correct, I am using the current version of XAMPP (as of yesterday) for windows and using Apache 2 on the live server, both with MySql.
Line 18-25:
// Takes values from 'config.php' and uses them to connect
private function __construct() {
try {
$this->_pdo = new PDO('mysql:host=' . Config::get('msql/host') . ';dbname=' . Config::get('mysql/db'), Config::get('mysql/username'), Config::get('mysql/password'));
} catch(PDOException $e) {
die($e->getMessage());
}
}
And this is where the array is set:
// Sets the config valuses
$GLOBALS['config'] = array(
'mysql' => array(
'host' => '127.0.0.1',
'username' => 'root',
'password' => 'password',
'db' => 'site'
),
'remember' => array(
'cookie_name' => 'hash',
'cookie_expiry' => 604800
),
'session' => array(
'session_name' => 'user'
)
);
And the config class:
class Config {
public static function get($path = null) {
if($path) {
$config = $GLOBALS['config'];
$path = explode('/', $path);
foreach($path as $bit) {
if(isset($config[$bit])) {
$config = $config[$bit];
}
}
return $config;
}
return false;
}
}
Typos:
$this->_pdo = new PDO('mysql:host=' . Config::get('msql/host') . ';dbname=' .
^^^^^---no Y
$GLOBALS['config'] = array(
'mysql' => array(
^---has a Y
$this->_pdo = new PDO("mysql:host=".config::get('mysql/host').";dbname=".config::get('mysql/database') ,config::get('mysql/user'),config::get('mysql/password'));
Please check! Is there any space between "mysql:host=".config::get('mysql/host')."
? I was getting the same error because of space!