Home Backend Development PHP Tutorial Summary of common functions for CI framework AR database operations

Summary of common functions for CI framework AR database operations

Jun 14, 2018 pm 01:57 PM
ci framework Database operations

This article mainly introduces the commonly used functions of CI framework AR database operations. It summarizes and analyzes the database addition, deletion, modification, caching, result set and other related operation functions and techniques based on CI framework in the form of examples. Friends in need can refer to the following

The examples in this article describe common functions for CI framework AR database operations. Share it with everyone for your reference, the details are as follows:

1. Query table record

$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();
Copy after login

##2 , add table records

$this->db->insert();
Copy after login

3, change table records

$this->db->set();
$this->db->update();
Copy after login

4. Delete table records

$this->db->delete();
Copy after login

5. Clear table records

$this->db->empty_table();
$this->db->truncate();
Copy after login

6、Cache part

$this->db->start_cache()
$this->db->stop_cache()
$this->db->flush_cache()
Copy after login

##7、 Result result set

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

8. Auxiliary query function

$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); //返回正确格式的更新字符串
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

About the method of operating redis in the CI framework


About the commonly used function encapsulation in the CI framework


The above is the detailed content of Summary of common functions for CI framework AR database operations. For more information, please follow other related articles on the PHP Chinese website!

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

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use CI framework in php? How to use CI framework in php? Jun 01, 2023 am 08:48 AM

How to use CI framework in php?

How to use PHP scripts to perform database operations in Linux environment How to use PHP scripts to perform database operations in Linux environment Oct 05, 2023 pm 03:48 PM

How to use PHP scripts to perform database operations in Linux environment

How to use CodeIgniter4 framework in php? How to use CodeIgniter4 framework in php? May 31, 2023 pm 02:51 PM

How to use CodeIgniter4 framework in php?

How to use Pagoda Panel for MySQL management How to use Pagoda Panel for MySQL management Jun 21, 2023 am 09:44 AM

How to use Pagoda Panel for MySQL management

How to use CI framework in PHP How to use CI framework in PHP Jun 27, 2023 pm 04:51 PM

How to use CI framework in PHP

How to use CI4 framework in php? How to use CI4 framework in php? Jun 01, 2023 pm 02:40 PM

How to use CI4 framework in php?

How to use thinkorm to improve database operation efficiency How to use thinkorm to improve database operation efficiency Jul 28, 2023 pm 03:21 PM

How to use thinkorm to improve database operation efficiency

Using PDO for Database Operations: A Better Way with PHP Using PDO for Database Operations: A Better Way with PHP Jun 21, 2023 pm 01:36 PM

Using PDO for Database Operations: A Better Way with PHP

See all articles