Example of inserting database operation function based on thinkPHP class

高洛峰
Release: 2023-03-04 18:12:02
Original
1350 people have browsed it

The example in this article describes the insert database operation function based on the thinkPHP class. Share it with everyone for your reference, the details are as follows:

Insertion database operation based on TP class

/**************************
* 插入互动专家的数据
*
* @param object $model        实例化的模型
* @param array $Model        获取到的专家数据
* @param int  $result      插入成功后返回的id
* @date 2016/02/19
* @write zss
****************************/
private function collect_sp_t_insert($model){
    $model = D($model);
    //删除主键,防止此操作成为更新操作
    unset( $_POST[$model->getPk()]);
    //回调处理post数据
    if (method_exists($this, '_tigger_post')) {
        $this->_tigger_post($_POST);
      }
    //reate数据
    if(false === $model->create()) {
      $this->error($model->getError());
    }
    //保存当前数据对象
    if ($result = $model->add()) { //保存成功
      // 回调接口
      if (method_exists($this, '_tigger_insert')) {
        $this->_tigger_insert($result);
      }
    }
}
Copy after login

I hope this article will be helpful to everyone’s PHP program design based on the ThinkPHP framework.

For more related articles on insert database operation function examples based on thinkPHP classes, please pay attention to the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template