简体   繁体   English

mysql:使用准备好的查询中的列值更新现有列

[英]mysql : updating existing column using the column value in prepared query

Old query was like this 旧查询是这样的

update tbl_order set `pack_id` =0, `pack_down_count`=pack_down_count + '".intval($_POST['item_number'])."',`price`='".$_POST['mc_gross']."', `otime`=Now(), `ptime`=Now(), status='paid', pack_download=pack_download + '".intval($_POST['item_number'])."' where member_id='".$_MYVAR['userid']."'"

I liked to change it to prepared statment , I am using a class from https://github.com/joshcam/PHP-MySQLi-Database-Class 我喜欢将其更改为准备好的语句,我使用的是https://github.com/joshcam/PHP-MySQLi-Database-Class中的类

for updating 用于更新

I changed the above query to 我将上面的查询更改为

       $data = array(
       'pack_id'              =>$_MYVAR['pack_id'], 
       'pack_apply_count'      =>`pack_apply_count` + intval($_POST['item_number']),
       'price'                =>$_POST['mc_gross'], 
       'otime'                =>date('Y-m-d H:i:s'), 
       'ptime'                =>date('Y-m-d H:i:s'), 
       'status'               =>'paid', 
       'pack_apply'        =>`pack_apply` + intval($_POST['item_number'])
       );
       $db->where('member_id',$_MYVAR['userid']);
       $db->update("tbl_order",$data);

also tried without backticks around pack_apply_count and pack_apply but didn't update my table 还尝试了在pack_apply_count和pack_apply周围没有反引号的情况,但是没有更新我的表

       $data = array(
       'pack_id'              =>$_MYVAR['pack_id'], 
       'pack_apply_count'      =>pack_apply_count + intval($_POST['item_number']),
       'price'                =>$_POST['mc_gross'], 
       'otime'                =>date('Y-m-d H:i:s'), 
       'ptime'                =>date('Y-m-d H:i:s'), 
       'status'               =>'paid', 
       'pack_apply'        =>pack_apply + intval($_POST['item_number'])
       );
       $db->where('member_id',$_MYVAR['userid']);
       $db->update("tbl_order",$data);

Please tell correct way to update the table 请告诉正确的方式更新表格

The link you provided will give you the information you need, look at the section Update Query . 您提供的链接将为您提供所需的信息,请参阅更新查询部分。

It seems you can increment with $db->inc($_POST['item_number']) 看来您可以使用$db->inc($_POST['item_number'])

As shown in the example: 如示例所示:

$data = Array (
    'firstName' => 'Bobby',
    'lastName' => 'Tables',
    'editCount' => $db->inc(2),
    // editCount = editCount + 2;
    'active' => $db->not()
    // active = !active;
);

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

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