2

我正在尝试使用事务更新 2 个不同的表。对于我的第一个查询,我收到错误“没有为准备好的语句中的参数提供数据”。我的第二个查询通过就好了。我知道错误是指传递给 $stmt->bind_param() 的变量。我已经检查,三次检查并且可以确认我传递给它的所有变量实际上都包含值。我还检查以确保传递的值由“s”或“i”正确指示。我的问题是我是否有一个语法错误会给我这个错误消息,或者是否有任何其他关于如何修复它的建议?

function updateClient($id,$first,$last,$email,$phone,$phoneCarrier,$tz,$wdh1,$wdh2,$weh1,$weh2,$goals){
global $conguest;
global $database;

$conguest->autocommit(false);  

//update the client tabel
$sql="UPDATE $database.client SET clientFirst = '?', clientLast = '?', clientEmail ='?', clientPhone =?, phoneCarrierId =?, timezoneId =?, clientHour1 ='?',clientHour2 ='?',clientHour3 ='?',clientHour4 ='?'
WHERE clientId = ?";

if($stmt = $conguest->prepare($sql)){        
    $stmt->bind_param('ssssiissssi', $first, $last, $email, $phone, $phoneCarrier, $tz, $wdh1, $wdh2, $weh1, $weh2, $id);
    $stmt->execute();        
    $clientupdate = $stmt->affected_rows;        
    $stmt->close();
}   
//update the goals table
$sql = "UPDATE $database.goal SET goalContent=?, categoryId = ?, goalDate=now() WHERE goalId = ?";

foreach ($goals as $goal) {
    if ($stmt = $conguest->prepare($sql)) {
        $stmt->bind_param('sii', $goal['goal'],$goal['cat'], $goal['id']);
        $stmt->execute();
        $i = $stmt->affected_rows;
        $stmt->close();
    }
    if($i){
        $goalupdate ++;
    }
}
//test that all updates worked
echo "$clientupdate, $goalupdate";
exit;
if($clientupdate ==1 && $goalupdate == 3){
    $conguest->commit();
    $conguest->autocommit(true);
    return 1;
}else{
    $conguest->rollback();
    $conguest->autocommit(true);
    return 0;
}    

}

4

1 回答 1

1

删除占位符周围的单引号。代替

$sql="UPDATE $database.client SET clientFirst = '?', clientLast = '?', clientEmail ='?', clientPhone =?, phoneCarrierId =?, timezoneId =?, clientHour1 ='?',clientHour2 ='?',clientHour3 ='?',clientHour4 ='?' WHERE clientId = ?";

$sql="UPDATE $database.client SET clientFirst = ?, clientLast = ?, clientEmail = ?, clientPhone = ?, phoneCarrierId = ?, timezoneId = ?, clientHour1 = ?, clientHour2 = ?,clientHour3 = ?,clientHour4 = ? WHERE clientId = ?";

此外,在“where clientid”之前有一个换行符。我不知道这是否相关。

于 2012-11-24T22:53:06.470 回答