abstract:?phpnamespace Home\Controller;use Think\Controller;class FormController extends Controller{public function insert(){$Form = D('Form');if($Form->create()) {$result = $Form->add();if($resu
?php
namespace Home\Controller;
use Think\Controller;
class FormController extends Controller{
public function insert(){
$Form = D('Form');
if($Form->create()) {
$result = $Form->add();
if($result) {
$this->success('數(shù)據(jù)添加成功!');
}else{
$this->error('數(shù)據(jù)添加錯(cuò)誤!');
}
}else{
$this->error($Form->getError());
}
}
}
如果主鍵是自增類型的話,add方法的返回值就是該主鍵的值。不是自增主鍵的話,返回值表示插入數(shù)據(jù)的個(gè)數(shù)。如果返回false則表示寫入出錯(cuò)。
Correcting teacher:西門大官人Correction time:2019-04-08 10:17:21
Teacher's summary:數(shù)據(jù)寫入理解的很好。糾正一下,如果主鍵是自增類型(不要求一定要自增,是主鍵就行)的話,add方法的返回值就是該主鍵的值