我在更新嵌套foreach循环中的数据数组时遇到问题。我在so上读过很多类似的问题,但没有使用嵌套foreach(请参阅我的数组模式),答案似乎是在值上使用“by reference”操作符&,但这对我不起作用。我也尝试过在外循环var上使用'by ref'操作符,因为它看起来有点逻辑,但没有用。下面是我的代码和数组转储:
输入数组架构:
array (
0 =>
array (
'ReviewDate' => '2016-05-08 00:00:00',
'ReviewDetails' => 'Release pending',
'RentAmount' => '112000.00',
'ReviewComplete' => 1,
),
1 =>
array (
'ReviewDate' => '2022-10-25 00:00:00',
'ReviewDetails' => 'Short-hold still open',
'RentAmount' => '21000.00',
'ReviewComplete' => 0,
),
)
这是我准备好的声明:
'UPDATE rentals SET `ReviewDate`=:ReviewDate, `ReviewDetails`=:ReviewDetails, `RentAmount`=:RentAmount, `ReviewComplete`=:ReviewComplete WHERE agreemID=14'
我的代码是:
try
{
$cnx->beginTransaction();
$stmt = $dbconx->prepare( $QryStr );
foreach ( $formArr as $tbl => $rec )
{
foreach ( $rec as $key => &$val ) {
$stmt->bindParam( $key, $val );
}
}
$stmt->execute();
$cnx->commit();
return $stmt->rowCount();
}
catch ( PDOException $e )
{
$cnx->rollBack();
$this->applog->logerr( __FUNCTION__ ." - ".$e->getMessage() );
return false;
}
db表更新如下-如您所见,记录被final语句覆盖:
array (
0 =>
array (
'ReviewDate' => '2022-10-25 00:00:00',
'ReviewDetails' => 'Short-hold still open',
'RentAmount' => '21000.00',
'ReviewComplete' => 0,
),
1 =>
array (
'ReviewDate' => '2022-10-25 00:00:00',
'ReviewDetails' => 'Short-hold still open',
'RentAmount' => '21000.00',
'ReviewComplete' => 0,
),
)
这正是我在使用'&'by reference char之前得到的结果-但它对我不起作用,而且我的日志文件中没有任何错误。我的连接很好,因为我在其他地方都使用它。我必须把每一个装订分开写吗?我尽量避免这样做,因为我有30多个类似的表要更新。谢谢你的帮助
暂无答案!
目前还没有任何答案,快来回答吧!