我有一个可以正常工作的 INSERT 函数,除非我尝试添加带引号的值。我有这段代码用两个单引号替换单引号,然后插入它,但没有任何改变。我更改了此示例的主机和密码。
$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();