|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-05-15 15:57 UTC] cweldon at tamu dot edu
[2008-09-12 10:46 UTC] johannes at schlueters dot de
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 17:00:01 2025 UTC |
Description: ------------ When connecting to MySQL via the standard PDO DSN (shown in the reproduce code section), I get a connection error (shown in the actual result). My php.ini file has the mysql.default_socket set to '/var/mysql/mysql.sock' and I additionally have in my .htaccess file: php_value mysql.default_socket '/var/mysql/mysql.sock' The phpinfo() script reports: mysql MySQL Support => enabled Active Persistent Links => 0 Active Links => 0 Client API version => 5.0.24a MYSQL_MODULE_TYPE => external MYSQL_SOCKET => /tmp/mysql.sock MYSQL_INCLUDE => -I/usr/local/php5/include/mysql MYSQL_LIBS => -L/usr/local/php5/lib/mysql -lmysqlclient Directive => Local Value => Master Value mysql.allow_persistent => On => On mysql.connect_timeout => 60 => 60 mysql.default_host => no value => no value mysql.default_password => no value => no value mysql.default_port => no value => no value mysql.default_socket => /var/mysql/mysql.sock => /var/mysql/mysql.sock mysql.default_user => no value => no value mysql.max_links => Unlimited => Unlimited mysql.max_persistent => Unlimited => Unlimited mysql.trace_mode => Off => Off Regular MySQL access through PHP works (ie: mysql_connect(), mysql_query(), etc.), but PDO does not seem to be obeying it, and I shouldn't have to force set the dbh to look like: mysql:socket=/var/mysql/mysql.sock;dbname=database since this application may float between servers where the socket is not always located here. Reproduce code: --------------- define('DBMS', 'mysql'); define('DBMS_HOSTNAME', 'localhost'); define('DBMS_USERNAME', 'username'); define('DBMS_PASSWORD', 'password'); define('DBMS_DATABASE', 'database'); $dbh = new PDO(DBMS.':host='.DBMS_HOSTNAME.';dbname='.DBMS_DATABASE, DBMS_USERNAME, DBMS_PASSWORD, array(PDO::ATTR_PERSISTENT => true)); Expected result: ---------------- The database connection should succeed and execute the code appropriately. Actual result: -------------- Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)' in /Library/WebServer/Documents/devel/Classes/dbNew.class.php:26 Stack trace: #0 /Library/WebServer/Documents/devel/Classes/dbNew.class.php(26): PDO->__construct('mysql:host=loca...', 'username', 'password', Array) #1 /Library/WebServer/Documents/devel/Classes/Customer.class.php(4): require_once('/Library/WebSer...') #2 /Library/WebServer/Documents/devel/Admin/transactionView.php(22): require_once('/Library/WebSer...') #3 {main} thrown in /Library/WebServer/Documents/devel/Classes/dbNew.class.php on line 26