我想一个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);
}
这是极限代码:
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;
}
你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
是数据保存的一个多维数组。