Home > Backend Development > PHP Tutorial > Use the CI framework to implement simple additions, deletions, modifications and queries in the database, ci framework_PHP tutorial

Use the CI framework to implement simple additions, deletions, modifications and queries in the database, ci framework_PHP tutorial

WBOY
Release: 2016-07-13 09:46:13
Original
895 people have browsed it

Use the CI framework to implement simple additions, deletions, modifications and queries in the database. The ci framework

The following code is based on CodeIgniter_version 2.1.3

Use PHP to implement simple addition, deletion, modification and query in the database (pure code) please click

http://www.cnblogs.com/corvoh/p/4641476.html

For compatibility issues between CodeIgniter_2.1.3 and PHP5.6, please click

http://www.cnblogs.com/corvoh/p/4649357.html

Added:

<span>//</span><span>insert<br /></span><span><span>//语法:$bool=$this->db->insert('表名',关联数组);<br /></span></span>
<span>$data</span>=<span>array</span><span>(
</span>    'username'=>'mary',
    'password'=>'mary',<span>//建立一个用户名叫mary,密码为mary的数组,并传递给变量$data</span><span>
);
</span><span>$bool</span>=<span>$this</span>->db->insert('user',<span>$data</span><span>);<span>//将$data插入数据库的user表中</span>
</span><span>var_dump</span>(<span>$bool</span>);<span>//成功则返回TURE</span>
Copy after login

Delete:

<span>//</span><span>delete<br />//语法:<span>$bool=$this->db->delete('表名',WHERE条件);</span></span>
<span>$bool</span>=<span>$this</span>->db->delete('user',<span>array</span>('id'=>3<span>));<span>//删除数据库.user表里id=3的用户所有信息</span>
</span><span>var_dump</span>(<span>$bool</span>);<span>//成功则返回TURE</span>
Copy after login


Change:

<span>//<span>update
<span>$data=<span>array<span>(
    'password'=>12345,<span>
);
<span>$bool=<span>$this->db->update('user',<span>$data,<span>array('id'=>3<span>));<span>//将数据库.user表里id=3的用户密码给为12345<br /></span><span>var_dump(<span>$bool);<span>//成功则返回TURE</span></span></span></span></span></span></span></span></span></span></span></span></span></span>
Copy after login

Check:

<span>//<span>get
<span>$res=<span>$list=<span>$this->db->get('user'<span>);
<span>//<span>var_dump($list);
<span>foreach(<span>$res->result() <span>as <span>$item<span>){<span>//利用foreach来列出所有用户名</span>
    <span>echo <span>$item-><span>username;
<span>echo '<br />'<span>;
}</span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span></span>
Copy after login

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1034507.htmlTechArticleUse the CI framework to implement simple additions, deletions, modifications and queries to the database. The following code of the ci framework is based on CodeIgniter_2.1.3 version using PHP To implement simple additions, deletions, modifications and queries (pure code) in the database, please click http:/...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template