dtbl1231 2015-07-01 21:17
浏览 38

Codeigniter:使用预准备语句删除查询

I'm not sure if this is a codeigniter thing or specifically a mysqli thing.

In my model class I'm trying to delete using 2 WHERE arguments:

$query = "DELETE FROM users WHERE user_id = ? AND company_id = ?";
$result = $this->db->query( $query, $user_id, '1' );

Error message: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '? AND company_id = ?' at line 1

Any ideas?

  • 写回答

2条回答 默认 最新

  • dongwu9063 2015-07-01 21:23
    关注

    I recommend you to use 'active record'

    $this->db->where('user_id', $user_id);
    $this->db->where('company_id', 1);
    $this->db->delete('users'); 
    

    https://ellislab.com/codeigniter/user-guide/database/active_record.html

    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计