本文实例讲述了基于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框架的php程序设计有所帮助。
更多基于thinkphp类的插入数据库操作功能示例。