温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

如何CI框架AR数据库操作常用函数

发布时间:2021-09-16 14:10:16 来源:亿速云 阅读:75 作者:柒染 栏目:开发技术

本篇文章为大家展示了如何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); //返回正确格式的更新字符串

PS:关于CodeIgniter详细使用技巧可参考本站在线手册:

CodeIgniter 2.2.4用户指南:
http://shouce.jb51.net/codeigniter2.2/

CodeIgniter 3.0用户指南:
http://shouce.jb51.net/codeigniter3.0/

上述内容就是如何CI框架AR数据库操作常用函数,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI