php/mysql:是否可以添加一个字段,而不选择从数据库


php/mysql : Is it possible to add one to the field without selecting from db?

我有这个代码…

$q = "SELECT count FROM " . TABLE_PREFIX . "count WHERE 1 LIMIT 1;";
        $r = mysql_query($q);
        if (!$r) {
            echo $q;
            return false;
        }
        $o = mysql_fetch_object($r);
        $count = $o->count + 1;
    $q = "UPDATE " . TABLE_PREFIX . "count SET `count` = {$count}";

正如你所看到的,它从数据库中选择字段(它只是一个数字),并在将它发送回数据库之前给它加1…

是否可以跳过选择部分,而只是说:

`SET `count` += 1`

之类的?

试试这个。您可以更新列,而无需获取和增加该字段

UPDATE tablename set `count` = (`count`+1) WHERE 1 LIMIT 1;
$q = "UPDATE " . TABLE_PREFIX . "count SET `count` = `count`+1 ";
update TABLE_PREFIX set count = count + 1 where {condition}

基本上:

UPDATE `table` SET `count` = `count`+1;