php - Why does this insert error occur in the Laravel project?
Get the solution ↓↓↓I'm using a SQL INSERT in Laravel.
SQL returns an error when I use the Laravel query builder.
But SQL INSERT directly on the server normally succeeds.
$results = DB::table('tbl_corona_region')->insert(
[
'seq' => "{$data->item[$i]->seq}",
'create_dt' => "'{$createDt}'",
'region_nm' => "'{$data->item[$i]->gubun}'",
'region_cn' => "'{$data->item[$i]->gubunCn}'",
'region_en' => "'{$data->item[$i]->gubunEn}'",
'defCnt' => "{$data->item[$i]->defCnt}",
'incDec' => "{$data->item[$i]->incDec}",
'deathCnt' => "{$data->item[$i]->deathCnt}",
'isolIngCnt' => "{$data->item[$i]->isolIngCnt}",
'isolClearCnt' => "{$data->item[$i]->isolClearCnt}",
'localOccCnt' => "{$data->item[$i]->localOccCnt}",
'overFlowCnt' => "{$data->item[$i]->overFlowCnt}",
//'qurRate' => "{$data->item[$i]->qurRate}",
'stdDay' => "'2021-07-10 00:00:00'",
'update_dt' => "'2021-07-10 00:00:00'"
]
);
SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: ''2021-07-09 09:43:18'' for column 'create_dt' at row 1 (SQL: insert into
tbl_corona_region
(seq
,create_dt
,region_nm
,region_cn
,region_en
,defCnt
,incDec
,deathCnt
,isolIngCnt
,isolClearCnt
,localOccCnt
,overFlowCnt
,stdDay
,update_dt
) values (10628, '2021-07-09 09:43:18', '검역', '隔離區', 'Lazaretto', 4492, 39, 5, 383, 4104, 0, 39, '2021-07-10 00:00:00', '2021-07-10 00:00:00'))
Answer
Solution:
You can remove quotes
$results = DB::table('tbl_corona_region')->insert(
[
'seq' => $data->item[$i]->seq,
'create_dt' => $createDt,
'region_nm' => $data->item[$i]->gubun,
'region_cn' => $data->item[$i]->gubunCn,
'region_en' => $data->item[$i]->gubunEn,
'defCnt' => $data->item[$i]->defCnt,
'incDec' => $data->item[$i]->incDec,
'deathCnt' => $data->item[$i]->deathCnt,
'isolIngCnt' => $data->item[$i]->isolIngCnt,
'isolClearCnt' =>$data->item[$i]->isolClearCnt,
'localOccCnt' => $data->item[$i]->localOccCnt,
'overFlowCnt' =>$data->item[$i]->overFlowCnt,
//'qurRate' => "{$data->item[$i]->qurRate",
'stdDay' => "2021-07-10 00:00:00",
'update_dt' => "2021-07-10 00:00:00"
]
);
Answer
Solution:
I think the problem is with your time zone, see the below question with the same problem:
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: closed without sending a request; it was probably just an unused speculative preconnection
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.