MSSQL insert statement

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

MSSQL insert statement

Post by kingconnections »

Ok so i have an insert statement that is dynamically being generated via xml parser. The issue is that the data contains an ' in side of one of the fields. I am not sure that magic quotes will work for mssql as the \ does not escape in mssql. I could be wrong. But what are my options to resolve this issue. The insert works fine as long as the data does not have an ' in it.

Thanks

Dan
GM
Forum Contributor
Posts: 365
Joined: Wed Apr 26, 2006 4:19 am
Location: Italy

Post by GM »

Standard SQL escapes the single quote character with another single quote character.

I'm not sure if there are mssql specific PHP functions to do this (check the mssql specific PHP functions in the manual), but basically you need to change each instance of ' into '' (two single quotes).
kingconnections
Forum Contributor
Posts: 137
Joined: Thu Jul 14, 2005 4:28 pm

[Solved]

Post by kingconnections »

Just an fyi for anyone who wants to know.
You can get around data that has an ' in it by doing a str_replace and replace the ' with '' in mssql.

example:

Code: Select all

$description="$Update[Description]";
	
	$description=str_replace("'","''",$description);


Thanks for the help guys.
Post Reply