簡體   English   中英

PDO無法執行更新

[英]PDO won't execute update

我試圖使用PDO在mysql中更新一行,但我不知道為什么它不執行。 一切似乎都是正確的,但是它沒有執行,也沒有產生任何錯誤。

首先,我得到了我通過$.ajax發送的值

$idRequest = $_POST['idRequest'];
$dateStarted = $_POST['dateStarted'];
$requester = $_POST['requester'];
$quantity = $_POST['quantity'];
$qaauthorization = $_POST['qaauthorization'];
$qengineer = $_POST['qengineer'];
$performer = $_POST['performer'];
$voltage = $_POST['voltage'];
$goal = $_POST['goal'];
$measurementunit = $_POST['measurementunit'];
$account = $_POST['account'];
$centercost = $_POST['centercost'];
$ela = $_POST['ela'];
$it = $_POST['it'];
$testtype = $_POST['testtype'];
$brand = $_POST['brand'];
$model = $_POST['model'];
$part = $_POST['part'];
$objective = $_POST['objective'];
$production = $_POST['production'];
$reason = $_POST['reason'];
$specifications = $_POST['specifications'];


然后我創建查詢

 $queryRQ = "UPDATE
                request
            SET
                `idRequester` = ? , `idQEngineer` = ? , `RequestDate` = ? , `idModelNumber` = ?,`idPartDescription` = ? ,`idTestType` = ? , `ReasonForTesting` = ? ,
                `Quantity` =?,`Goal` = ?,`idMeasurementUnit` = ?, `Voltage` = ?, `AccountNumber` = ?, `CenterCost` = ?, `ELA` = ?,`ITNumber` = ?, `idPerformer` = ?, `DateStarted` = NOW(), `DateCompleted` = NULL,
                `Specifications` =?, `idObjective` = ?, `idProduction` = ?, `idBrand` = ?, `Available` = 1 , `Pending` = 0)
            WHERE
                idRequest = ?";

最后,當我prepareexecute $stmt ,好像什么也沒發生,並且不會產生任何錯誤

$reqVals = array($requester,$qengineer,$dateStarted,$model,$part,$testtype,$reason,
                    $quantity,$goal,$measurementunit,$voltage,$account,$centercost,$ela,$it,$performer,
                    $specifications,$objective,$production,$brand, /* WHERE */ $idRequest);
$stmtRQ = $pdo->prepare($queryRQ);
$stmtRQ->execute($reqVals);

我正在通過try - catch包圍一切來報告錯誤:

try{
 // EVERYTHING
} catch(PDOException $e){
    echo(json_encode($e->getMessage());
}

您還有一個看起來不合適的NULL關鍵字...

`DateStarted` = NOW(), NULL,
                       ^^^^^

還有一個右括號,看起來無效...

 `Pending` = 0)
              ^

為了發現這些問題,以特殊方式格式化SQL語句(即使行數更多)也很有幫助...這是一個與您的SQL語句等價的格式錯誤的SQL語句,它具有無關的NULL關鍵字和無與倫比的結束符(右)括號:

UPDATE request
   SET `idRequester`       = ?
     , `idQEngineer`       = ?
     , `RequestDate`       = ?
     , `idModelNumber`     = ?
     , `idPartDescription` = ?
     , `idTestType`        = ?
     , `ReasonForTesting`  = ?
     , `Quantity`          = ?
     , `Goal`              = ?
     , `idMeasurementUnit` = ?
     , `Voltage`           = ?
     , `AccountNumber`     = ?
     , `CenterCost`        = ?
     , `ELA`               = ?
     , `ITNumber`          = ?
     , `idPerformer`       = ?
     , `DateStarted`       = NOW()
     , NULL
     , `Specifications`    = ?
     , `idObjective`       = ?
     , `idProduction`      = ?
     , `idBrand`           = ?
     , `Available`         = 1
     , `Pending`           = 0
     )
 WHERE idRequest = ?

如果將此SQL語句發送到數據庫,則數據庫肯定會引發異常。 更根本的問題是您的代碼沒有准備該語句,或者沒有以您期望的方式公開SQL異常。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM