Page 1 of 1

MSSQL insert statement

Posted: Fri Jul 07, 2006 11:41 am
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

Posted: Fri Jul 07, 2006 11:43 am
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).

[Solved]

Posted: Fri Jul 07, 2006 2:00 pm
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.