There are many introductions to Codeigniter database operations on the Internet. Here is a summary.
Copy code The code is as follows:
//Query:
$query = $this->db_query("SELECT * FROM table");
==================================
//result () Return object array
$data = $query->result();
//result_array() Return data
$data = $query->result_array();
//row() only returns one row of object array
$data = $query->row();
//num_rows() returns the number of query result rows
$data = $query->num_rows();
//num_fields() returns the number of fields requested by the query
$data = $query->num_fields();
/ /row_array() returns only one row array
$data = $query->row_array();
//free_result() releases the memory occupied by the current query and deletes the associated resource identifier
$ data = $query->free_result();
/*
============================ ======
Insert operation
====================================
*/
//ID generated by the last insert operation
echo $this->db->insert_id();
//Write and update operations are affected The number of rows
echo $this->db->affected_rows();
//Returns the total number of rows in the specified table
echo $this->db->count_all(' table_name');
//Output the current database version number
echo $this->db->version();
//Output the current database platform
echo $this->db->platform();
//Return the last query statement run
echo $this->db->last_query();
//Insert data, the inserted data will be automatically converted and filtered, for example:
//$data = array('name' => $name, 'email' => $email, 'url ' => $url);
$this->db->insert_string('table_name', $data);
/*
======== =========================
Update operation
================= =================
*/
//Update data, the updated data will be automatically converted and filtered, for example:
/ /$data = array('name' => $name, 'email' => $email, 'url' => $url);
//$where = "author_id = 1 AND status = ' active'";
$this->db->update_string('table_name', $data, $where);
/*
========== ========================
Select data
================== ================
*/
//Get all data of the table
$this->db->get('table_name ');
//The second parameter is the number of output items, and the third parameter is the starting position
$this->db->get('table_name', 10, 20);
//Get data, the first parameter is the table name, the second parameter is the acquisition condition, and the third parameter is the number of items
$this->db->get_where('table_name', array('id'=>$id), $offset);
//Select method to obtain data
$this->db->select('title, content, date') ;
$data = $this->db->get('table_name');
//Get the maximum value of the field. The second parameter is an alias, which is equivalent to max(age) AS nianling
$this->db->select_max('age');
$this->db->select_max('age', 'nianling');
//Get the minimum value of the field
$this->db->select_min('age');
$this->db->select_min('age', 'nianling');
//Get the sum of fields
$this->db->select_sum('age');
$this->db->select_sum('age', 'nianling ');
//Customized from table
$this->db->select('title', content, date');
$this->db-> ;from('table_name');
//Query condition WHERE name = 'Joe' AND title = "boss" AND status = 'active'
$this->db->where( 'name', $name);
$this->db->where('title', $title);
$this->db->where('status', $status );
//Range query
$this->db->where_in('item1', 'item2');
$this->db->where_not_in(' item1', 'item2');
//Matching, the third parameter is the matching mode title LIKE '%match%'
$this->db->like('title', 'match', 'before/after/both');
http://www.bkjia.com/PHPjc/788620.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/788620.htmlTechArticleThere are many introductions to Codeigniter database operations on the Internet. Here is a summary. Copy the code as follows: //Query: $query = $this-db_query("SELECT * FROM table"); ===========...
Statement: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