由于某种原因,我无法将 VAR 传递给 PDO SQL 查询。
<?php
$hostname = "host";
$username = "username";
$password = "pass";
$score = "B" ;
try {
$dbh = new PDO("mysql:host=$hostname;dbname='DBNAME'", $username, $password);
echo "Connected to database"; // check for connection
$dbh->exec("UPDATE Quiz1 SET '$score' = 1 WHERE Question = 1"); // THIS DOES NOT
//$dbh->exec("UPDATE Quiz1 SET B = 1 WHERE Question = 1"); // THIS WORKS
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>