CI框架AR数据库操作常用函数总结

不言
发布: 2023-04-01 07:32:01
原创
1975 人浏览过

这篇文章主要介绍了CI框架AR数据库操作常用函数,结合实例形式总结分析了基于CI框架的数据库增删改查与缓存、结果集等相关操作函数与技巧,需要的朋友可以参考下

本文实例讲述了CI框架AR数据库操作常用函数。分享给大家供大家参考,具体如下:

1、查询表记录

$this->db->select();  //选择查询的字段
$this->db->select_max();
$this->db->select_min();
$this->db->select_avg();
$this->db->select_sum();
$this->db->from();   //选择表名
$this->db->join();
$this->db->get();   //得到查询结果
$this->db->get_where();
$this->db->where();
$this->db->or_where();
$this->db->where_in();
$this->db->or_where_in();
$this->db->where_not_in();
$this->db->or_where_not_in();
$this->db->like();
$this->db->or_like();
$this->db->not_like();
$this->db->or_not_like();
$this->db->group_by();
$this->db->distinct();
$this->db->having();
$this->db->or_having();
$this->db->order_by();
$this->db->limit();
$this->db->count_all_results();
登录后复制

2、增加表记录

$this->db->insert();
登录后复制

3、更改表记录

$this->db->set();
$this->db->update();
登录后复制

4、删除表记录

$this->db->delete();
登录后复制

5、清空表记录

$this->db->empty_table();
$this->db->truncate();
登录后复制

6、缓存部分

$this->db->start_cache()
$this->db->stop_cache()
$this->db->flush_cache()
登录后复制

7、结果结果集

result()  //返回对象数组
result_array() //返回二维数组
row()   //返回一个对象
row_array()  //返回一维数组
num_rows()  //返回查询的行数
num_fields() //返回查询结果的字段数
free_result() //释放查询所占的资源内存
登录后复制

8、辅助查询函数

$this->db->insert_id()  //获取刚刚插入的id
$this->db->affected_rows() //修改或插入影响的行数
$this->db->count_all();  //统计记录的总条数 这一函数加入where条件无效
$this->db->last_query();  //最后一条执行的sql语句
//注意以下两个函数仅返回sql语句 不执行sql语句
$data = array('name' => $name, 'email' => $email, 'url' => $url);
$str = $this->db->insert_string('table_name', $data);
$data = array('name' => $name, 'email' => $email, 'url' => $url);
$where = "author_id = 1 AND status = 'active'";
$str = $this->db->update_string('table_name', $data, $where); //返回正确格式的更新字符串
登录后复制

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

关于CI框架操作redis的方法

关于CI框架常用的函数封装

以上是CI框架AR数据库操作常用函数总结的详细内容。更多信息请关注PHP中文网其他相关文章!

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!