|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-02-21 11:11 UTC] hholzgra@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 23 09:00:02 2025 UTC |
Description: ------------ Hello, When I am trying to create PDO object with the following dsn, i am getting the following error. $dsn='mysql:dbname=test;host=localhost'; Connection failed SQLSTATE[HY000] [2005] Unknown MySQL server host '.' (4) However, if i change the dsn string to something like $dsn='mysql:dbname=test;host=127.0.0.1'; there seem to be no problem. AS you can see, in the second case, i am passing the host IP address instead of string 'localhost'; my /etc/hosts file looks like below. <root@localhost /opt/IBMIHS/htdocs/en_US> cat /etc/hosts # Do not remove the following line, or various programs # that require network functionality will fail. 127.0.0.1 localhost.localdomain localhost 127.0.0.1 localhost I am using IHS with PHP 5.0.3 on IA32 box running with RHEL3, I am not sure whether this is a bug, or is there any thing silly which I am missing. Thank you, Srini. Reproduce code: --------------- <?php //$dsn='mysql:dbname=test;host=127.0.0.1'; $dsn='mysql:dbname=test;host=localhost'; $user='root'; $password='qpoiqpoi'; try { $dbh = new PDO($dsn, $user, $password); print "PDO Object has been created </br>"; } catch (PDOException $e) { print "Connection failed </br>" . $e->getMessage(); } ?> Expected result: ---------------- PDO Object has been created Actual result: -------------- Connection failed SQLSTATE[HY000] [2005] Unknown MySQL server host '.' (4)