0
我有一個INSERT函數可以正常工作,除非我試圖用引號添加一個值。我有這塊代碼來替換單引號與兩個單打,然後插入它,但沒有任何改變。我改變了這個例子的主機和密碼。即使更換字符串,SQL也插入反斜槓
$title = str_replace("'", " '' ", $title);
//Connecting to the database
$dbh = new PDO('mysql:host=workinghost;dbname=mydatabase', $username, $password);
if (!($stmt = $dbh->prepare("INSERT INTO calendar(title, start) VALUES(:title, :start)")))
{
//echo "Prepare failed: (" . $mysql->errno . ") " . $mysql->error;
}
$stmt->bindParam(":title", $title);
$stmt->bindParam(":start", $date);
$stmt->execute();
您是否真的執行了準備好的語句?您的代碼似乎沒有這樣做。 – Palpatim
「有兩個單打」 - 你的意思是雙引號? –
不,我的意思是我將單引號改爲兩個單引號 – user2415335