查询辅助函数

$this->db->insert_id()

这个ID号是执行数据插入时的ID。

$this->db->affected_rows()

Displays the number of affected rows, when doing "write\" type queries
(insert, update, etc.).

当执行写入操作(insert,update等)的查询后,显示被影响的行数。

Note: In MySQL "DELETE FROM TABLE" returns 0 affected rows. The database
class has a small hack that allows it to return the correct number of affected
rows. By default this hack is enabled but it can be turned off in the database
driver file.

注意:在 MySQL 中“DELETE FROM TABLE”的被影响行数将会返回 0。database 类有一个小
hack 允许返回正确的被影响的行数。默认情况下这个 hack 功能是打开的但可以在数据库驱动文件中关闭它。

$this->db->count_all();

Permits you to determine the number of rows in a particular table. Submit the
table name in the first parameter.
Example:

计算出指定表的总行数并返回。在第一个参数中写入被提交的表名。例如: echo
$this->db->count_all('my_table');

// Produces an
integer, like 25

$this->db->platform()

Outputs the database platform you are running (MySQL, MS SQL, Postgres,
etc...):

输出系统使用的数据库平台(MySQL, MS SQL, Postgres……)

echo
$this->db->platform();

$this->db->version()

Outputs the database version you are running:

输出系统正在运行的数据库版本号
echo $this->db->version();

$this->db->last_query();

Returns the last query that was run (the query string, not the result).
Example:

返回最后运行的查询(是查询语句,不是查询结果)

$str =
$this->db->last_query();

// Produces: SELECT * FROM sometable....

The following two functions help simplify the process of writing database
INSERTs and UPDATEs.

下面的两个函数简化了写入数据库的insert和update操作。

$this->db->insert_string();

This function simplifies the process of writing database inserts. It returns
a correctly formatted SQL insert string.
Example:

这个函数简化了写入数据库的insert函数。它返回一个标准的SQL insert字符串。例如: $data =
array('name' => $name, 'email' => $email, 'url' => $url);

$str =
$this->db->insert_string('table_name', $data);

The first parameter is the table name, the second is an associative array
with the data to be inserted. The above example
produces:

第一个参数是表名,第二个是被插入数据的联合数组,上面的例子生成的效果为: INSERT INTO
table_name (name, email, url) VALUES ('Rick', 'rick@example.com',
'example.com')

Note: Values are automatically escaped, producing safer
queries.

注解:被插入的数据会被自动转换和过滤,生成安全的查询语句。

$this->db->update_string();

This function simplifies the process of writing database updates. It returns
a correctly formatted SQL update string.
Example:

这个函数简化了写入数据库的update操作。它返回一条格式正确的SQL update字符串。例如: $data =
array('name' => $name, 'email' => $email, 'url' => $url);

$where
= "author_id = 1 AND status = 'active'";

$str =
$this->db->update_string('table_name', $data, $where);

The first parameter is the table name, the second is an associative array
with the data to be updated, and the third parameter is the "where" clause. The
above example
produces:

第一个参数是表名,第二个是被更新数据的关联数组,第三个参数是“where”子句。上面的例子生成的效果为:
UPDATE table_name SET name = 'Rick', email = 'rick@example.com', url =
'example.com' WHERE author_id = 1 AND status = 'active'

Note: Values are automatically escaped, producing safer
queries.

注解:被插入的数据会被自动转换和过滤,生成安全的查询语句。

***CI查询辅助函数:insert_id()、affected_rows()的更多相关文章

  1. CodeIgniter-Lottery - php ci 抽奖辅助函数

    CodeIgniter-Lottery - php ci 抽奖辅助函数 Github https://github.com/xjnotxj/CodeIgniter-Lottery 用法 1. 移入文件 ...

  2. PHP CI 查询条件大全

    php CI 框架 this->db->where() 条件 PHP 5 版本 $this->db->where() 接受可选的第三个参数.如果你将它设置为 FALSE, Co ...

  3. CI URL 辅助函数 url helper

    URL 辅助函数文件包含一些在处理 URL 中很有用的函数 加载辅助函数 本辅助函数通过如下代码加载: $this->load->helper('url'); 可用函数如下: site_u ...

  4. ci框架——辅助函数

    辅助函数:application/helper下面.命名要求为***_helper.php;这样在调用的时候直接$this->load->helper('***');若想给自定义的辅助函数 ...

  5. ci查询数据库

    public function getUsers() { $this->load->database();//载入数据库 $users = $this->db->get(&qu ...

  6. CI框架笔记

    @update 2016-4-2 13:45:35 一.目录结构 ci_demo ├─myapp 应用主目录 │ ├─autoload.php 自定义的自动加载文件(可选) │ ├─myapp.php ...

  7. 第一天ci框架开发商城2

    ci框架开发商城2 1/28/2016 9:45:52 PM mvc完整案例 mvc完成新闻的增删改查 news控制器news.php class News extends CI_controller ...

  8. CI入门

    CI入门 一.[查]按条件获取一条记录 获取数据有返回数组形式或对象形式,row_array().result_array()是以数组形式返回:row().result()是以对象形式返回.同样的,更 ...

  9. CI 数据库操作总结

    最简单示例 $query = $this->db->query("YOUR QUERY"); foreach ($query->result() as $row) ...

随机推荐

  1. MySQL force Index 强制索引概述

    以下的文章主要介绍的是MySQL force Index  强制索引,以及其他的强制操作,其优先操作的具体操作步骤如下:我们以MySQL中常用的hint来进行详细的解析,如果你是经常使用Oracle的 ...

  2. jquery------隐式迭代

    其中Jq方法遍历内部dom数组的过程就叫做[隐式迭代] my.js $(document).ready(function(){ (function($){ $.fn.swapClass=functio ...

  3. MyEclipse------随机流(能读也能写数据)

    RandomAccessFile流指向文件时,不刷新文件. 其中seek(long a)用来定位RandomAccessFile流的读写位置,其中参数a确定读写位置距离文件开头的字节个数. other ...

  4. linux建立用户 详细

    .你同时属于两个或两个以上的组. 两个条件你至少具备一个,你才能够把文件所属旧组变为新组.使用如下的命令将当前目录下所有html文件所属的组改为httpd: chgrp httpd *.html 和c ...

  5. ThinkPad紧凑型蓝牙键盘(0B47189)鼠标滚轮用法,F1到F12功能键的功能切换以及其他技巧

    入手小红点蓝牙键盘(ThinkPad Compact Bluetooth),手感极佳,小红点特别适合程序员工作,双手无需离开键盘就可以操作鼠标,完全解决肩部.腕部疲劳酸痛问题,程序员健康的大福音! 使 ...

  6. webform添加到webapi的支持

    1.添加引用 添加对 System.Net.Http , System.Net.Http.Formatting , System.Web.Http , System.Web.Http.Common , ...

  7. Oracle 11g r2 x64 中文乱码解决方案

    1.检查服务器编码: 执行SQL语法: select * from v$nls_parameters; 2.设置本地客户端编码: 进入 我的电脑,属性,高级,环境变量,添加2项:LANG=zh_CN. ...

  8. SQL里的EXISTS与in、not exists与not in

    系统要求进行SQL优化,对效率比较低的SQL进行优化,使其运行效率更高,其中要求对SQL中的部分in/not in修改为exists/not exists 修改方法如下: in的SQL语句 SELEC ...

  9. 微信公众平台开发(十) 消息回复总结——用其xml模板

    一.简介 微信公众平台提供了三种消息回复的格式,即文本回复.音乐回复和图文回复,在这一篇文章中,我们将对这三种消息回复的格式做一下简单讲解,然后封装成函数,以供读者使用. 二.思路分析 对于每一个PO ...

  10. [Effective JavaScript 笔记]第22条:使用arguments创建可变参数的函数

    第21条讲述使用可变参数的函数average.该函数可处理任意数量的参数并返回这些参数的平均值. 如何创建可变参数的函数 1.实现固定元数的函数 书上的版本 function averageOfArr ...