当前位置: 移动技术网 > IT编程>开发语言>PHP > CI框架中数据库操作函数$this->db->where()相关用法总结

CI框架中数据库操作函数$this->db->where()相关用法总结

2017年12月12日  | 移动技术网IT编程  | 我要评论

本文实例总结了ci框架中数据库操作函数$this->db->where()相关用法。分享给大家供大家参考,具体如下:

ci 框架数据库操作函数 this->db->where() 的使用

1) $this->db->where('match (field) against ("value")', null, false)

如果把$this->db->where() 接受可选的第三个参数设置为 false, codeigniter 将不会为那些包含反勾号的字段名或表名提供保护。

2) $this->db->or_where()

本函数与上面的那个几乎完全相同,唯一的区别是本函数生成的子句是用 or 来连接的:

$this->db->where('name !=', $name);
$this->db->or_where('id >', $id);
// 生成: where name != 'joe' or id > 50

说明: or_where() 以前被叫作 orwhere(), 后者已经过时。

3) $this->db->where_in();

生成一段 where field in ('item', 'item') 查询语句,如果合适的话,用 and 连接起来。

$names = array('frank', 'todd', 'james');
$this->db->where_in('username', $names);
// 生成: where username in ('frank', 'todd', 'james')

4)$this->db->or_where_in();

生成一段 where field in ('item', 'item') 查询语句,如果合适的话,用 or 连接起来。

$names = array('frank', 'todd', 'james');
$this->db->or_where_in('username', $names);
// 生成: or username in ('frank', 'todd', 'james')

5)$this->db->where_not_in();

生成一段 where field not in ('item', 'item') 查询语句,如果合适的话,用 and 连接起来。

$names = array('frank', 'todd', 'james');
$this->db->where_not_in('username', $names);
// 生成: where username not in ('frank', 'todd', 'james')

6)$this->db->or_where_not_in();

生成一段 where field not in ('item', 'item') 查询语句,如果合适的话,用 or 连接起来。

$names = array('frank', 'todd', 'james');
$this->db->or_where_not_in('username', $names);
// 生成: or username not in ('frank', 'todd', 'james')

更多关于codeigniter相关内容感兴趣的读者可查看本站专题:《codeigniter入门教程》、《ci(codeigniter)框架进阶教程》、《php优秀开发框架总结》、《thinkphp入门教程》、《thinkphp常用方法总结》、《zend framework框架入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

希望本文所述对大家基于codeigniter框架的php程序设计有所帮助。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网