Use the CI framework for simple addition, deletion, modification, and query to databases.
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 '<br/> ';}