123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="utf-8" lang="utf-8">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=0" />
- <title>查询辅助函数 - CodeIgniter 中文手册|用户手册|用户指南|Wiki文档</title>
- <link rel="shortcut icon" href="http://codeigniter.org.cn/user_guide/../images/design/favicon.ico" type="image/x-icon" />
- <link rel="stylesheet" type="text/css" media="all" href="../userguide.css" />
- <link rel="search" href="http://codeigniter.org.cn/user_guide/../CodeIgniterSearch.xml" type="application/opensearchdescription+xml" title="CodeIgniter 搜索"/>
- <link rel="canonical" href="http://codeigniter.org.cn/user_guide/database/helpers.html" />
- <script type="text/javascript" src="../nav/mootools.js-ver=20130324.js"></script>
- <script type="text/javascript" src="../nav/mootools-more.js-ver=20130324.js"></script>
- <script type="text/javascript" src="../nav/nav.js-ver=20130324.js"></script>
- <script type="text/javascript" src="../nav/user_guide_menu.js-ver=20130324.js"></script>
- <meta name="robots" content="all" />
- <meta name="author" content="ExpressionEngine Dev Team" />
- <meta name="description" content="CodeIgniter 中文手册, CodeIgniter 用户指南, CodeIgniter User Guide, Wiki 文档" />
- </head>
- <body>
- <!-- START NAVIGATION -->
- <div id="nav">
- <div id="nav_inner">
- <script type="text/javascript">create_menu('../');</script>
- </div>
- </div>
- <script type="text/javascript">_setNavigation();</script>
- <div id="nav2"><a name="top"></a><a href="javascript:void(0);" onclick="myHeight.toggle();"><img src="../images/nav_toggle_darker.jpg" width="154" height="43" border="0" title="切换目录" alt="切换目录" /></a></div>
- <div id="masthead" class="clearfix">
- <div class="topbar-hd"><h1>CodeIgniter 用户指南 版本 2.2.0</h1></div>
- <div class="topbar-tip">编辑文档、查看近期更改请 <a href="#">登录</a> 或 <a href="#">注册</a> <a href="#">找回密码</a></div> <div id="breadcrumb_right"><a href="../toc.html">目录页</a></div>
- </div>
- <!-- END NAVIGATION -->
- <!-- START BREADCRUMB -->
- <table cellpadding="0" cellspacing="0" border="0" style="width:100%">
- <tr>
- <td id="breadcrumb">
- <a href="#" target="_blank">CodeIgniter 中国首页</a> ›
- <a href="../index.html">用户指南首页</a> › <a href="index.html">数据库类</a> › 查询辅助函数 </td>
- <td id="searchbox">
- <form method="get" action="http://www.google.com.hk/search" target="google_window">
- <input type="hidden" name="client" value="pub-0176846097796333"></input>
- <input type="hidden" name="forid" value="1"></input>
- <input type="hidden" name="ie" value="UTF-8"></input>
- <input type="hidden" name="oe" value="UTF-8"></input>
- <input type="hidden" name="as_sitesearch" id="as_sitesearch" value="codeigniter.org.cn/user_guide/" />
- 搜索用户指南
- <input type="text" class="input" style="width:200px;" name="q" id="q" size="31" maxlength="255" value="" />
-
- <input type="submit" class="submit" name="sa" value="Go" />
- </form>
- </td>
- </tr>
- </table>
- <!-- END BREADCRUMB -->
- <div style="clear:both;text-align:right;padding: 6px 40px 0 0;">
- <a href="#" target="_blank">查看原文</a>
- </div>
- <!--<br clear="all" />--><!-- START CONTENT -->
- <div id="content">
- <h1>查询辅助函数</h1>
- <h2>$this->db->insert_id()</h2>
- <br/>
- 这个ID号是执行数据插入时的ID。
- <h2>$this->db->affected_rows()</h2>
- <p>Displays the number of affected rows, when doing "write\" type queries (insert, update, etc.).</p>
- <br/>
- 当执行写入操作(insert,update等)的查询后,显示被影响的行数。<br/>
- <p>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.</p>
- <br/>
- 注意:在 MySQL 中“DELETE FROM TABLE”的被影响行数将会返回 0。database 类有一个小 hack 允许返回正确的被影响的行数。默认情况下这个 hack 功能是打开的但可以在数据库驱动文件中关闭它。
- <h2>$this->db->count_all();</h2>
- <p>Permits you to determine the number of rows in a particular table. Submit the table name in the first parameter. Example:</p>
- <br/>
- 计算出指定表的总行数并返回。在第一个参数中写入被提交的表名。例如:
- <code>echo $this->db->count_all('<var>my_table</var>');<br />
- <br />
- // Produces an integer, like 25
- </code>
- <h2>$this->db->platform()</h2>
- <p>Outputs the database platform you are running (MySQL, MS SQL, Postgres, etc...):</p>
- <p>输出系统使用的数据库平台(MySQL, MS SQL, Postgres……)</p>
- <code>echo $this->db->platform();</code>
- <h2>$this->db->version()</h2>
- <p>Outputs the database version you are running:</p><br/>
- 输出系统正在运行的数据库版本号
- <code>echo $this->db->version();</code>
- <h2>$this->db->last_query();</h2>
- <p>Returns the last query that was run (the query string, not the result). Example:</p>
- <p>返回最后运行的查询(是查询语句,不是查询结果)</p>
- <code>$str = $this->db->last_query();<br />
- <br />
- // Produces: SELECT * FROM sometable....
- </code>
- <p>The following two functions help simplify the process of writing database INSERTs and UPDATEs.</p>
- <br/>
- 下面的两个函数简化了写入数据库的insert和update操作。
- <h2>$this->db->insert_string(); </h2>
- <p>This function simplifies the process of writing database inserts. It returns a correctly formatted SQL insert string. Example:</p>
- <br/>
- 这个函数简化了写入数据库的insert函数。它返回一个标准的SQL insert字符串。例如:
- <code>$data = array('name' => $name, 'email' => $email, 'url' => $url);<br />
- <br />
- $str = $this->db->insert_string('table_name', $data);
- </code>
- <p>The first parameter is the table name, the second is an associative array with the data to be inserted. The above example produces:</p>
- <br/>
- 第一个参数是表名,第二个是被插入数据的联合数组,上面的例子生成的效果为:
- <code>INSERT INTO table_name (name, email, url) VALUES ('Rick', 'rick@example.com', 'example.com')</code>
- <p class="important">Note: Values are automatically escaped, producing safer queries.</p>
- <br/>
- 注解:被插入的数据会被自动转换和过滤,生成安全的查询语句。
- <h2>$this->db->update_string(); </h2>
- <p>This function simplifies the process of writing database updates. It returns a correctly formatted SQL update string. Example:</p>
- <br/>
- 这个函数简化了写入数据库的update操作。它返回一条格式正确的SQL update字符串。例如:
- <code>$data = array('name' => $name, 'email' => $email, 'url' => $url);<br />
- <br />
- $where = "author_id = 1 AND status = 'active'";
- <br /><br />
- $str = $this->db->update_string('table_name', $data, $where);
- </code>
- <p>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:</p>
- <br />
- 第一个参数是表名,第二个是被更新数据的关联数组,第三个参数是“where”子句。上面的例子生成的效果为:
- <code> UPDATE table_name SET name = 'Rick', email = 'rick@example.com', url = 'example.com' WHERE author_id = 1 AND status = 'active'</code>
- <p class="important">Note: Values are automatically escaped, producing safer queries.</p>
- <br/>
- 注解:被插入的数据会被自动转换和过滤,生成安全的查询语句。<p> </p>
- <div id="Contributors">
- 翻译贡献者:
- analyzer, Hex, IT不倒翁, loiynet, sexy22</div>
- <div id="DocDate">
- 最后修改: 2012-10-25 17:00:51</div>
- </div>
- <!-- END CONTENT -->
- <div id="footer">
- <p>
- 上一个主题: <a href="results.html">查询结果</a> · <a href="#top">页首</a>
- · <a href="../index.html">用户指南首页</a> · 下一个主题: <a href="active_record.html">Active Record 模式</a> </p>
- <p><a href="#">CodeIgniter</a> · 版权所有 © 2006-2013 · <a href="#">Ellislab, Inc.</a></p>
- <p>中文化: <a href="#">CodeIgniter 中国</a> · 制作: Hex · 版本: 1.30 · 鸣谢: 子非鱼</p>
- </div>
- </body>
- </html>
|