加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – MySQL bind_param将NULL写入表

发布时间:2020-12-13 15:58:13 所属栏目:PHP教程 来源:网络整理
导读:问题:尽管我的$settings数组中包含值(int),但当值为0和2时,MySQL会将NULL写入表中. 作为参考,$settings数组中的每个索引都是[0] = max和[1] = min的数组. public function updateAdaptiveArmour($gameid,$shipid,$settings){ foreach ($settings as $key =
问题:尽管我的$settings数组中包含值(int),但当值为0和2时,MySQL会将NULL写入表中.

作为参考,$settings数组中的每个索引都是[0] = max和[1] = min的数组.

public function updateAdaptiveArmour($gameid,$shipid,$settings){

    foreach ($settings as $key => $value){
        debug::log($key." ".$value[0]." ".$value[1]);

       //just to show the contents
       //   [561103190304f][2015-10-04 12:44:41] particle 4 2 
       //   [56110319035b3][2015-10-04 12:44:41] laser 0 0 
       //   [56110319035b3][2015-10-04 12:44:41] molecular 0 0 
    }   


    try {
        if ($stmt = $this->connection->prepare(
                "UPDATE 
                    tac_adaptivearmour
                 SET
                    particlealloc = ?,laseralloc = ?,molecularalloc = ?
                 WHERE 
                    gameid = ?
                    AND shipid = ?
                 "
        ))
        {
            $stmt->bind_param('iiiii',$settings[0][1],$settings[1][1],$settings[2][1],$gameid,$shipid);
            $stmt->execute();
            $stmt->close();
        }
    }
    catch(Exception $e) {

        throw $e;
    }
}

理想情况下,对于此示例,我希望UPDATE为2/0/0而不是null / null / null.

解决方法

您的数组填充如下:

$settings = [
    'particle' => [4,2],'laser' => [0,0],'molecular' => [0,0]
];

我希望能回答这个问题,而无需进一步解释.

它将固定如下:

$stmt->bind_param('iiiii',$settings['particle'][1],$settings['laser'][1],$settings['molecular'][1],$shipid
);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读