: 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.