Codeigniter database operation function aggregation _ PHP Tutorial-php Tutorial

Source: Internet
Author: User
Codeigniter database operation function summary. There are many Codeigniter database operations on the internet. here is a summary. Copy the code as follows: query: $ query $ this-db_query (SELECT * FROMtable); there are a lot of Codeigniter database operations on the Internet, here is a summary.

The code is as follows:

// Query:
$ Query = $ this-> db_query ("SELECT * FROM table ");
========================================

// Result () returns an array of objects.
$ Data = $ query-> result ();

// Result_array () returns data
$ Data = $ query-> result_array ();

// Row () returns only one array of objects
$ Data = $ query-> row ();

// Number of rows returned by num_rows ()
$ Data = $ query-> num_rows ();

// Num_fields () returns the number of fields in the query request.
$ Data = $ query-> num_fields ();

// Row_array () returns only one array row
$ Data = $ query-> row_array ();

// Free_result () releases the memory occupied by the current query and deletes the associated resource ID
$ Data = $ query-> free_result ();

/*
========================================
INSERT operation
========================================
*/

// ID generated during the last insert operation
Echo $ this-> db-> insert_id ();

// Number of rows affected by write and update operations
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 running query statement
Echo $ this-> db-> last_query ();

// Insert data. the inserted data is 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 is 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
========================================
*/

// Obtain all the table data
$ This-> db-> get ('Table _ name ');

// The second parameter is the number of output records, and the third parameter is the start position.
$ This-> db-> get ('Table _ name', 10, 20 );

// Obtain data. The first parameter is the table name, the second parameter is the query condition, and the third parameter is the number of items.
$ This-> db-> get_where ('Table _ name', array ('id' => $ id), $ offset );

// Obtain data in select mode
$ This-> db-> select ('title, content, date ');
$ Data = $ this-> db-> get ('Table _ name ');

// Obtain the maximum value of a 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 ');

// Obtain the minimum value of a field
$ This-> db-> select_min ('age ');
$ This-> db-> select_min ('age', 'nianling ');

// Obtain the sum of fields
$ This-> db-> select_sum ('age ');
$ This-> db-> select_sum ('age', 'nianling ');

// Custom from table
$ This-> db-> select ('title', content, date ');
$ This-> db-> from ('Table _ name ');

// Query condition WHERE name = 'job' AND title = "boss" AND status = 'active'
$ This-> db-> where ('name', $ name );
$ This-> db-> where ('title', $ title );
$ This-> db-> where ('status', $ status );

// Query the range
$ This-> db-> where_in ('item1', 'item2 ');
$ This-> db-> where_not_in ('item1', 'item2 ');

// Match. The third parameter is the matching mode title LIKE '% match %'
$ This-> db-> like ('title', 'match', 'before/after/both ');

Bytes. The code is as follows: // query: $ query = $ this-db_query ("SELECT * FROM table"); ==============...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.