note 70078 modified in function.mssql-query by danbrown

From: Date: Thu, 16 Dec 2010 14:27:32 +0000
Subject: note 70078 modified in function.mssql-query by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-174986@lists.php.net to get a copy of this message
You need to escape ' with '' in mssql, however while doing a large dataset migration I ran into an issue with \0 (NULL) in the strings breaking the query. I ended up writting the below small little function, I'm sure it could be done faster/better but it has served me well. <?php function sqlEscape($sql) { /* De MagicQuotes */ $fix_str = stripslashes($sql); $fix_str = str_replace("'","''",$sql); $fix_str = str_replace("\0","[NULL]",$fix_str); return $fix_str; } // sqlEscape ?> --was-- As noted above you need to escape ' with '' in mssql, however while doing a large dataset migration I ran into an issue with \0 (NULL) in the strings breaking the query. I ended up writting the below small little function, I'm sure it could be done faster/better but it has served me well. function sqlEscape($sql) { /* De MagicQuotes */ $fix_str = stripslashes($sql); $fix_str = str_replace("'","''",$sql); $fix_str = str_replace("\0","[NULL]",$fix_str); return $fix_str; } // sqlEscape http://php.net/manual/en/function.mssql-query.php

« previous php.notes (#174986) next »