php - SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed -


the full error is:

sqlstate[hy000] [2002] php_network_getaddresses: getaddrinfo failed: name or service not known 

this first time try connect website host. i'm not big php developer , code see here different have seen. can connect phpmyadmin can't through website

class config   {     const db_type = 'mysql';     const db_host = ' localhost';     const db_user = 'xxxx';     const db_password = 'xxxx';     const db_name = 'xxxx'; }      class databasepdo {      /** @var pdo */     private static $dbh;     public static function getinstance()     {          $dsn = config::db_type.':host='.config::db_host.';dbname='.config::db_name;          try {             self::$dbh = new pdo($dsn, config::db_user, config::db_password);         }         catch( pdoexception $e ){             echo "error!: ".$e->getmessage();             die();         }          return self::$dbh;     } }   require_once www_root. 'php' .ds. 'classes' .ds. 'config.php'; require_once www_root. 'php' .ds. 'classes' .ds. 'databasepdo.php';  class userdao {      public $dbh;      public function __construct()     {         $this->dbh = databasepdo::getinstance();     } 

you have white space in localhost. change config to:

class config   {     const db_type = 'mysql';     const db_host = 'localhost';  // <- fixed     const db_user = 'xxxx';     const db_password = 'xxxx';     const db_name = 'xxxx'; }   

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -