background image

插入数据

$this->db->insert();

生成一条基于你所提供的数据的 SQL

 

 

插入字符串并执行查询。你可以向函数传递 数组 或

 

一个 对象。

$this->db->insert_batch();

一次插入多条数据,生成一条基于你所提供的数据的 SQL 插入字符串并执行查询。你可

 

 

 

以向函数传递 数组 或一个 对象。

$this->db->set();

本函数使您能够设置 inserts(插入)或 updates(更新)值。它可以用来代替那种直接传递数组
给插入和更新函数的方式。
更新数据

$this->db->update();

根据你提供的数据生成并执行一条 update(更新)语句。你可以将一个数组或者对象传递给
本函数。

$this->db->update_batch();

Generates an update string based on the data you supply, and runs the query. You can either pass 
an array or an object to the function. Here is an example using an array:
删除数据

$this->db->delete();

生成并执行一条 DELETE(删除)语句。

$this->db->empty_table();

生成并执行一条 DELETE(删除)语句。

$this->db->truncate();

生成并执行一条 TRUNCATE(截断)语句。
链式方法
链式方法允许你以连接多个函数的方式简化你的语法。考虑一下这个范例:

$this->db->select('title')->from('mytable')->where('id', $id)->limit(10, 20); 
$query = $this->db->get();

 

说明: 链式方法只能在 PHP 5 下面运行。

查询

$this->db->query();

 

 

要提交一个查询,用以下函数:

$this->db->query('YOUR QUERY HERE');

 

query() 函数以 object(对象)

 

 

的形式返回一个数据库结果集。 当使用 "read" 模式来运行查询

时, 

你可以使用 显示你的结果集 来显示查询结果; 

 

当使用 "write" 模式来运行查询时, 将

 

会仅根据执行的成功或失败来返回 TRUE   

或 FALSE.

转义查询

$this->db->escape()

这个函数将会确定数据类型,以便仅对字符串类型数据进行转义。并且,

 

它也会自动把数据用单引号括起来,所以你不必手动添加单引号,用法如下:

$sql = 

"INSERT INTO table (title) VALUES(".$this->db->escape($title).")";

查询辅助函数