mssql real escape string equivilent?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dallasx
Forum Contributor
Posts: 106
Joined: Thu Oct 20, 2005 4:55 pm
Location: California

mssql real escape string equivilent?

Post by dallasx »

Is there an mssql function that is equivilent to the mysql_real_escape_string function? If not, how would you write one?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post 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() ?
User avatar
dallasx
Forum Contributor
Posts: 106
Joined: Thu Oct 20, 2005 4:55 pm
Location: California

Post 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.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post 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 \.
Post Reply