|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2011-05-26 08:22 UTC] johannes at schlueters dot de
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 11:00:01 2025 UTC |
Description: ------------ When loading connection information from a .cnf file, specified with PDO::MYSQL_ATTR_READ_DEFAULT_FILE, the hostname(s) defined in said file are apparently ignored and localhost is used instead. Other information such as database, username, and password are indeed read and used...Just not the hostname. Reproduce code: --------------- <?php /* This would be the contents of the "apps.cnf" file: [client] host=dbserve1 [app1] database=app1 user=app1_user password=shhhhh [app2] host=dbserve2 database=app2 user=app2_user password=supersecret */ // try to connect using settings in .cnf file $dbh = new PDO('mysql:', NULL, NULL, array( PDO::ATTR_TIMEOUT => 3, PDO::MYSQL_ATTR_READ_DEFAULT_FILE => '/var/mysql/apps.cnf', PDO::MYSQL_ATTR_READ_DEFAULT_GROUP => 'app1', )); // tell us what happened print_r($dbh->errorInfo()); ?> Expected result: ---------------- In lieu of any host/db/user information specified in the DSN, said info would be pulled from the .cnf file and the script would attempt to connect to the database 'app1' as 'app1_user' on host 'dbserve1'. Actual result: -------------- The script attempts to connect to the database 'app1' as 'app1_user' on host 'localhost'.