gpt4 book ai didi

php - 更新查询在 mysql 中抛出错误

转载 作者:可可西里 更新时间:2023-11-01 08:14:57 28 4
gpt4 key购买 nike

<分区>

我有一个名为“mostread”的表,其中包含 2 列 open_id(int) 和 read(int)。现在的问题是,如果表中已经存在“open_id”,那么我需要为每次点击更新“read”,否则我需要插入一个新行,其中包含从 Controller 检索到的“open_id”并且 read=1。我在我的模型中使用了下面的代码,它正确地插入了一个新行,但是我第二次点击它时会抛出如下错误。

发生数据库错误

Error Number: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read = read+1 WHERE open_id = '193'' at line 1

UPDATE mostread SET read = read+1 WHERE open_id = '193'

Filename: D:/Xampp/htdocs/opunletter/opunletter/application/models/Select.php

Line Number: 52

             public function click($id)  
{
$query = $this->db->query("SELECT * FROM mostread WHERE open_id='$id'");

$count= $query->num_rows();
if($count > 0) {
$this->db->set('read', 'read+1', FALSE);
$this->db->where('open_id', $id);
$this->db->update('mostread');

$data = array(
'open_id' => $id,
'read' => '1'
);

$this->db->insert('mostread', $data);
return TRUE;
}else{
return FALSE;
}
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com