Zend_Db_Adapter_Pdo_Oci关于字符集设置的解决方法

默认没有提供在 Zend_Db_Adapter_Pdo 中设置 charset 的方法,使用下面的补丁可以解决这个问题:

Index: Oci.php
==========================================
— Oci.php (revision 267)
+++ Oci.php (working copy)
@@ -67,7 +67,12 @@
$tns .= ‘/’;
}
$tns .= $dsn[‘dbname’];

+
+ if (isset($dsn[‘charset’]))
+ {
+ $tns .= ‘;charset=’ . $dsn[‘charset’];
+ }
+
return $this->_pdoType . ‘:’ . $tns;
}

这样 Zend_Db::factory 方法将支持这样的设置:

<?php

require_once ‘Zend/Db.php’;

$db = Zend_Db::factory(‘Pdo_Oci’, array(
‘host’ => ‘127.0.0.1’,
‘username’ => ‘webuser’,

‘password’ => ‘xxxxxxxx’,
‘dbname’ => ‘test’,
‘charset’ => ‘utf8’
));

这个问题我已经提交到了 Zend Framework 的 Issue 中。

http://framework.zend.com/issues/browse/ZF-1541?page=all

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *