php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #58305 Support 'host' from specified .cnf file
Submitted: 2008-08-08 14:03 UTC Modified: 2011-05-26 08:22 UTC
From: timtowdi at yahoo dot com Assigned:
Status: Wont fix Package: PDO_MYSQL (PECL)
PHP Version: 5.2.5 OS: All
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2008-08-08 14:03 UTC] timtowdi at yahoo dot com
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'.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-05-26 08:22 UTC] johannes at schlueters dot de
This will not be supported. You may use pdo.dsn.* in php.ini though. http://php.net/manual/en/pdo.construct.php
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Oct 16 13:03:34 2021 UTC