I have a series of regular expressions that include escape characters that I need to store in a mysql table.
If I don't escape the backslash, it is eliminated.
I have tried escaping the backslash in PHP using mysql_real_escape_string, addslashes, str_replace, and every time the database stores a double backslash rather than a single one.
I have also tried using sed in bash to escape the backslash, but it also prints 2.
Example:
$regex = "stackoverflow\.com\/questions\/ask";
$query_text = addslashes($regex);
$query = "INSERT INTO my_table (url) VALUES ('$query_text')";
me@server:$ echo "select * from my_table" | mysql -uuser -Ddatabase -p'password'
stackoverflow\\.com\\/questions\\ask
Any ideas as to what I am doing wrong?