如何使用PHP中的预备语句从mysql更改为pdo?
问题描述:
$dml = "insert into bookmark(accountId,category,url,hash,title,created) value($_SESSION[accountId],$_POST[category],'$_POST[url]',md5('$_POST[url]'),'$_POST[title]',now())";
mysql_query($dml,$con);
如何在PDO中使用准备好的语句来执行此语句?
How do I do this statement using prepared statements in PDO?
答
$dml = "INSERT INTO bookmark (accountId, category, url, hash, title, created) "
. "VALUES (:accountId, :category, :url, MD5(:url), :title, NOW())";
$statement = $pdo->prepare($dml);
$parameters = array(
":accountId" => $_SESSION["accountId"],
":category" => $_POST["category"],
":url" => $_POST["url"],
":title" => $_POST["title"]);
$statement->execute($parameters);