Edit your my.cnf file (mysql configuration file. Search within MAMP)
Find ‘skip-networking’. If non commented, comment it out. This will allow network access to mysql. Currently your mysql setup might only be allowing local access.
I had similar issues on MAMP. (1) You must use ‘localhost’, not ‘127.0.0.1’ – don’t know why; (2) make sure that your firewall (if enabled) isn’t blocking port 3306; and (3) I had to explicitly state the MySQL port (3306), see my code below:
This did the trick for me. I didn’t know there are two php.ini config files under Ubuntu. I have previously configured the standard /etc/php5/apache2/php.ini. This is the one used by Apache to serve PHP script.
However, phpunit is happened to use /etc/php5/cli/php.ini, i.e. the php.ini for client applications. Well, it does make sense. However, I didn’t know this. So, I just copied configs that I added to the standard php.ini related to my pdo_cubrid and xdebug.so, and I scored a goal! Hope this helps to others, too!
I had the same problem in Fedora 15. I am using LAMPP and was struggling with the problem for more than a day. Your solution fixed my problem. For the benefit of everyone, here is my fix:
Remove the default PHP executable: rm /usr/bin/php
Add a symbolic link to LAMPP PHP installation and make that your default LINUX PHP installation: ln -s /opt/lampp/bin/php-5.3.5 /usr/bin/php
Modify the /opt/lampp/etc/php.ini file: uncomment the include_path
I don’t have any problem in my Snow Leopard at home, everything works perfectly fine, but at work I use an ubuntu vm machine and I have the same problem: I’m able to connect through the yii application, but phpunit gives me the “CDbConnection failed to open db connection” error.
I have done every single suggestion, but none of them worked. Does anyone have another idea?