ThinkPHP-based database insertion Operation example, thinkphp example

Source: Internet
Author: User

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 );}}}

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.