ThinkPHP5使用SQLServer 数据库Schemas

浏览:834 发布日期:2018/12/05 分类:技术分享
修改thinkphp自带 Sqlsrv.php 文件,让数据库查询支持多个Schemas模式查询;
Sqlserver数据库默认的Schemas为 dbo 。TP5默认数据库连接全在 dbo模式下。
需要访问其他Schemas下的表提示错误,无法获取到正确的数据字段。

查找到 \thinkphp\library\think\db\connector\Sqlsrv.php 文件,找到 getFields 方法,将list($tableName) = explode(' ', $tableName);替换为:list($tableName) = explode(' ', $tableName);
$tableNames = explode('.', $tableName);
$tableName = isset($tableNames[1])?$tableNames[1]:$tableNames[0];
完美解决!!!!!
最佳答案
评论( 相关
后面还有条评论,点击查看>>