如何在sqlsrv_fetch_array循环中更新相同的SqlServer记录?

时间:2014-11-09 08:07:45

标签: php sql-server loops

这是生产代码,因此我无法选择检查错误 SqlProfile跟踪显示更新已尝试7次。

$query = "Select pkey, field1 from Table1 with (NOLOCK) where etc ....;";
$unitsrs  = sqlsrv_query($conn,$query) or die('sqlsrv error: ' . print_r( sqlsrv_errors()) );

while($unitsrow = sqlsrv_fetch_array($unitsrs)) {
    $pkey = $unitsrow['pkey'];
    $field1   = $unitsrow['field1'];

    $newvalue = 0;
    ...
    $update = "Update Table1 Set Field1 = $newvalue where pkey = '$pkey';";
    sqlsrv_query($conn, $update);

}

1 个答案:

答案 0 :(得分:0)

从更新查询中删除分号

   $update = "Update Table1 Set Field1 = $newvalue where pkey = '$pkey'";