我正在尝试使用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 = ?";
最后当我prepare
和execute
$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());
}
答案 0 :(得分:3)
你有一个额外的NULL关键字,看起来不合适......
`DateStarted` = NOW(), NULL,
^^^^^
还有一个看起来无效的权利......
`Pending` = 0)
^
为了发现这些事情,以特定的方式格式化SQL语句(即使它是更多的行)有很大帮助...这里是一个格式错误的SQL语句,它等同于你的,它有无关的NULL关键字,以及无与伦比的结束(右)paren:
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异常。