donglei2288 2019-01-18 15:54
浏览 1208
已采纳

如何修复'SQLSTATE [22007]:无效的日期时间格式:1292截断错误的DOUBLE值:'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.

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('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!

  • 写回答

1条回答 默认 最新

  • doter1995 2019-01-18 16:00
    关注

    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!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Centos7 / PETGEM
  • ¥15 csmar数据进行spss描述性统计分析
  • ¥15 各位请问平行检验趋势图这样要怎么调整?说标准差差异太大了
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 wpf界面一直接收PLC给过来的信号,导致UI界面操作起来会卡顿
  • ¥15 init i2c:2 freq:100000[MAIXPY]: find ov2640[MAIXPY]: find ov sensor是main文件哪里有问题吗
  • ¥15 运动想象脑电信号数据集.vhdr
  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗