2019-01-18 15:54

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

  • php
  • sql

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.

I've seen other users get this problem because they included a "AND" statement in their "SET" statement. I however don't have an "AND" statement

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(' = (:name)')
        ->setParameter('name', $name)

    return $qb->execute();

and in my controller, I have this code:

    $query = $this->getDoctrine()

    $cookieCreator = 0;
    if (!isset($_COOKIE['Connection'])) {

        $connections = $this->getDoctrine()

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!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享