首页 > 解决方案 > 未设置 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;
}

标签: phpmysql

解决方案


您的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是要保存的多维数据数组。


推荐阅读