I have a standard composer project for Zf2.2 with Doctrine 2.implementing the steps laid out at http://framework.zend.com/manual/2.2/en/user-guide/overview.html and installing Doctrine 2 via composer.
{
"name": "zendframework/skeleton-application",
"description": "Skeleton Application for ZF2",
"license": "BSD-3-Clause",
"keywords": [
"framework",
"zf2"
],
"homepage": "http://framework.zend.com/",
"require": {
"php": ">=5.3.3",
"zendframework/zendframework": "2.2.*",
"zendframework/zend-developer-tools": "0.0.2",
"doctrine/doctrine-orm-module": "0.7.0"
}
}
As at now the project has only 1 Doctrine connection 'orm_default':
return array (
'doctrine' => array (
'connection' => array (
'orm_default' => array (
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array (
'host' => 'localhost',
'port' => '3306',
'user' => 'sameuser',
'password' => 'samepassword',
'dbname' => 'dbname1',
'charset' => 'utf8'
)
)
),
'driver' => array (
'modulename_entities' => array (
'class' => 'Doctrine\ORM\Mapping\Driver\AnnotationDriver',
'cache' => 'array',
'paths' => array (
__DIR__ . '/../src/Modulename/Entity'
)
),
'orm_default' => array (
'drivers' => array (
'Modulename\Entity' => 'modulename_entities'
)
)
)
)
);
My typical application format separates different business functions into different databases. So, a lot of the application information goes into a "main" database, marketing info into a "mktg" db, and back-end stuff, like errors goes into another.
An extensive Google search brought about the option of adding the dbname to the Entity Annotations like so:
/**
* @ORM\Entity
* @ORM\Table
* (
* name="dbname2.error_tickets",
* indexes=
* {
*
...
* }
* )
*
*/
class Error....
However, when I run
doctrine-module orm:schema-tool:create
and get:
ATTENTION: This operation should not be executed in a production environment.
Creating database schema...
Database schema created successfully!
Table error_tickets is not created in ANY database. No errors are displayed. Yet, when I annotate like so:
/**
* @ORM\Entity
* @ORM\Table
* (
* name="error_tickets",
* indexes=
* {
*
...
* }
* )
*
*/
class Error....
or so:
/**
* @ORM\Entity
* @ORM\Table
* (
* name="dbname1.error_tickets",
* indexes=
* {
*
...
* }
* )
*
*/
class Error....
and run
doctrine-module orm:schema-tool:create
Table error_tickets is created in my default dbname1.
I have read that adding the dbname to the Table annotation is a way to "trick" doctrine into creating said table on another database without going into lengthy, unsupported design hacks that aren't really production ready. I have ensured the following:
- The sameuser has 'ALL PRIVILEGES' to both databases
- Both databases are on the same server
- No other design hack was implemented (I've tried them). This is a clean, working zf2 + D2 install
- setting the 'dbname' key in my doctrine.local.php to any of null, FALSE, '' or not setting it at all, stops any table from being created in any database.
Question: What else is needed for this "trick" to work?
The simplest/most stable solution will be best