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.

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

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么