3.ZF 的web.xml 数据库配置文件改成:
<db>
<adapter>PDO_MSSQL</adapter>
<config>
<host>localhost</host>
<username>sa</username>
<password>123456</password>
<dbname>testdb </dbname>
<pdoType>sqlsrv</pdoType>
</config>
</db>
期间遇到中文乱码问题
function convert2utf8($string)
{
$config = $this->getCfg();
$pdoType = $config->db->config->pdoType;
if($pdoType == 'dblib'){
return iconv("gbk","utf-8",$string);
}elseif($pdoType == 'sqlsrv'){
return mb_convert_encoding($string,"UTF-8","auto");
}
}
function convert2gbk($string)
{
$config = $this->getCfg();
$pdoType = $config->db->config->pdoType;
if($pdoType == 'dblib'){
return iconv("utf-8","gbk",$string);
}elseif($pdoType == 'sqlsrv'){
return mb_convert_encoding($string,"GBK","auto");
}
}
protected function &getCfg() {
if ($this->cfg_ === null) {
$registry = Zend_Registry::getInstance();
$this->cfg_ = $registry->get('web_config');
}
return $this->cfg_;
}
针对不同的类型,进行不同的处理。
更多关于zend相关内容感兴趣的读者可查看本站专题:《Zend FrameWork框架入门教程》、《php优秀开发框架总结》、《Yii框架入门及常用技巧总结》、《ThinkPHP入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于Zend Framework框架的PHP程序设计有所帮助。







