Home  >  Article  >  Backend Development  >  laravel5.3 runs error in mysql5.1 error: 1366 Incorrect integer

laravel5.3 runs error in mysql5.1 error: 1366 Incorrect integer

WBOY
WBOYOriginal
2016-09-26 08:40:131545browse

Laravel has an error when running under MySQL5.1. The error is as follows:

<code>SQLSTATE[HY000]: General error: 1366 Incorrect integer value: ''1'' for column 'status' at row 1 (SQL: insert into `cases` (`case_name`, `status`, `updated_at`, `created_at`) values ('fdsafdsadsa', '1', 1474504956, 1474504956))
</code>

But the PDO I wrote has no problem executing the test

<code>try {
    $sth = $db->prepare('insert into cases(case_name,status,updated_at,created_at) values (?,?,?,?)');
    $sth->bindValue(1, '我也是中文', PDO::PARAM_STR);
    $sth->bindValue(2, '1', PDO::PARAM_INT);
    $sth->bindValue(3, time(), PDO::PARAM_INT);
    $sth->bindValue(4, time(), PDO::PARAM_INT);

    $sth->execute();
} catch (\Exception $e)
{
    echo $e->getMessage();
}</code>

Data table structure:laravel5.3 runs error in mysql5.1 error: 1366 Incorrect integer

I also checked online and it said that I changed SQL_MODE and changed it, but still got the error

The problem has been solved. It was the double quotation mark issue caused by adding Shell filter

Reply content:

Laravel has an error when running under MySQL5.1. The error is as follows:

<code>SQLSTATE[HY000]: General error: 1366 Incorrect integer value: ''1'' for column 'status' at row 1 (SQL: insert into `cases` (`case_name`, `status`, `updated_at`, `created_at`) values ('fdsafdsadsa', '1', 1474504956, 1474504956))
</code>

But the PDO I wrote has no problem executing the test

<code>try {
    $sth = $db->prepare('insert into cases(case_name,status,updated_at,created_at) values (?,?,?,?)');
    $sth->bindValue(1, '我也是中文', PDO::PARAM_STR);
    $sth->bindValue(2, '1', PDO::PARAM_INT);
    $sth->bindValue(3, time(), PDO::PARAM_INT);
    $sth->bindValue(4, time(), PDO::PARAM_INT);

    $sth->execute();
} catch (\Exception $e)
{
    echo $e->getMessage();
}</code>

Data table structure:laravel5.3 runs error in mysql5.1 error: 1366 Incorrect integer

I also checked online and it said that I changed SQL_MODE and changed it, but still got the error

The problem has been solved. It was the double quotation mark issue caused by adding Shell filter

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn