#41435 [Opn]: my.cnf database and host values are ignored in pdo_mysql
| From: | marques at displague dot com | Date: | Fri, 18 May 2007 14:52:05 +0000 |
| Subject: | #41435 [Opn]: my.cnf database and host values are ignored in pdo_mysql | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-112838@lists.php.net to get a copy of this message | ||
ID: 41435
User updated by: marques at displague dot com
Reported By: marques at displague dot com
Status: Open
Bug Type: Feature/Change Request
PHP Version: 5.2.2
New Comment:
The example should have read:
$ppv = PDO('mysql',null,null,array(PDO::MYSQL_ATTR_READ_DEFAULT_GROU
P=> 'php');
Previous Comments:
------------------------------------------------------------------------
[2007-05-18 14:50:21] marques at displague dot com
Description:
------------
When creating a pdo_mysql connection, database and hostname are
required even when they are supplied in the my.cnf file.
Reproduce code:
---------------
contents of ~/.my.cnf:
[php]
user = myusername
password = mypassword
database = mydb
host = db.mydomain.com
default-character-set = utf8
PHP code to test usage of ~/.my.cnf:
<?
$pdo = new
PDO('mysql:dbname=ppv',null,null,array(PDO::MYSQL_ATTR_READ_DEFAULT_GROUP=>
'php');
$st = $pdo->prepare("select user()");
$st->execute();
$rs = $st->fetchAll();
print_r($rs);
?>
Expected result:
----------------
myusername@db.mydomain.com
Actual result:
--------------
Fatal error: Uncaught exception 'PDOException' with message 'invalid
data source name'
In the above example, "dbname" is still required even though a
"database" was given in ~/.my.cnf.
The host given in ~/.my.cnf is also ignored, and PHP/mysql defaults to
"localhost".
Interestingly enough, default_character_set is applied.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=41435&edit=1