Survivor guide for Symfony2 + PDO

Wed, 05/30/2012 - 11:20 | 205 Views

Hello folks.

A few days ago I started with a self-training for Symfony 2 just to start getting ready for when it gets implemented in Drupal 8.

In the process I had to deal with some weird issues explained below.

1. DB Connection

Symfony 2 uses PDO to connect with your DB ( MYSQL, SQL Server, ORACLE, Postgres, SQLite, etc), for instance if you want to use MySQL, you have to install the PHP modules for that service i.e: pdo_mysql or pdo_pgsql.

Also you have to edit the php.ini to set the proper values:

mysql.default_socket => /Applications/MAMP/tmp/mysql/mysql.sock
pdo_mysql.default_socket => /Applications/MAMP/tmp/mysql/mysql.sock

These values work if you are using MAMP for MAC OS X.

Also remember the PHP used by APACHE, use a diferent php.ini than PHP Cli, for example in my configuration:

mysql.default_socket => /Applications/MAMP/tmp/mysql/mysql.sock
pdo_mysql.default_socket => /Applications/MAMP/tmp/mysql/mysql.sock

If you don't set the proper values for this variable, you will get erratic error using the command: php app/console from symfony.

2. Time Zone

Symfony 2 requires a defined Time Zone, again you have to set the values in both php.ini.

One possible configuration:

date.timezone = "America/Costa_Rica"

After that you can use Symfony 2 + Doctrine without any problem.

Enjoy IT