Index: mssql.php =================================================================== RCS file: /repository/pear/DB/DB/mssql.php,v retrieving revision 1.19 diff -u -r1.19 mssql.php --- mssql.php 5 Dec 2003 22:00:14 -0000 1.19 +++ mssql.php 10 Dec 2003 22:49:50 -0000 @@ -203,6 +203,38 @@ } // }}} + // {{{ quote() + + /** + * Quote the given string so it can be safely used in a query. + * + * @param $str mixed data to be quoted + * + * @return mixed Submitted variable's type = returned value: + * + null = the string NULL + * + boolean = 1 if true or + * 0 if false. Use the BIT + * data type because MS SQL doesn't have BOOLEAN. + * + integer or double = the unquoted number + * + other (including strings and numeric strings) = + * the data with single quotes escaped by preceeding + * single quotes then the whole string is encapsulated + * between single quotes + */ + function quote($str = null) + { + if (is_int($str) || is_double($str)) { + return $str; + } elseif (is_bool($str)) { + return $str ? 1 : 0; + } elseif (is_null($str)) { + return 'NULL'; + } else { + return "'" . str_replace("'", "''", $str) . "'"; + } + } + + // }}} // {{{ numCols() function numCols($result)