Problem with PDO_MYSQL

Problems with the Linux version of XAMPP, questions, comments, and anything related.

Problem with PDO_MYSQL

Postby RomanM » 31. August 2009 22:02

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.
RomanM
 
Posts: 1
Joined: 31. August 2009 21:08

Re: Problem with PDO_MYSQL

Postby ned » 12. December 2009 05:36

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.
ned
 
Posts: 1
Joined: 12. December 2009 05:25


Return to XAMPP for Linux

Who is online

Users browsing this forum: No registered users and 35 guests