zend框架实现支持sql server的操作方法
本篇章节讲解zend框架实现支持sql server的操作方法。分享给大家供大家参考,具体如下: 1.修改Zend/Db/Adapter/Pdo/Abstract.php中的connect方法 _connection) {
return;
}
// get the dsn first,because some adapters alter the $_pdoType
$dsn = $this->_dsn();
// check for PDO extension
if (!extension_loaded('pdo')) {
/**
* [url=home.php?mod=space&uid=86763]@see[/url] Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception('The PDO extension is required for this adapter but the extension is not loaded');
}
// check the PDO driver is available
if (!in_array($this->_pdoType,PDO::getAvailableDrivers())) {
/**
* @see Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception('The ' . $this->_pdoType . ' driver is not currently installed');
}
// create PDO connection
$q = $this->_profiler->queryStart('connect',Zend_Db_Profiler::CONNECT);
// add the persistence flag if we find it in our config array
if (isset($this->_config['persistent']) && ($this->_config['persistent'] == true)) {
$this->_config['driver_options'][PDO::ATTR_PERSISTENT] = true;
}
try {
//print_r($this->_config);exit;
if($this->_config['pdoType']=='sqlsrv'){
$this->_connection = new PDO( "sqlsrv:Server=".$this->_config['host'].";Database = ".$this->_config['dbname'],$this->_config['username'],$this->_config['password']);
$this->_connection->setAttribute( PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION );
$this->_connection->setAttribute( PDO::SQLSRV_ATTR_ENCODING,PDO::SQLSRV_ENCODING_UTF8 );
$this->_profiler->queryEnd($q);
}elseif ($this->_config['pdoType']=='dblib') {
$this->_connection = new PDO(
$dsn,$this->_config['password'],$this->_config['driver_options']
);
$this->_profiler->queryEnd($q);
}
// set the PDO connection to perform case-folding on array keys,or not
$this->_connection->setAttribute(PDO::ATTR_CASE,$this->_caseFolding);
// always use exceptions.
$this->_connection->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
/**
* @see Zend_Db_Adapter_Exception
*/
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception($e->getMessage());
}
}
这里针对linux和windows提供两种连接方式。 2.mssql.php 中的为
3.ZF 的web.xml 数据库配置文件改成: 期间遇到中文乱码问题 针对不同的类型,进行不同的处理。 更多关于zend相关内容感兴趣的读者可查看本站专题:《》、《》、《》、《》、《》、《》及《》 希望本文所述对大家基于Zend Framework框架的PHP程序设计有所帮助。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |