|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2007-05-18 14:50 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 21:00:01 2025 UTC |
The example should have read: $ppv = PDO('mysql',null,null,array(PDO::MYSQL_ATTR_READ_DEFAULT_GROU P=> 'php');