Error connecting PDO to database

I try to run my project on my local machine, but this leads to the following error:

ERRNO: 2
TEXT: PDO::__construct() [pdo.--construct]: php_network_getaddresses: getaddrinfo failed: The requested name is valid, but no data of the requested type was found. LOCATION: C:\xampp\htdocs\rsecrets\business\database_handler.php, line 25, at December 4, 2012, 12:46 pm PDO::__construct() [pdo.--construct]: php_network_getaddresses: getaddrinfo failed: The requested name is valid, but no data of the requested type was found. LOCATION: C:\xampp\htdocs\rsecrets\business\database_handler.php, line 25, at December 4, 2012, 12:46 pm

How I defined the connection:

 define('DB_PERSISTENCY', 'true'); define('DB_SERVER', 'localhost'); define('DB_USERNAME', 'root'); define('DB_PASSWORD', ''); define('DB_DATABASE', 'xxyy'); define('PDO_DSN', 'mysql:host=' . DB_SERVER . ';dbname=' . DB_DATABASE); 

Here is what is on line 25 in the database_handler.php file:

  self::$_mHandler = new PDO(PDO_DSN, DB_USERNAME, DB_PASSWORD, array(PDO::ATTR_PERSISTENT => DB_PERSISTENCY)); 

What am I not getting?

+4
source share
1 answer

You probably do not have a valid IPv4 entry for localhost in your hosts file.

Run notepad.exe as administrator and edit %SystemRoot%\system32\drivers\etc\hosts

Make sure the following line is displayed (without leading # )

 127.0.0.1 localhost 
+2
source

All Articles