【问题标题】:Mass update using pdo not running使用 pdo 的大规模更新未运行
【发布时间】:2014-10-21 20:21:19
【问题描述】:

这是我的代码

$actor=$_SESSION['ID'];

         $code= $_SESSION['order_code'];
        $quantity_invoiced=  $_POST['invoice'];
        $price=  $_POST['price'];
        $charge=  $_POST['tax'];

          $total_items= $_POST['count'];
     $account=  $_POST['account'];

 //first step update order table
             for($y=0;$y<$total_items;$y++){




                echo  $price1 = round($price[$y]);
                echo  $quantity_invoiced1 =  $quantity_invoiced[$y];

                echo $charge1 = round($charge[$y]);

                print_r( $insert_query="update tbl_order SET GENERAL_LEDGER='{$account}',RECEIVED='1',INVOICED_PRICE='{$price1}',QUANTITY_INVOICED='{$quantity_invoiced1}',CHARGES='{$charge1}',TOTAL_COST='{$price1}*{$quantity_invoiced1}' WHERE ORDER_CODE='{$code}' AND ACTOR='{$actor}'");
                 $stmt = $con->prepare( $insert_query );

                 $stmt->execute() ;
             }

【问题讨论】:

  • “不运行”是什么意思?
  • 请查询不更新表
  • 您是否遇到任何错误?我没有看到任何错误检查。
  • 没有。我注意到不是数组的字段已更新,但数组的字段未能更新
  • 您要在列中插入一个数组?

标签: php mysql pdo


【解决方案1】:

这不是您准备查询的方式,请调整为:

//params
session_start();
$actor=$_SESSION['ID'];
$code= $_SESSION['order_code'];
$quantity_invoiced=  $_POST['invoice'];
$price=  $_POST['price'];
$charge=  $_POST['tax'];
$total_items= $_POST['count'];
$account=  $_POST['account'];


if(!$con){
    echo 'conn failed';
    die(print_r($con->errorInfo()));
}

$insert_query="
      UPDATE tbl_order 
      SET GENERAL_LEDGER = ?,
          RECEIVED='1',
          INVOICED_PRICE = ?,
          QUANTITY_INVOICED = ?,
          CHARGES=?,
          TOTAL_COST=?,
       WHERE ORDER_CODE=? AND ACTOR= ?");
if($stmt = $con->prepare($insert_query){
    for($y=0;$y<$total_items;$y++){

    //other params
    $price1 = round($price[$y]);
    $quantity_invoiced1 =  $quantity_invoiced[$y];
    $charge1 = round($charge[$y]);
    $total_cost = $price1 * $quantity_invoiced1;

        $params = array($account,
                        $price1, 
                        $quantity_invoiced1,
                        $charge1,
                        $total_cost, 
                        $code,
                        $actor)
         var_dump($params);//use this to see
            if($stmt->execute($params)){
                if($stmt->rowCount() > 0){
                    echo 'update successful';
                }else{
                    echo 'did not affect any rows';
                }
            }else{
                echo 'execute failed';
                die(print_r($con->errorInfo()));
            }
    }
}else{
    echo 'prepare failed';
    die(print_r($con->errorInfo()));
}

【讨论】:

  • @PaaKojoGad 刷新我的帖子,下次显示完整代码,因为这很浪费时间
  • 请准备语句工作但执行失败
  • die(print_r($con-&gt;errorInfo())); 应该给你一个错误
猜你喜欢
  • 1970-01-01
  • 2013-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多