Use the CI framework for simple addition, deletion, modification, and query to databases

Source: Internet
Author: User
: This article mainly introduces how to use the CI framework to add, delete, modify, and query data to databases. For more information about PHP tutorials, see. The following code is based on CodeIgniter_2.1.3

Use PHP to add, delete, modify, and query (pure code) to the database.

Http://www.cnblogs.com/corvoh/p/4641476.html

For compatibility issues with PHP5.6, see

Http://www.cnblogs.com/corvoh/p/4649357.html

Add:

// Insert
// Syntax: $ bool = $ this-> db-> insert ('Table name', associated array );
$ Data = array ('username' => 'Mary ', 'password' => 'Mary', // create an array with the username mary and password mary, and pass it to the variable $ data); $ bool = $ this-> db-> insert ('user', $ data ); // Insert $ data into the user table of the database var_dump ($ bool); // If yes, true is returned.

Delete:

// Delete
// Syntax: $ bool = $ this-> db-> delete ('Table name', WHERE condition ); $ bool = $ this-> db-> delete ('user', array ('id' => 3); // delete a database. all user information of id = 3 in the user table var_dump ($ bool); // if the table is successful, true is returned.


Change:

// Update $ data = array ('password' => 12345,); $ bool = $ this-> db-> update ('user', $ data, array ('id' => 3); // sets the database. the password for id = 3 in the user table is 12345
Var_dump ($ bool); // if it succeeds, true is returned.

Query:

// Get $ res = $ list = $ this-> db-> get ('user'); // var_dump ($ list); foreach ($ res-> result () as $ item) {// use foreach to list all user names echo $ item-> username; echo'
';}

The above describes how to use the CI framework to implement simple addition, deletion, modification, and query for the database, including some content, and hope to help those who are interested in the PHP Tutorial.

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.