php - Is there any way in CodeIgniter to remove dbprefix from the query?
问题描述
I'm building a CI application, and I need to use 2 different databases (mysql & mssql). When i try to run a simple query to the mssql DB then CI adds the dbprefix to the table names, so it ends up to an error. How is it possible to prevent CI adding the prefix? There is no dbprefix set in database.php file
Query in Model
public function getAccName($uid)
{
$this->load->database('mssqlsrv',TRUE);
return $this->db->where("uid", $uid)
->select("account")->get("user_account");
}
解决方案
要正确回答这个问题:
在 Codeigniter 中处理多个数据库连接时,每个连接都需要分配给一个变量,例如:
$DB1 = $this->load->database('mssqlsrv', TRUE);
$DB2 = $this->load->database('group_two', TRUE);
然后你可以用
$DB1->where("uid", $uid)->select("account")->get("user_account");
代替
$this->db->where("uid", $uid)->select("account")->get("user_account");
有关这方面的更多信息,请参阅https://www.codeigniter.com/userguide3/database/connecting.html。
推荐阅读
- powershell - 使用 Powershell 从 AD 获取 AllowLogon 并不总是显示正确的信息
- angular - 运行 ng build --prod 时找不到模块“angularfire2/firestore”
- docker - dotnet core microservices 实际开发过程,给新手一个说明
- java - 如何在四人连线游戏中表达棋盘上的玩家
- javascript - 使用函数获取变量名 - 返回变量值
- python-3.x - Django - 在另一个表上更新数据库中的值
- json - 如何在自定义 Zapier 应用程序中从 Xero 访问特定订单项值?
- sql - 如何制作更新不同表的计数器触发器?
- drupal-modules - 如何从 URL 路径设置修复 webform drupal
- ios - 如何在 Swift 中压缩文件夹?