In my blog, I want to count the articles views every time the page is loaded so I can make a chart of the top articles.
I'm using this code but something goes wrong.
If I put the first query in phpMyAdmin the query result is correct.
$readViewsCountSQL = "SELECT `view_count` FROM `andreaem`.`article` WHERE `article`.`slug` = '$articleSlug' LIMIT 1";
$readViewsCount = $DB_CON ->query($readViewsCountSQL);
$readViewsCountResult = $readViewsCount->fetch(PDO::FETCH_ASSOC);
function updateVCount ($current) {
$count = $current ++;
return $count;
}
$addViewsCount = updateVCount($readViewsCountResult);
var_dump($addViewsCount); //This return the correct value
$updateViewsCount = "UPDATE `andreaem`.`article` SET `view_count` = '$addViewsCount' WHERE `article`.`slug` = '$articleSlug'";
$DB_CON ->query($updateViewsCount);
In the mySQL logs the query was executed successfully but something goes wrong.
$DB_CON is the PDO connection and working in other queries
Aucun commentaire:
Enregistrer un commentaire