4

I am trying to run my project in my local machine but its bringing 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

How I have 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 in line 25 in database_handler.php:

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

What am i not getting?

1
  • 2
    Can you connect using command line: mysql -u root -p -d xxyy -h localhost ? Commented Dec 4, 2012 at 11:57

1 Answer 1

2

You probably don't have a valid IPv4 entry for localhost in your hosts file.

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

Make sure the following line appears (with no leading #)

127.0.0.1    localhost
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.