我尝试将tinyint字段的值设置为1、2或3,但没有设置。我是mySQL的新手,所以我可能在什么地方犯了个错误,但我看不出来。
我调用了这个函数,所有其他字段都被设置了,只有tinyint没有,它一直显示为0。
$this->db->update('jobattachment', ['redline' => $tid], ['id' => $attachmentid], ['editing' => '2']);我试着去掉2两边的引号,设置一个变量并“编辑”=> $editingLevel,但是都不起作用。
更新代码:
public function update($table = '', $set = NULL, $where = NULL, $limit = NULL)
{
// Combine any cached components with the current statements
$this->_merge_cache();
if ($set !== NULL)
{
$this->set($set);
}
if ($this->_validate_update($table) === FALSE)
{
return FALSE;
}
if ($where !== NULL)
{
$this->where($where);
}
if ( ! empty($limit))
{
$this->limit($limit);
}
$sql = $this->_update($this->qb_from[0], $this->qb_set);
$this->_reset_write();
return $this->query($sql);
}以下是limit代码:
public function limit($value, $offset = 0)
{
is_null($value) OR $this->qb_limit = (int) $value;
empty($offset) OR $this->qb_offset = (int) $offset;
return $this;
}发布于 2019-02-03 20:12:51
您的update()函数接受4个参数,其中最后一个是可选的限制。当您调用它时,您将传递4个参数,但最后一个是一个数组(['editing' => '2'])。我猜测$limit应该是一个整数,所以您的代码可能会生成类似... LIMIT 5的内容。
所以看起来你传递参数的方式有问题。
现在,下面是如何通过传递给update()的参数来设置变量
$table = jobattachment
$set = ['redline' => $tid]
$where = ['id' => $attachmentid]
$limit = ['editing' => '2']我的猜测是最后3个都应该是$set格式的--您传入了3个列名,每个列名都有一个要保存的新值。
同样,我们看不到实际的set()代码,但它可能需要一个键/值对数组。所以你可以像这样调用update() (重新格式化以清楚地表明你只传递了2个参数,而不是之前的4个)
$this->db->update('jobattachment', [
['redline' => $tid],
['id' => $attachmentid],
['editing' => '2']
]); 现在,$set是要保存的数据的多维数组。
https://stackoverflow.com/questions/54501479
复制相似问题