mysql wrong column increment

2019-07-29 13:51发布

问题:

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.