Symfony2 CLI does not connect to MySQL while browser works fine.
So i had an issue that i am still somewhat unsure of the cause, though i suspect the culprit was an upgrade to a newer version of MAMP.
So when using the Symfony2 project in the browser, everything works fine, however on the CLI i get the following:
SQLSTATE[HY000]  No such file or directory
Warning: PDO::__construct():  No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in …htdocs/Symfony/vendor/doctrine-dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php line 36
So i thought it was pretty odd that the CLI would not connect when the browser did just fine. I tried adding this to my parameters.ini:
Though this seems to have made no difference what so ever. It seems SF2 CLI would ignore the sock file location and was only interested in the sock file located in the /private/var/mysql directory. So the solution is to make a symlink to the sock file thus resolving the issue. Do the following to resolve it:
$ sudo mkdir /private/var/mysql/
$ sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /private/var/mysql/mysql.sock
This should resolve the issue.