所有列均设置为相同的值 [英] All columns being set to the same value

查看:61
本文介绍了所有列均设置为相同的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我完全不知道自己的脚本有什么问题. JSON数据正确输入,变量$ i和$ current都是在forloop中每个阶段应使用的变量.

I am totally lost as to what is wrong with my script. The JSON data is coming in correctly and the variables $i and $current are all what they should be at every stage in the forloop.

似乎总是用id更新我的数据库,因此在id为11的情况下,它将更新所有带有数字11的列.

It seems to keep updating my database with the id, so in the case where id is 11, it will update all columns with the number 11.

这是我的剧本:

if($mode == 'SAVE_BUYING_ROW')
{   
    $JSON = (array)$JSON ;

    include('pdoconnect.php') ;
    $result = $dbh->prepare("UPDATE parts_trading_instructions
                 SET quantity = ?, supplierRef = ?, currencyRef = ?, 
                             net = ?, vat = ?, shippingNet = ?,
                 shippingVat = ?, direct = ?, ebayItemNumber = ?
                 WHERE id = ?") ;
    $i = 0 ;
    foreach($JSON as $current) {
        $current = (string)$current ;
        if($i == 0)
        {
            $i++ ;
            continue ;
        }

            $result->bindParam($i, $current, PDO::PARAM_STR) ;  
        $i++ ;
    }

$result->execute() ;

}

谁能看到我要去哪里错了?

Can anyone see where I am going wrong?

推荐答案

使用 bindValue ,而不是 bindParam . bindParam对变量进行引用,并且仅在执行查询时读取其值. bindValue立即获取一个.

Use bindValue instead of bindParam. bindParam takes a reference to a variable and only reads its value when executing the query. bindValue takes a value immediately.

这篇关于所有列均设置为相同的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆