[英]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.