Page 1 of 1

mssql real escape string equivilent?

Posted: Fri Dec 30, 2005 6:18 pm
by dallasx
Is there an mssql function that is equivilent to the mysql_real_escape_string function? If not, how would you write one?

Posted: Fri Dec 30, 2005 6:49 pm
by josh
prepend backslashes to the following characters
(using regex)

Code: Select all

\x00, \n, \r, \, ', " and \x1a.
may I ask why you can't just use mysql_real_escape_string() ?

Posted: Fri Dec 30, 2005 6:56 pm
by dallasx
jshpro2 wrote:prepend backslashes to the following characters
(using regex)

Code: Select all

\x00, \n, \r, \, ', " and \x1a.
may I ask why you can't just use mysql_real_escape_string() ?
My database is SQL Server 2000. Or can I use mysql functions against a SQL Server? I never thought about it but I assume not.

Posted: Fri Dec 30, 2005 8:39 pm
by Chris Corbyn
It's all just SQL (with differences of course). The syntax should still follow the same rules so I guess the MySQL functions will work for things like escaping.

Posted: Sat Dec 31, 2005 3:05 am
by Jenk
mysql_real_escape_string fails if no vaild MySQL connection can be found, or if there are no default connection parameters in php.ini.

i.e. make a regex that escapes the char's mentioned by jshpro2, with one exception - the escape char in MSSQL is ', not \.