2010-11-29 111 views
1

由於我的陳述一樣防止SQL注入與PHP

"SELECT * FROM `box` WHERE `thing` = '{$variable}' 

我能清理與單純

$variable = str_replace("'","\'",$variable); 
"SELECT * FROM `box` WHERE `thing` = '{$variable}' 

將這項工作?我的主機不支持mysql轉義,我不使用mysqli。

+0

有你爲什麼不使用mysqli的具體原因是什麼? – GolezTrol 2010-11-29 23:56:08

+0

這是確定\t靜態函數乾淨($ x)的 \t { \t \t $ X = str_replace函數( '\' '' '」,用htmlspecialchars($ x)的); \t \t回$ X; \t} – Macmee 2010-11-29 23:57:57

+0

轉到PDO - http://stackoverflow.com/questions/13569/mysqli-or-pdo-what-are-the-pros-and-cons - http://stackoverflow.com/questions/770782/moving - 從MySQL的到庫MySQLi-或-PDO – 2010-11-30 00:48:13

回答

-8

根據什麼類作爲查詢有效的數據類型,通常可以逃脫:

function cleanVar($str){ 
    $str = strip_tags(addslashes($str)); 
    return $str; 
} 
0

如果是Postgres的你可以使用pg_escape_string