所有列都设置为相同的值

imp*_*335 1 php mysql

我完全不知道我的脚本有什么问题。JSON 数据正确输入,变量 $i 和 $current 在 forloop 的每个阶段都应该是它们。

它似乎一直在用 id 更新我的数据库,所以在 id 为 11 的情况下,它将用数字 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() ;

}
Run Code Online (Sandbox Code Playgroud)

谁能看到我哪里出错了?

DCo*_*der 5

使用bindValue代替bindParambindParam获取对变量的引用,并且仅在执行查询时读取其值。bindValue需要一个马上。