[英]Codeigniter4 shows You must use the "set" method when running update query even I used "set" method
My query as follows我的查询如下
function reset_attempt($usr_id, $attempt = 0)
{
if (!$usr_id)
exit("No user found");
$builder = $this->table($this->table);
$builder->set('usr_attempt', $attempt);
$builder->set('usr_lock', NULL);
$builder->where("usr_attempt > ", $this->max_attempt);
$builder->where($this->primaryKey, $usr_id);
echo "<br> Query: " . $builder->getCompiledUpdate(false);
exit();
// $builder->update($this->table);
}
Then I am getting the following error message然后我收到以下错误消息
CodeIgniter\\Database\\Exceptions\\DatabaseException #8
You must use the "set" method to update an entry.
The following worked以下工作
class UserModel extends Model
{
// Property used to connect with database
protected $db;
function __construct()
{
// Connedt with database
$this->db = \Config\Database::connect();
}
function reset_attempt($usr_id, $attempt = 0)
{
if (!$usr_id)
exit("No user found");
// Call method table() with $this->db
$builder = $this->db->table($this->table);
$builder->set('usr_attempt', $attempt);
$builder->set('usr_lock', NULL);
$builder->where("usr_attempt > ", $this->max_attempt);
$builder->where($this->primaryKey, $usr_id);
echo "<br> Query: " . $builder->getCompiledUpdate(false);
exit();
}
}
Output输出
Query: UPDATE `users` SET `usr_attempt` = '0', `usr_lock` = NULL WHERE `usr_attempt` > 2 AND `usr_id` = '1'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.