基于thinkPHP类如何实现插入数据库操作功能
更新:HHH   时间:2023-1-7


小编给大家分享一下基于thinkPHP类如何实现插入数据库操作功能,希望大家阅读完这篇文章之后都有所收获,下面让我们一起去探讨吧!

具体如下:

基于TP类的插入数据库操作

/**************************
* 插入互动专家的数据
*
* @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);
      }
    }
}

看完了这篇文章,相信你对“基于thinkPHP类如何实现插入数据库操作功能”有了一定的了解,如果想了解更多相关知识,欢迎关注天达云行业资讯频道,感谢各位的阅读!

返回开发技术教程...