1
如何在SQL select語句中轉義字段中的特殊字符。在Select語句中轉義特殊字符SQL PHP
我有那個sql select語句和列account_name具有包含特殊字符的值,它給我錯誤,因爲它不會轉義那些特殊字符。
select * from account where account_name ='$account_name'
如何在SQL select語句中轉義字段中的特殊字符。在Select語句中轉義特殊字符SQL PHP
我有那個sql select語句和列account_name具有包含特殊字符的值,它給我錯誤,因爲它不會轉義那些特殊字符。
select * from account where account_name ='$account_name'
不要使用任何MySQL擴展命令,它們已經過時並且不再被推薦。
使用PDO並準備了處理。
$name = '$somethingHere';
$stmt = $db->prepare("Select * from account where account_name = :name");
$stmt->bindValue(':name', $name, PDO::PARAM_STR);
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
使用mysql_real_escape_string($account_name)
功能。
使用準備無論是在'PDO'或'mysqli'語句。 – moonwave99 2013-02-21 13:19:02