一次調用為啥總插入兩條相同數據???
????public?function?add()?{
//????????$result?=?DB::insert('insert?into?student(name,?age)?values(?,??)',?['xxx',?18]);
//????????var_dump($result);
????????$result?=?DB::table('student')
????????????->insertGetId(['name'?=>?'mmm',?'age'=>20]);
????????var_dump($result);
????????return?"StudentController?-?add";
????}我使用 兩種方式插入數據, 每次訪問一次接口,數據庫總是插入兩條相同的數據,除了 主鍵外,其他都相同,是為什么呢?
mysql> select * from student;
+-----+------+-----+-----+------------+------------+
| id? | name | age | sex | created_at | updated_at |
+-----+------+-----+-----+------------+------------+
| 108 | mmm? |? 20 | ? 0 |? ? ? ? ? 0 |? ? ? ? ? 0 |
| 109 | mmm? |? 20 | ? 0 |? ? ? ? ? 0 |? ? ? ? ? 0 |
+-----+------+-----+-----+------------+------------+
2018-10-08
你這里添加一次了??$result?=?DB::table('student')?->insertGetId(['name'?=>?'mmm',?'age'=>20]); ?return?"StudentController?-?add";這里又一次;所以是兩次