php - 未设置 Tinyint 字段
问题描述
我正在尝试将 tinyint 字段的值设置为 1、2 或 3,但它没有被设置。我对 mySQL 很陌生,所以我可能在某个地方犯了错误,但我看不到它。
我调用了该函数,并且正在设置所有其他字段,只是不是 tinyint,它一直显示为 0。
$this->db->update('jobattachment', ['redline' => $tid], ['id' => $attachmentid], ['editing' => '2']);
我尝试删除 2 周围的引号并设置变量并执行 ['editing'] => $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
是要保存的多维数据数组。
推荐阅读
- unity3d - 将数据库链接到服务器上的 php 脚本到 c#
- android - Android Studio 预览版没有链接障碍
- python - 如何将唯一标识符与来自 Python 应用程序的 PostgreSQL 连接相关联?
- delphi - 如何遍历过滤的 dbGrid
- javascript - 如何通过在javascript中移动滑块来增加圆圈中的线条
- javascript - 使用queryselectorall选择innerHTML等于指定值的所有元素是否可行?
- ffmpeg - FFMPEG 再保险
- java - 如何在 libGdx 中创建我自己在 .png 中绘制的字体?
- java - 当我们使用保留端口时,为什么套接字编程工作?
- javascript - ExpressionChangedAfterItHasBeenCheckedError:表达式在检查后已更改。以前的值:'ngIf: true'。当前值:'ngIf: false'