3.2 - 致命 - 未处理
PostgreSQL在插入 “I'm prayingpanda”时,使用两个单引号对单引号进行转义,即“I''m prayingpanda”,而非“I\'m prayingpanda”然后在Pdo.class.php中,第439行:
对PGSQL进行的转义是addslashes(),这样就导致含有单引号的数据无法被插入数据库。
应该对PGSQL使用和ORACLE相同的处理,使用str_ireplace("'", "''", $str);
解决方案:
// ThinkPHP\Library\Think\Db\Driver\Pdo.class.php
public function escapeString($str) {
switch($this->dbType) {
//case 'PGSQL':
case 'MSSQL':
case 'SQLSRV':
case 'MYSQL':
return addslashes($str);
case 'PGSQL':
case 'IBASE':
case 'SQLITE':
case 'ORACLE':
case 'OCI':
return str_ireplace("'", "''", $str);
}
}我的PGSQL版本为PostgreSQL 9.3.2 on i686-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-3), 32-bit
