【问题标题】:How to select mssql schema by using php queries?如何使用 php 查询选择 mssql 架构?
【发布时间】:2021-12-29 12:57:51
【问题描述】:

我在尝试将 prod 数据库恢复到 dev 数据库时遇到问题,因为它是按架构划分的。是否可以使用 PHP 代码选择架构?

【问题讨论】:

  • 不确定“选择...架构”是什么意思,但您可以为连接字符串中指定的用户设置默认架构。数据库引擎在解析非模式限定的对象名称时使用该默认值。
  • 说明 prod 中的数据库结构没有使用 schema 划分,但是 dev structrue 使用了。

标签: php sql-server


【解决方案1】:

我认为 PHP 没有内置函数来执行此操作,但我找到了一个非常适合我的解决方案。

function setSchema($query, $schema) {
    $query = str_ireplace('from ', "from {$schema}.", $query);
    $query = str_ireplace('update ', "update {$schema}.", $query);
    $query = str_ireplace('join ', "join {$schema}.", $query);
    $query = str_ireplace('into ', "into {$schema}.", $query);
    return $query;
}

【讨论】:

    猜你喜欢
    • 2016-11-25
    • 2015-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多