views:

393

answers:

1

Hey there,

i start learning Zend Framework with the Book "Zend Framework in Action" in German.

Right there where it start to get interesting my PHP Unit Test throws this Error: "Zend_Db_Adapter_Exception: SQLSTATE[HY000] [2002] No such file or directory"

I cant find any hints at google. I did everything like in the book. Can anyone give me a hint where to search my fault?

Is this a usual beginner mistake?

+2  A: 

I would say that you have a problem connecting from PHP to MySQL...

Something like PHP trying to find some socket file, and not finding it, maybe ?
(I've had this problem a couple of times -- not sure the error I got was exactly this one, though)


If you are running some Linux-based system, there should be a my.cnf file somewhere, that is used to configure MySQL -- on my Ubuntu, it's in /etc/mysql/.

In this file, there might be something like this :

socket = /var/run/mysqld/mysqld.sock


PHP need to use the same file -- and, depending on your distribution, the default file might not be the same as the one that MySQL uses.

In this case, adding these lines to your php.ini file might help :

mysql.default_socket = /var/run/mysqld/mysqld.sock
mysqli.default_socket = /var/run/mysqld/mysqld.sock
pdo_mysql.default_socket = /var/run/mysqld/mysqld.sock

(You'll need to restart Apache so the modification to php.ini is taken into account)

The last one should be enough for PDO, which is used by Zend Framework -- but the two previous ones will not do any harm, and can be useful for other applications.


If this doesn't help : can you connect to your database using PDO, in another script, that's totally independant of Zend Framework ?

i.e. does something like this work (quoting) :

$dsn = 'mysql:dbname=testdb;host=127.0.0.1';
$user = 'dbuser';
$password = 'dbpass';

try {
    $dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}

If no, the problem is definitly not with ZF, and is a configuration / installation problem of PHP.

If yes... Well, it means you have a problem with ZF, and you'll need to give us more informations about your setup (like your DSN, for instance ? )

Pascal MARTIN
YEAH! Thank you so much!!! Without this hint I would have been sitting here for hours...Thank you for your fast reply.The problem: I have installed MAMP on my Mac (my ubuntu server is currently down)And for some reason my Unit-Test uses the /etc/php.ini instead of the /Applicaton/MAMP/:bla:/php.iniSo to go on in my code i simply copied the socket paths from the Mamp-ini into the etc/php.ini and it works!
Oliver
Glad to see I could help, and that you solved your problem :-) ;; thanks for the comment and the explanation of the "why" it didn't work ! Have fun ;-)
Pascal MARTIN