繁体   English   中英

未设置Tinyint字段

[英]Tinyint field not being set

我试图将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是要保存的多维数据数组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM