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!