简体   繁体   English

如何修复'SQLSTATE [22007]:无效的日期时间格式:1292截断了错误的DOUBLE值:'X'

[英]How to fix 'SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value: 'X''

I'm currently setting up a website page ('records' page) that counts the amount of total people that went on another website page ('site' page), so I set up a cookie on the site page that increments said data in a database. 我目前正在建立一个网站页面(“记录”页面),该页面计算进入另一个网站页面(“网站”页面)的总人数,因此我在该网站页面上设置了一个cookie,以增加数据库。

I've seen other users get this problem because they included a "AND" statement in their "SET" statement. 我已经看到其他用户遇到此问题,因为他们在其“ SET”语句中包含了“ AND”语句。 I however don't have an "AND" statement 但是,我没有“ AND”语句

In my repository, I have this code: 在我的存储库中,我有以下代码:

public function addConnections($name): int
{
    $qb = $this->createQueryBuilder('connectionCounter')
        ->update('App\Entity\site', 'connectionCounter')
        ->set('connectionCounter.nbConnections', 'connectionCounter.nbConnections + 1')
        ->where('connectionCounter.name = (:name)')
        ->setParameter('name', $name)
        ->getQuery();

    return $qb->execute();
}

and in my controller, I have this code: 在我的控制器中,我有以下代码:

if($repository)
{
    $query = $this->getDoctrine()
                  ->getRepository(Activity::class)
                  ->findActivities($repository[0]->getIdSite());

    $cookieCreator = 0;
    if (!isset($_COOKIE['Connection'])) {
        setcookie("Connection","1",time()+60*60*24*100);

        $connections = $this->getDoctrine()
                            ->getRepository(Site::class)
                            ->addConnections($repository[0]->getIdSite());
}

What I expect is my database getting updated, and when I go on the records page, I see that the amount of visits incremented. 我期望数据库得到更新,当我进入“记录”页面时,我看到访问量增加了。

What actually happens is this: 实际发生的情况是这样的:

An exception occurred while executing 'UPDATE site SET nb_connections = nb_connections + 1 WHERE name = (?)' with params [2]:

SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value: 'X '

Even an explanation as to why this could happen would be great! 甚至对为什么会发生这种情况的解释也很棒!

Slight oversight on my part, in my controller, I have: 在我的控制器中,我有轻微的疏忽:

->addConnections($repository[0]->getIdSite());

When it should be: 什么时候应该是:

->addConnections($repository[0]->getName());

I changed it, it works now. 我更改了它,现在可以使用了。 Sorry! 抱歉!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 LARAVEL:SQLSTATE [22007]:无效的日期时间格式:1292 截断不正确的 DOUBLE 值 - LARAVEL : SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value Eloquent 删除 - SQLSTATE [22007]:无效的日期时间格式:1292 截断不正确的 DOUBLE 值: - Eloquent Delete - SQLSTATE[22007]: Invalid datetime format: 1292 Truncated incorrect DOUBLE value: SQLSTATE[22007]:无效的日期时间格式:1292 日期时间值不正确 - SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value Laravel 将时间戳保存为 DateTime - SQLSTATE[22007]:日期时间格式无效:1292 日期时间值不正确: - Timestamp being saved as DateTime by Laravel - SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: Laravel - SQLSTATE [22007]:无效的日期时间格式:1292 不正确的日期时间值:'1616818311712' - Laravel - SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1616818311712' SQLSTATE [22007]:日期时间格式无效:1292 日期时间值不正确:“fotostudio”列的“28-01-2022 12:00”。“transaction_details” - SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '28-01-2022 12:00' for column `fotostudio`.`transaction_details` SQLSTATE [22007]:无效的日期时间格式:1292错误的日期时间值:第1行的“ created_at”列为“ 1970-01-01 00:00:01” - SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '1970-01-01 00:00:01' for column 'created_at' at row 1 “SQLSTATE[22007]:无效的日期时间格式:1292 不正确的日期时间值:'2018'列'created_at'在第 1 行(SQL:插入到`news` - "SQLSTATE[22007]: Invalid datetime format: 1292 Incorrect datetime value: '2018' for column 'created_at' at row 1 (SQL: insert into `news` SQLSTATE [22007]:无效的日期时间格式:1366不正确的整数值 - SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value SQLSTATE [22007]:无效的日期时间格式:1366 不正确的 integer 值:问题 - SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect integer value: problem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM