Mysql Update +1 not working on live server

Am using my local machine to develop my websites. I am currently working on a script o jail content scrappers and ban them later on.

I am dealing with the follow 'strange' mysql update situation.

By trying to update the counter to set the current int + 1, It wont happen and the same records is inserted as a new record.

When I run the exactly same query on my local machine (even with multiply fast requests) It count's like it supposed to be.

Could it be the scrapper with same ip is requesting pages faster than mySQL can write away the queries so they will be in a kind of queue?

Some one some good advice to treat this well?

Some more code:

// Check if ip exists
        $sql = $this->dbConnection->prepare("SELECT * FROM $this->table WHERE ipv4 = '$this->ipv4'");
        $sql->execute();

        $data = $sql->fetch(PDO::FETCH_OBJ);

        if ($data) {
            // Update counter ip
            $sql = $this->dbConnection->prepare("UPDATE $this->table SET counter = counter+1 WHERE ipv4 = '$data->ipv4'");
            $sql->execute();

        } else {

            // Insert new ip
            $ip2long = ip2long($this->ip);
            $sql = $this->dbConnection->prepare("INSERT INTO $this->table (ip, ipv4, referer, useragent) VALUES ('$ip2long', '$this->ip', '$this->referer', '$this->userAgent')");
            $sql->execute();
        }

Answers


Try an INSERT INTO ... ON DUPLICATE KEY UPDATE counter = counter+1 query instead.


Need Your Help

How to programmatically set drawableRight on Android Edittext?

android drawable

I know about set drawableRight in XML. but i required to do it programmatically because it is change as per some condition.

How can i delete a file after complete download on client PC in MVC asp.net

.net asp.net-mvc asp.net-mvc-3 download

i have used getCSV function for return csv file at client side but i want to delete a file after download complete at client side