zend支持sql server
1.修改Zend下Db下Adapter下Pdo下Abstract.php中的connect方法
protected function _connect()
{
// if we already have a PDO object, no need to re-connect.
if ($this->_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['username'],
$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 中的为 protected $_pdoType = 'sqlsrv';
protected function _dsn()
{
// baseline of DSN parts
$dsn = $this->_config; // don't pass the username and password in the DSN
unset($dsn['username']);
unset($dsn['password']);
unset($dsn['driver_options']); if (isset($dsn['port'])) {
$seperator = ':';
if (strtoupper(substr(PHP_OS, , )) === 'WIN') {
$seperator = ',';
}
$dsn['host'] .= $seperator . $dsn['port'];
unset($dsn['port']);
} // this driver supports multiple DSN prefixes
// @see http://www.php.net/manual/en/ref.pdo-dblib.connection.php
//print_r($dsn);exit; if (isset($dsn['pdoType'])) {
switch (strtolower($dsn['pdoType'])) {
case 'freetds':
case 'sybase':
$this->_pdoType = 'sybase';
break;
case 'mssql':
$this->_pdoType = 'mssql';
break;
case 'sqlsrv':
$this->_pdoType = 'sqlsrv';
break;
case 'dblib':
default:
$this->_pdoType = 'dblib';
break;
}
unset($dsn['pdoType']);
} // use all remaining parts in the DSN
foreach ($dsn as $key => $val) {
$dsn[$key] = "$key=$val";
} $dsn = $this->_pdoType . ':' . implode(';', $dsn);
// print_r($dsn);exit;
return $dsn;
}
3.ZF 的web.xml 数据库配置文件改成:
<db>
<adapter>PDO_MSSQL</adapter>
<config>
<host>localhost</host>
<username>sa</username>
<password></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支持sql server的更多相关文章
- 功能齐全、效率一流的免费开源数据库导入导出工具(c#开发,支持SQL server、SQLite、ACCESS三种数据库),每月借此处理数据5G以上
		
软件名:DataPie 功能:支持SQL server.SQLite.ACCESS数据库的导入.导出.存储过程调用,支持EXCEL2007.EXCEL2003.ACCESS2007. CSV文件导入数 ...
 - Linux + .net core 开发升讯威在线客服系统:同时支持 SQL Server 和 MySQL 的实现方法
		
前段时间我发表了一系列文章,开始介绍基于 .net core 的在线客服系统开发过程. 有很多朋友一直提出希望能够支持 MySQL 数据库,考虑到已经有朋友在用 SQL Server,我在升级的过程中 ...
 - Linux 运行升讯威在线客服系统:同时支持 SQL Server 和 MySQL 的实现方法
		
前段时间我发表了一系列文章,开始介绍基于 .net core 的在线客服系统开发过程. 有很多朋友一直提出希望能够支持 MySQL 数据库,考虑到已经有朋友在用 SQL Server,我在升级的过程中 ...
 - SQLSERVER 免费对比数据库结构和数据的工具支持:SQL Server 2012, SQL Server 2008 and SQL Server 2005
		
New xSQL Schema Compare - version 5 Compare the schemas of two SQL Server databases, review differen ...
 - 支持SQL Server数据库又支持MongoDB数据库的数据访问设计
		
网站整体架构建议采用工厂模式 分别包括:数据访问层DAL,数据访问接口层IDAL,工厂层DALFactory,业务逻辑层,显示层这样的架构方式 在WebConfig配置采用何种数据库的数据访问层 &l ...
 - 让wampserver2.5.exe支持sql server数据库的方法
		
将D:\wamp\bin\php\php5.5.12\ext路径下 这两个文件复制到php.ini中 链接数据库方法 <?php $serverName = "."; $co ...
 - Linq to SQL只支持SQL Server(所选对象使用不支持的数据提供程序)
 - 让PDF.NET支持不同版本的SQL Server Compact数据库
		
最近项目中需要用到嵌入式数据库,我们选用的数据开发框架是PDF.NET(http://www.pwmis.com/SqlMap/),之前的博文已经总结了让PDF.NET支持最新的SQLite,今天我们 ...
 - SQL Server 2000 sp2 及更低版本不受此版本的 Windows 支持
		
SQL Server 2000 sp2 及更低版本不受此版本的 Windows 支持.在安装了 SQL Server 2000 之后请应用 sp3. 出现这种现象的原因在于:Windows Serve ...
 
随机推荐
- 【转】vsftp 遇到错误 500 OOPS: vsftpd: refusing to run with writable root inside chroot()--不错
			
原文网址:http://linux.it.net.cn/e/server/ftp/2015/0227/13554.html 当我们限定了用户不能跳出其主目录之后,使用该用户登录FTP时往往会遇到这个错 ...
 - Eclipse-cdt 配合 gdbserver 进行 arm 程序远程调试 上
			
做嵌入式Linux开发也不用再羡慕windows程序员VS集成开发环境的强大,我们同样能够搭建出给力的IDE. 今天在这里记录一下我使用Eclipse-cdt,gdb,gdbserver搭建远程arm ...
 - 《Two Days DIV + CSS》读书笔记——CSS选择器
			
1.1.2 CSS选择器 CSS 选择器最基本的有四种:标签选择器.ID 选择器.类选择器.通用选择器. [标签选择器] 一个完整的 HTML 页面由很多不同的标签组成,而标签选择器,则是决定哪些标签 ...
 - thinkjs与Fine Uploader的邂逅
			
最近在做一个内部系统,需要一个无刷新的上传功能,找了许久,发现了一个好用的上传工具-Fine Uploader,网上也有不少关于它的介绍,对我有不少的启发,结合我的使用场景简单的介绍一下它与t ...
 - 详述.NET里class和struct的异同
			
结构与类共享几乎所有相同的语法,但结构比类受到的限制更多:尽管结构的静态字段可以初始化,结构实例字段声明还是不能使用初始值设定项. 结构不能声明默认构造函数(没有参数的构造函数)或析构函数. 结构的副 ...
 - C++11里面的Lambda表达式
			
Lambda Expressions in C++ C++中的Lambda表达式 In Visual C++, a lambda expression—referred to as a lambda— ...
 - NYOJ17,单调递增最长子序列
			
单调递增最长子序列 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描写叙述 求一个字符串的最长递增子序列的长度 如:dabdbf最长递增子序列就是abdf.长度为4 输入 第 ...
 - ERROR 1130: Host is not allowed to connect to this MySQL server
			
解决远程连接mysql错误1130代码的方法 今天在用远程连接Mysql服务器的数据库,不管怎么弄都是连接不到,错误代码是1130,ERROR 1130: Host 192.168.2.159 is ...
 - zabbix PHP databases support off   Fail
			
zabbix初始化检查安装环境不通过: PHP databases support off Fail --未找到所支持的数据库 处理方法:安装Mysqli模块 ############## ...
 - django表单及母板
			
在之前的埔文中说到了对Model的操作以及对url的路由映射等内容,对应django的mtv框架则是完成了学习,Model与viewer的操作,那么本节主要来唠叨一下template,当Model,v ...