php - Multiple databases with prefixes -


i novice zend framework 2 , doctrine developer. not find answers problems described below.

i using multiple databases 1 website. example there users database user details , database statistics. it's possible there statistics user there relations (constrains) between both databases. previous projects used 1 configuration file , 1 class/directory entities (for 1 db).

  • how can use multiple databases in 1 project correct table relations?
  • how/where should store database configuration?
  • how/where should store entities?

in same project use multiple versions of databases (develop, testing, production) want use prefixes database name. example dev_users , tst_users. think should use prefix configuration file , use somewhere prefix databases.

  • how should prefix databases?

at last curious how other people use database entities when have multiple modules using them.

  • how can use multiple databases in 1 project correct table relations?

doctrine uses 1 entity manager per db connection. can connect multiple databases can't link entities. way put constraints on entity within doctrine or within database if in same db.

you can enforce constraint , use 2 separate entity managers wouldn't recommend

  • how/where should store database configuration?

the database connection details should stored in /config/autoload/local.php or /config/autoload/{ownname}.local.php , ownname can example choose 'doctrine'

doctrine.local.php

<?php  return array(     'doctrine' => array(         'connection' => array(             'orm_default' => array(                 'configuration' => 'orm_default',                 'driverclass' =>'doctrine\dbal\driver\pdomysql\driver',                 'eventmanager' => 'orm_default',                 'params' => array(                     'host' => 'localhost',                     'port' => '3306',                     'user' => '{username}',                     'password' => '{password}',                     'dbname' => '{db}',                 ),             ),         ),     ), ); 

the general doctrine setting entites located reading class meta data can placed in /config/autoload/global.php file or in file ending global.php in previous local or can store in modules config file

  • how/where should store entities?

the entities should stored in module in directory entity like: root/module/{modulename}/src/{modulename}/entity/

for how store them see: doctrine documentation

if use entities multiple modules better make common module , put dependency modules require entity

  • testing mode

you can change databases testing environments or use module chnaging between config files like: config module made people made zf2


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -