douan0729 2019-02-03 09:18
浏览 307
已采纳

没有设置Tinyint字段

I am trying to set the value of a tinyint field to 1, 2, or 3, but it's not being set. I am pretty new at mySQL, so I am probably making a mistake somewhere, but I can't see it.

I called the function and all the other fields are being set, just not tinyint, which keeps showing as 0.

 $this->db->update('jobattachment', ['redline' => $tid], ['id' => $attachmentid], ['editing' => '2']);

I have tried removing the quotes around the 2 and also setting a variable and doing ['editing'] => $editingLevel, but nothing works.

Code for update:

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);
}

This is the limit code:

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;
}
  • 写回答

1条回答 默认 最新

  • dongzhenjian5195 2019-02-03 12:12
    关注

    Your update() function takes 4 parameters, the last of which is an optional limit. When you call it, you are passing 4 parameters, but the last one is an array (['editing' => '2']). My guess is $limit is supposed to be an integer, so your code might generate something like ... LIMIT 5.

    So it looks like there is something wrong with how you are passing parameters.

    Right now, here's how the variables are set up by the parameters passed to update():

    $table = jobattachment
    $set   = ['redline' => $tid]
    $where = ['id' => $attachmentid]
    $limit = ['editing' => '2']
    

    My guess is that all the last 3 are supposed to be in $set - you are passing in 3 column names, each with a new value to save.

    Again, we can't see your actual set() code, but probably it expects an array of key/value pairs. So you would call update() like this (re-formatted to make it clear that you are passing just 2 parameters, vs 4 previously)

    $this->db->update('jobattachment', [
        ['redline' => $tid],
        ['id' => $attachmentid],
        ['editing' => '2']
    ]); 
    

    Now $set is a multi-dimensional array of data to save.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?