ThinkPHP-based database insertion Operation example, thinkphp example
This example describes how to insert a database based on the thinkPHP class. We will share this with you for your reference. The details are as follows:
TP-based database insertion
/************************** Insert interactive expert data ** @ param object $ model instantiated Model * @ param array $ expert data obtained by the Model * @ param int $ id returned after the result is inserted successfully * @ date 2016/02/19 * @ write zss ******* * *******************/private function collect_sp_t_insert ($ model) {$ model = D ($ model); // Delete the primary key to prevent this operation from becoming an update operation unset ($ _ POST [$ model-> getPk ()]); // callback processing post data if (method_exists ($ this, '_ tigger_post') {$ this-> _ tigger_post ($ _ POST );} // reate data if (false ===$ model-> create () {$ this-> error ($ model-> getError ());} // Save the current data object if ($ result = $ model-> add () {// saved successfully // callback interface if (method_exists ($ this, '_ tigger_insert') {$ this-> _ tigger_insert ($ result );}}}