Support for multiple databases in symfony

I am using Propel as my DAL for my Symfony project. I cannot get an application to work in two or more databases.

Here is my schema.yml:

db1:
  lkp_User:
    pk_User:                     { type: integer, required: true, primaryKey: true, autoIncrement: true }
    UserName:                    { type: varchar(45), required: true }
    Password:                    longvarchar
    _uniques:
      Unique:                    [ UserName ]

db2:
  tesco:
    Id:                  { type: integer, required: true, primaryKey: true, autoIncrement: true }
    Name:                { type: varchar(45), required: true }
    Description:         longvarchar

And here is the .yml database:

dev:
  db1:
    param:
      classname: DebugPDO
test:
  db1:
    param:
      classname: DebugPDO
all:
  db1:
    class: sfPropelDatabase
    param:
      classname: PropelPDO
      dsn: 'mysql:dbname=bpodb;host=localhost'   #where the db is located
      username: root
      password: #pass
      encoding: utf8
      persistent: true
      pooling: true


  db2:
    class: sfPropelDatabase
    param:
      classname: PropelPDO
      dsn: 'mysql:dbname=mystore2;host=localhost'   #where the db is located
      username: root
      password: #pass
      encoding: utf8
      persistent: true
      pooling: true

When I call php symfony propel-build-model, generated only db1, db2- no.

Any idea how to solve this problem?

+3
source share
3 answers

This problem is working for me ! Most importantly, you should name your schema according to% dbname% .schema.yml. This way, Symfony can assign ymls to the correct database.

+6
source

Also, when starting a task, you must specify a connection, for example:

symfony propel:build-all-load --connection=my_connection

It worked for me, hope it helps.

+1

Propel::getConnection('db2') .

Just keep in mind that you call "db1", "db2" connection names. You can have multiple connections to the same database with different inputs / permissions (e.g. read-only, etc.).

This is very good for testing purposes: you can do this with the same connection name to a different database. Unable to destroy your production database :)

+1
source

Source: https://habr.com/ru/post/1706164/


All Articles