使用php

时间:2018-08-14 10:08:47

标签: php mysql

我知道这个问题已被多次询问,但我找不到所需的解决方案。我已经设法将CSV文件上传到我的数据库并设法对其进行更新,但是我要更新的记录数是有限的,最多为90行。我尝试上传包含400条记录的记录,但无法更新此记录。在数据库中明智地使用它已消耗了180kb。

如果查询有问题,请提供指导,我们将为您提供任何帮助

  echo  $query="SELECT  bankstatement.referenceno,bankstatement.debit,bankstatement.credit,bankstatement.status,cashbook.referenceno,
            cashbook.debit,cashbook.credit,cashbook.status
                FROM   bankstatement CROSS JOIN
                             cashbook
                            where '$bank' = '$cash' and cashbook.credit = bankstatement.debit and cashbook.debit = bankstatement.credit and bankstatement.status = '0' and cashbook.status = '0' ";

     echo   $res= mysqli_query($db,$query) or trigger_error("Query Failed! SQL: $query - Error: ".mysqli_error(),E_USER_ERROR);


        if($res){
        echo $change = "update bankstatement set status='1' where referenceno in($bank)";
        echo $change1 = "update cashbook set status='1' where referenceno in($cash)";


        echo mysqli_query($db,$change);
        echo mysqli_query($db,$change1);

echo "<script>
        alert('Success in Reconciling Process!!!');
        window.location.href='viewreconcile.php';
        </script>
        ";
    }else{
        echo "<script>
        alert('Error in Reconciling Process!!!');
        window.location.href='managereconcile.php';
        </script>
        ";
    }
    }
 }
}

1 个答案:

答案 0 :(得分:0)

您可以跳过第一步,以检查是否有未设置后备帐户的后备帐户,因为您的update语句将只更新数组where中的所有内容。

我在您的更新查询中添加了where status='0'语句,以将更新限制为实际需要更新的行。

// The back account numbers to update
$bank_accounts= [000001, 0000002, 000003];
// adding fix from https://stackoverflow.com/questions/5527202/mysqli-stmtbind-paramnumber-of-elements-in-type-definition-string-doesnt-ma
$types = implode('', array_fill(0, count($bank_accounts), 's'));
$bank_accounts = array_merge([$types], $bank_accounts);

$to_prepare = [];
foreach($bank_accounts as $key => $value) {
   $to_prepare[$key] = &$bank_accounts[$key];
}

// Preparing the parameters for the prepared statement
$clause = implode(',', array_fill(0, count($bank_accounts), '?'));


// Preparing the statement
$stmt = $db->prepare("update bankstatement 
                     set status='1' 
                     where 
                        status='0' 
                     and 
                        referenceno in($clause)
                     ");

// always check whether the prepare() succeeded 
if ($stmt === false) {
  trigger_error($db->error, E_USER_ERROR);
  return;
}

// bind the bank accounts to the parameters
call_user_func_array(array($stmt, 'bind_param'), $to_prepare );

// Update all the rows
$stmt->execute();

这与现金查询的工作方式相同。