Some time back, I inherited a project where the original coding used addslashes/stripslashes to escape/unescape text in/out of MySQL. I've continued to use that method of escaping and have only just now come across a problem with it.
To insert the original string
O'Brian says "Don't do it! 1\2\3
Addslashes does add a backslash to each backslash in the original string
INSERT INTO test VALUES ('O\'Brian says \"Don\'t do it!\" 1\\2\\3')
But on retrieval, stripslashes strips ALL the backslashes and outputs:
O'Brian says "Don't do it!" 123
I'm looking at using $mdb2->quote() going forward, which seems to be working okay in my initial tests, but anybody have any suggestions about how to fix all the hundredes of queries (which addslashes/stripslashes) in the 1.4 million lines of existing code?
Is it possible to redefine built-in functions in PHP so I could maybe intercept and redefine all calls to addslashes and stripslashes so that addslashes actually executes $mdb2->quote() and stripslashes doesn't do anything?
If so, how might I clean up all my existing data which has been written with addslashes?
To insert the original string
O'Brian says "Don't do it! 1\2\3
Addslashes does add a backslash to each backslash in the original string
INSERT INTO test VALUES ('O\'Brian says \"Don\'t do it!\" 1\\2\\3')
But on retrieval, stripslashes strips ALL the backslashes and outputs:
O'Brian says "Don't do it!" 123
I'm looking at using $mdb2->quote() going forward, which seems to be working okay in my initial tests, but anybody have any suggestions about how to fix all the hundredes of queries (which addslashes/stripslashes) in the 1.4 million lines of existing code?
Is it possible to redefine built-in functions in PHP so I could maybe intercept and redefine all calls to addslashes and stripslashes so that addslashes actually executes $mdb2->quote() and stripslashes doesn't do anything?
If so, how might I clean up all my existing data which has been written with addslashes?