我有一系列正则表达式,包括我需要存储在mysql表中的转义字符。MySQL逃逸反斜杠
如果我不逃避反斜杠,它将被消除。
我已经尝试在PHP中使用mysql_real_escape_string,addslashes,str_replace转义反斜杠,并且每次数据库存储双反斜杠而不是单个反斜杠。
我也试图在bash使用sed中转义反斜线,但它也打印2.
例子:
$regex = "stackoverflow\.com\/questions\/ask";
$query_text = addslashes($regex);
$query = "INSERT INTO my_table (url) VALUES ('$query_text')";
[email protected]:$ echo "select * from my_table" | mysql -uuser -Ddatabase -p'password'
stackoverflow\\.com\\/questions\\ask
任何想法,我在做什么错误?
有用的链接 - http://stackoverflow.com/questions/4731144/the-mysql-use-of-addslashes – ajreal
**只有使用'mysql_real_escape_string'来转义在数据库中注入$ vars,永远不会组合或替换它与其他任何**或甚至更好,使用PDO。 – Johan