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.

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

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来