【问题标题】:Selecting schema configuration in Postgres with doctrine 2使用教义 2 在 Postgres 中选择模式配置
【发布时间】:2013-05-30 19:46:24
【问题描述】:

我有一个复杂的问题,希望你能帮助我。

我在我的应用程序中使用 Doctrine DBAL,因为我想让它在 Postgres 和 Mysql 中工作。

问题是我想切换我拥有的 5 个模式。

例如我会做这件事:

  1. 操作 1 --> 选择架构 1

  2. 操作 2 --> 发出这样的 SQL 请求:“SELECT * FROM users”

  3. 动作 3 --> 选择模式 2

  4. 操作 4 --> 发出另一个 SQL 请求,例如“SELECT * FROM users”

我不想做的事:

  1. 操作 1 --> 发出这样的 SQL 请求:“SELECT * FROM schema1.users”

  2. 操作 2 --> 像这样发出另一个 SQL 请求 "SELECT * FROM schema2.users"

我尝试过的(但不起作用=S):

    $connection->getConnection()->exec("SET SEARCH_PATH schema1");
    $stmt = $connection->getConnection()->executeQuery("SELECT * FROM users");

有人知道如何解决我的问题吗? 如果您能给我一些帮助,我将不胜感激。

谢谢。

冰箱

【问题讨论】:

    标签: mysql postgresql doctrine-orm zend-framework2 dbal


    【解决方案1】:

    我找到了问题所在。

    我的代码出错了>_

    这是有效的代码:

    $connection->getConnection()->exec("SET SEARCH_PATH TO schema1");
    $stmt = $connection->getConnection()->executeQuery("SELECT * FROM users");
    

    谢谢

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多