SQL Update table (Azure with PHP)


SQL Update table (Azure with PHP)

不知怎么的,我一定在某个地方犯了错误,似乎找不到正确的解决方案,一定是做错了什么。我想更新我的Azure SQL表名为名人从PHP页面,它不更新。你能帮帮我或者告诉我我做错了什么吗?

<?php 
 try {
$conn = new PDO( "sqlsrv:Server= $host ; Database = $db ", $user, $pwd);
$conn->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
}
catch(Exception $e){
die(var_dump($e));
}
if(!empty($_POST)) {
try {
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$id = $_POST['id_celebrity'];
$sql_update = "UPDATE 
       Celebrity
    SET
        (FirstName, LastName)
    VALUES 
        (?,?)                      
    WHERE
       id_celebrity='$id'";
$stmt = $conn->prepare($sql_update);
$stmt->bindValue(1, $FirstName);
$stmt->bindValue(2, $LastName);
$stmt->execute();
}
catch(Exception $e) {
die(var_dump($e));
}
echo "Celebrity Updated in DB!";
}
?>

下面是使用说明,这是我从AZURE服务器得到的结果:

object(PDOException)#3 (8) { ["message":protected]=> string(97) "SQLSTATE[42000]: [Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near '('." ["string":"Exception":private]=> string(0) "" ["code":protected]=> string(5) "42000" ["file":protected]=> string(62) "D:'home'site'wwwroot'CelebrityOverview'CelebrityEditResult.php" ["line":protected]=> int(57) ["trace":"Exception":private]=> array(1) { [0]=> array(6) { ["file"]=> string(62) "D:'home'site'wwwroot'CelebrityOverview'CelebrityEditResult.php" ["line"]=> int(57) ["function"]=> string(7) "execute" ["class"]=> string(12) "PDOStatement" ["type"]=> string(2) "->" ["args"]=> array(0) { } } } ["previous":"Exception":private]=> NULL ["errorInfo"]=> array(3) { [0]=> string(5) "42000" [1]=> int(102) [2]=> string(80) "[Microsoft][SQL Server Native Client 11.0][SQL Server]Incorrect syntax near '('." } }

试试这个:

$sql_update = "UPDATE Celebrity
SET FirstName = ?, LastName = ?             
WHERE id_celebrity='$id'";

给每一列赋一个值,中间用逗号隔开,UPDATE标记与INSERT不同。