Board index   FAQ   Search  
Register  Login
Board index php forum :: Database Other Database Engines

addslashes and mssql

Do you have questions regarding other database enginges (not MySQL) -- ask here!

Moderators: macek, egami, gesf

addslashes and mssql

Postby nickk » Wed May 04, 2005 1:14 pm

try the following 2 sql queries and you will see what I mean:

Code: Select all
$where = "users'";
$where = addslashes($where);
$sqlMY = "select * from $where";

$where = "orders'";
$where = addslashes($where);
$sqlMS = "select * from $where";


now, the addslashes prevents the ' from causing errors in the mysql statement,. but the / returns an error in the mssql query. How does one get aroudnt his in mssql?
nickk
New php-forum User
New php-forum User
 
Posts: 36
Joined: Sat Nov 29, 2003 6:57 am

Postby Alexej Kubarev » Wed May 04, 2005 1:27 pm

moved to Other databases forum

Reply: try addcslashes()

it will add backslashes instead
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby nickk » Thu May 05, 2005 3:53 pm

I guess a quick google search would have helped me before posting here.
Apparently (unsurprisingly) mssql doesnt support slashes, only solution I could find was the following:

please note that addslashes will NOT work with mssql, since mssql does not use the backslash character as an escape mechanism. just double your quotes instead. or use this:

Code: Select all
<?php
function mssql_addslashes($data) {
   $data = str_replace("'", "''", $data);
   return $data;
}
?>

[/code][/quote]
nickk
New php-forum User
New php-forum User
 
Posts: 36
Joined: Sat Nov 29, 2003 6:57 am

Postby ruturajv » Thu May 12, 2005 8:11 pm

hey!!!
what a co-incidience
I've developed same mssql_addslashes
but my version is
Code: Select all
<?php
function mssql_addslashes($data) {
   $data = str_replace('\'', '\'\'', $data);
   return $data;
}
?>

And this one works like a smooth ride
User avatar
ruturajv
php-forum Super User
php-forum Super User
 
Posts: 1280
Joined: Sat Mar 22, 2003 9:42 am
Location: Mumbai, India


Return to Other Database Engines

Who is online

Users browsing this forum: No registered users and 0 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron