mysql wrong column increment

二次信任 提交于 2019-12-24 07:07:43

问题


what is wrong with this code?

$core->query("UPDATE games SET hits = hits + 1 WHERE id=".intval($id).";");

hits incerements by 2 and sometimes by 3! I mean for example hits = 3; when I call this function, hits will be 5 and sometimes 6! (add 2 and 3 instead 1).

mysql table type is MyISAM.

query function is:

function query($query) {


    $this->error="";
    $this->result=@$this->link->query($query);
    if(!$this->result) {
        $this->error=@$this->link->error;
        return FALSE;
    }

    return $this->result;
}

link is:

$link = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);

回答1:


The SQL code looks correct, so it must be the context that is causing the problem.

It is possible that you put the code in an element that gets called two or three times per page? If not explicitly, through an include or subroutine structure?




回答2:


It seems that your query is correct but may be this function call for multiple time for same $id value. Please check this..

thanks




回答3:


It was from flash on that page.



来源:https://stackoverflow.com/questions/10313961/mysql-wrong-column-increment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!