Symfony 中的多个数据库支持 [英] Multiple databases support in Symfony

查看:27
本文介绍了Symfony 中的多个数据库支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Propel 作为我的 Symfony 项目的 DAL.我似乎无法让我的应用程序跨两个或多个数据库工作.

I am using Propel as my DAL for my Symfony project. I can't seem to get my application to work across two or more databases.

这是我的 schema.yml:

Here's 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

这是databases.yml:

And here's the databases.yml:

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

当我调用 php symfony propel-build-model 时,只生成 db1db2 没有.

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

知道如何解决这个问题吗?

Any idea how to fix this problem?

推荐答案

我解决了这个问题!最重要的是您必须根据 %dbname%.schema.yml 命名您的架构.通过这种方式,Symfony 将能够将 ymls 分配给正确的数据库.

I got this issue working! The most important thing is you must name your schema according to %dbname%.schema.yml. In this way Symfony will be able to assign the ymls to the correct database.

这篇关于Symfony 中的多个数据库支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆