0

我正在尝试使用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 = ?";

最后,当 iprepareexecutethe$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());
}
4

1 回答 1

3

你有一个额外的 NULL 关键字,看起来不合适......

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

还有一个看起来无效的右括号...

 `Pending` = 0)
              ^

为了发现这类事情,以特定方式格式化 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 异常。

于 2012-08-09T18:44:36.143 回答