From: <var...@us...> - 2009-10-09 17:01:03
|
Revision: 7200 http://phpwiki.svn.sourceforge.net/phpwiki/?rev=7200&view=rev Author: vargenau Date: 2009-10-09 17:00:54 +0000 (Fri, 09 Oct 2009) Log Message: ----------- Use pg_escape_string in escapeSimple Modified Paths: -------------- trunk/lib/pear/DB/pgsql.php Modified: trunk/lib/pear/DB/pgsql.php =================================================================== --- trunk/lib/pear/DB/pgsql.php 2009-10-09 16:55:08 UTC (rev 7199) +++ trunk/lib/pear/DB/pgsql.php 2009-10-09 17:00:54 UTC (rev 7200) @@ -378,22 +378,35 @@ // {{{ escapeSimple() /** - * Escape a string according to the current DBMS's standards + * Escapes a string according to the current DBMS's standards * - * PostgreSQL treats a backslash as an escape character, so they are - * removed. + * {@internal PostgreSQL treats a backslash as an escape character, + * so they are escaped as well. * - * Not using pg_escape_string() yet because it requires PostgreSQL - * to be at version 7.2 or greater. - * * @param string $str the string to be escaped * * @return string the escaped string * - * @internal + * @see DB_common::quoteSmart() + * @since Method available since Release 1.6.0 */ - function escapeSimple($str) { - return str_replace("'", "''", str_replace('\\', '\\\\', $str)); + function escapeSimple($str) + { + if (function_exists('pg_escape_string')) { + /* This fixes an undocumented BC break in PHP 5.2.0 which changed + * the prototype of pg_escape_string. I'm not thrilled about having + * to sniff the PHP version, quite frankly, but it's the only way + * to deal with the problem. Revision 1.331.2.13.2.10 on + * php-src/ext/pgsql/pgsql.c (PHP_5_2 branch) is to blame, for the + * record. */ + if (version_compare(PHP_VERSION, '5.2.0', '>=')) { + return pg_escape_string($this->connection, $str); + } else { + return pg_escape_string($str); + } + } else { + return str_replace("'", "''", str_replace('\\', '\\\\', $str)); + } } // }}} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |