带有许多变量的Prepared语句与参数数量不匹配

时间:2014-06-18 14:24:13

标签: php mysql sql mysqli prepared-statement

虽然我多次检查参数,但我仍然得到了例外。我该如何清理这个混乱并解决错误?

mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement

这是我的代码,基本上它不是那么多代码 - 但是 33个变量/参数。它使用INSERT语句以相同的方式工作:

public function update($assetId, $genericAssetId, $umdns, $assetFullName, $manufacturerId, $model, $serialNumber,
                            $internaliventoryNumber, $locationId, $responsiblePers, $assetStatusId, $assetUtilizationId, $purchaseDate,
                            $installationDate, $lifeTime, $purchasePrice, $currentValue, $warrantyContractId, $agentId, $warrantyContractExp,
                            $warrantyContractNotes, $employeeId, $supplierId, $donorId, $serviceManual, $notes, $picture, $lastmodified,
                            $by_user, $URL_Manual, $metrologyDocument, $metrologyDate, $metrology)
{

    $sql = "UPDATE assets SET GenericAssetID = '$genericAssetId', UMDNS = '$umdns', AssetFullName = '$assetFullName',
     ManufacturerID = '$manufacturerId', Model = '$model', SerialNumber = '$serialNumber',
      InternalIventoryNumber = '$internaliventoryNumber', LocationID = '$locationId',
       ResponsiblePers = '$responsiblePers', AssetStatusID = '$assetStatusId',
       AssetUtilizationID = '$assetUtilizationId', PurchaseDate = '$purchaseDate',
        InstallationDate = '$installationDate', Lifetime = '$lifeTime', PurchasePrice = '$purchasePrice',
         CurrentValue = '$currentValue', WarrantyContractID = '$warrantyContractId', AgentID = '$agentId',
          WarrantyContractExp = '$warrantyContractExp', WarrantyContractNotes = '$warrantyContractNotes',
           EmployeeID = '$employeeId', SupplierID = '$supplierId', DonorID = '$donorId',
            ServiceManual = '$serviceManual', Notes = '$notes', Picture = '$picture', lastmodified = '$lastmodified',
             by_user = '$by_user', URL_Manual = '$URL_Manual', MetrologyDocument = '$metrologyDocument',
              MetrologyDate = '$metrologyDate', Metrology = '$metrology' WHERE AssetID = '$assetId'";

    if ($stmt = $this->db->prepare($sql)) {
        $stmt->bind_param("siisssssssiissiddisssssssssssssss", $assetId, $genericAssetId, $umdns, $assetFullName,
            $manufacturerId, $model, $serialNumber, $internaliventoryNumber, $locationId, $responsiblePers,
            $assetStatusId, $assetUtilizationId, $purchaseDate, $installationDate, $lifeTime, $purchasePrice,
            $currentValue, $warrantyContractId, $agentId, $warrantyContractExp, $warrantyContractNotes, $employeeId,
            $supplierId, $donorId, $serviceManual, $notes, $picture, $lastmodified, $by_user, $URL_Manual,
            $metrologyDocument, $metrologyDate, $metrology);
    }
    $stmt->execute();
    $num_affected_rows = $stmt->affected_rows;
    $stmt->close();
    return $num_affected_rows > 0;
}

1 个答案:

答案 0 :(得分:3)

你有绑定。您将变量放在查询中而不是绑定运算符?

$sql = "UPDATE assets SET GenericAssetID = ?, UMDNS = ?, 

等...