Conectare la baza de date - Tutorial Symfony
Postat la Wed 27 May 2015 in tutoriale, symfony 2
In marea majoritate a cazurilor un site are in spate o baza de date in care se stocheaza datele afisate in diverse pagini. Nici Symfony nu face exceptie. Pentru conectarea la diverse baze de date - Mysql, PostgreSQL, SQLite sau Microsoft SQL - se foloseste libraria Doctrine.
Configurarea bazei de date se face simplu in fisierul app/config/parameters.yml:
1 2 3 4 5 6 | parameters: database_driver: pdo_mysql database_host: localhost database_name: test_project database_user: root database_password: parola |
Apoi aceste valori se preiau in fisierul app/config/config.yml:
1 2 3 4 5 6 7 | doctrine: dbal: driver: "%database_driver%" host: "%database_host%" dbname: "%database_name%" user: "%database_user%" password: "%database_password%" |
Iar crearea bazei de date se realizeaza usor:
php app/console doctrine:database:drop --force
php app/console doctrine:database:create