对 OOP 来说是全新的,所以提前道歉。我正在尝试连接到我的数据库。不断收到以下错误消息:
<块引用>SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename or servname provided, or not known
如果有人可以提供帮助,这将是一个巨大的帮助。
$GLOBALS ['config'] = array(
'mysql' => array(
'host' => ' 127.0.0.1',
'username' => 'root',
'password' => 'root',
'db' => 'honeybee'
),
'remember' => array(
'cookie_name' => 'hash',
'cookie_expiry' => 604800
),
'session' => array(
'session_name' => 'user'
)
);
try {
$this->_pdo = new PDO('mysql:host=' . Config::get('mysql/host') . ';dbname=' . Config::get('mysql/db'), Config::get('mysql/username'), Config::get('mysql/password'));
} catch(PDOException $e) {
die($e->getMessage());
}
哪里(根据评论)......
<?php
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;
}
}