From 7c630a6246d70ac0d9af53e1cfcdf0100215cd24 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Fri, 1 Nov 2013 17:02:31 +0100 Subject: [PATCH] fixed problem with Postgres PDO and Boolean values See the following resources for details: yiisoft/yii#779 https://bugs.php.net/bug.php?id=33876 http://www.yiiframework.com/forum/index.php/topic/32334-boolean-type-with-postgresql/page__view__findpost__p__155647 --- framework/yii/db/pgsql/Schema.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/framework/yii/db/pgsql/Schema.php b/framework/yii/db/pgsql/Schema.php index 20c6fb6..bb38605 100644 --- a/framework/yii/db/pgsql/Schema.php +++ b/framework/yii/db/pgsql/Schema.php @@ -318,4 +318,24 @@ SQL; $column->phpType = $this->getColumnPhpType($column); return $column; } + + /** + * Determines the PDO type for the given PHP data value. + * @param mixed $data the data whose PDO type is to be determined + * @return integer the PDO type + * @see http://www.php.net/manual/en/pdo.constants.php + */ + public function getPdoType($data) + { + static $typeMap = [ + // php type => PDO type + 'boolean' => \PDO::PARAM_INT, // Cast boolean to integer values to work around problems with PDO casting false to string '' https://bugs.php.net/bug.php?id=33876 + 'integer' => \PDO::PARAM_INT, + 'string' => \PDO::PARAM_STR, + 'resource' => \PDO::PARAM_LOB, + 'NULL' => \PDO::PARAM_NULL, + ]; + $type = gettype($data); + return isset($typeMap[$type]) ? $typeMap[$type] : \PDO::PARAM_STR; + } }