So completely new to OOP, so apologies in advance. I am trying to connect to my database. Keep getting the following error message:
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
If anyone could help, this would be a massive help.
$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()); }
Where (according to the comments)....
<?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; } }
https://stackoverflow.com/questions/65781333/unable-to-connect-to-mysql-database-using-mamp January 19, 2021 at 03:59AM
没有评论:
发表评论