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

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

WBOY
WBOYOriginal
2016-06-13 08:39:36767browse

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

本文实例总结了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程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn