我現在用的波紋管查詢,更新,但現在我想將其更改爲PDO和它未能奏效 請任何幫助將不勝感激如何將更新查詢從mysql更改爲pdo?
function updateonlinesession(){
if(isset($_SESSION['username']['id'])){
$uid = $_SESSION['username']['id'];
$page = $_SERVER['REQUEST_URI'];
$ip = $_SERVER['REMOTE_ADDR'];
$username = $_SESSION['logged'];
mysql_query("UPDATE site_user SET dateupdated = now(),ip = '$ip' WHERE
username = '".mysql_real_escape_string($_SESSION['username'])."'");
}
}
這是我試圖與PDO
function updateonlinesession(){
if(isset($_SESSION['username']['id'])){
$uid = $_SESSION['username']['id'];
$page = $_SERVER['REQUEST_URI'];
$ip = $_SERVER['REMOTE_ADDR'];
$username = $_SESSION['logged'];
$update = ("UPDATE site_user SET dateupdated = now(),ip = '$ip' WHERE
username = '".($_SESSION['username'])."'");
$sth_update= $con->prepare($update);
$sth_update->execute();
}
}
?>
發表你試過的東西... – Eggplant 2013-02-26 15:42:35
有一個gander:http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers – Nick 2013-02-26 15:43:16
這個線程談論'sql注入',但它顯示了使用準備語句的方法,其中一個是PDO,[如何防止SQL注入在PHP?](http://stackoverflow.com/questions/60174/how-to-prevent-sql-injection-in-php) – 2013-02-26 15:43:42