Page 1 of 1

Problem with PDO_MYSQL

PostPosted: 31. August 2009 22:02
by RomanM
I have installed "XAMPP for linux 1.7.2" on fedora11 (2.6.29.6-217.2.16.fc11.i686.PAE) and tryed to use PDO_MYSQL:

Code: Select all
try {
   $dbh = new PDO('mysql:host=localhost;dbname=db', 'root', '');
   foreach ($dbh->query('SELECT * from good') as $row) {
      print_r($row);
   }
   $dbh = null;
} catch (PDOException $e) {
   print "Error!: " . $e->getMessage() . "<br/>";
   die();
}


and got error:

Code: Select all
Warning: PDO::__construct() [pdo.--construct]: [2002] (trying to connect via unix://) in /opt/lampp/htdocs/public/index.php on line 30
Error!: SQLSTATE[HY000] [2002]


How can i fix it?

Thanks.

Re: Problem with PDO_MYSQL

PostPosted: 12. December 2009 05:36
by ned
I saw the same problem and found a fix on the web so I'm sharing. The observed behavior for me on Ubuntu Karmic Koala is that MySQL and MySQLi calls will work fine but PDO fails with the error listed in the previous posting.

Open up your php.ini file in the /opt/lampp/etc directory. You may need root privileges to edit the file on your distro.

Look for the line titled pdo_mysql.default_socket. Add /opt/lampp/var/mysql/mysql.sock after the equal sign and save the file. Once I did this I was able to get PDO working properly.