简体   繁体   English

如何使用 php 查询 select mssql 模式?

[英]How to select mssql schema by using php queries?

I had a issue when tried to restore prod database into a dev database because it is divided by schema.尝试将 prod 数据库恢复到 dev 数据库时遇到问题,因为它是按模式划分的。 Is it possible to select schema using PHP code?是否可以使用 PHP 代码实现 select 模式?

I don't think PHP has a built in function to do this, but i have found a solution that worked very well for me.我不认为 PHP 有一个内置的 function 可以做到这一点,但我找到了一个对我来说效果很好的解决方案。

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM