简体   繁体   English

PDO无法执行更新

[英]PDO won't execute update

I'm trying to update a row in mysql using PDO to do so, i have no idea why it doesn't execute. 我试图使用PDO在mysql中更新一行,但我不知道为什么它不执行。 Everything seems to be correct, but it doesn't execute, neither does it generates any error. 一切似乎都是正确的,但是它没有执行,也没有产生任何错误。

First i get the values that i send via $.ajax 首先,我得到了我通过$.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'];


Then i create the query 然后我创建查询

 $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 = ?";

Finally when i prepare and execute the $stmt it seems as if nothing has happened, and it doesn't generate any error 最后,当我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);

I'm reporting the error by surrounding everything with a try - catch : 我正在通过try - catch包围一切来报告错误:

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

You have an extra NULL keyword which looks out of place... 您还有一个看起来不合适的NULL关键字...

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

There's also a right paren that looks invalid ... 还有一个右括号,看起来无效...

 `Pending` = 0)
              ^

For spotting these kinds of things, formatting SQL statements in a particular way (even if it is more lines) helps a lot... here's a malformed SQL statement that is equivalent to yours, it has the extraneous NULL keyword, and the unmatched closing (right) paren: 为了发现这些问题,以特殊方式格式化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 = ?

If this SQL statement is being sent to the database, the database is certainly raising an exception. 如果将此SQL语句发送到数据库,则数据库肯定会引发异常。 The more fundamental problem is that your code is either not preparing this statement, or it's not exposing a SQL exception in the way you expect it to. 更根本的问题是您的代码没有准备该语句,或者没有以您期望的方式公开SQL异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM