Codeigniter4 显示运行更新查询时必须使用 "set" 方法,即使我使用了"set"方法



我的查询如下

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);
}

然后我得到以下错误信息

CodeIgniterDatabaseExceptionsDatabaseException #8

You must use the "set" method to update an entry.

下面的工作

class UserModel extends Model
{
// Property used to connect with database
protected $db;

function __construct()
{
// Connedt with database
$this->db = ConfigDatabase::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();
}
}

Query: UPDATE `users` SET `usr_attempt` = '0', `usr_lock` = NULL WHERE `usr_attempt` > 2 AND `usr_id` = '1'

相关内容

  • 没有找到相关文章

最新更新