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 ...
随机推荐
- 利用内存结构及多线程优化多图片下载(IOS篇)
利用内存结构及多线程优化多图片下载(IOS篇) 前言 下载地址, 后续发布, 请继续关注本blog 在IOS中,我们常常遇到多图片下载的问题.最简单的解决方案是直接利用别人写好的框架.但是这如同练武, ...
- 【HDU1325】Is It A Tree?(并查集基础题)
有以下坑点: 1.结束输入不一定-1,题目中的叙述只是说所有权值都为正值. 2.是否构成一棵树不能只判断是否只有一个根节点,没有环路,而且还需要判断每个节点的入度一定是1,不然就不是一棵树. (无环路 ...
- [Immutable.js] Exploring Sequences and Range() in Immutable.js
Understanding Immutable.js's Map() and List() structures will likely take you as far as you want to ...
- Firebase远程更新应用
能打造出色的应用不意味着一定能在商业上取得成功,两者之间还有许多工作要做,绝不能简单发布应用后就宣告“收工”.您需要能迅速根据用户反馈作出调整.测试新功能,以及向用户提供他们最关注的内容. Fireb ...
- 细讲encodeURI和encodeURIComponent以及escape的区别与应用
首先,我们都知道这三个东西都是用来编码的 先来说encodeURI()和encodeURIComponent() 这两个是在转换url时候用来编码解码用的. 有编码就会有解码, 解码就是decodeU ...
- js数组去重,并统计最多项算法
从事了一段时间的前端开发,今天写了一个数组去重,并统计最多项的方法,目前只支持数组的项都是数字. 由于本人能力有限,希望能得到网友的指正!如有问题或者更好的实现思路,也欢迎大家和我讨论!代码如下: f ...
- Java Timer触发定时器
XML: <!-- Java Timer定时 --> <!-- <bean id="shortUrlTask" class=" com.sprin ...
- GitHub+hexo to Blog
title: GitHub+hexo to Blog date: 2014-12-26 09:44:53 tags: hexo, github --- 摘要 一直想要一个自己的博客,不过一直怯于对网站 ...
- FTP之主动模式vs被动模式
背景说明 最近有个项目涉及到FTP的上传下载问题.在本地开发好的程序测试的时候能正常获取FTP内容,但一放到生产上却显示connection timeout,无法连接.经过一些研究,发现是防火墙造成的 ...
- Jquery表单与表格的运用
1,表单的应用: a. 单行文本框的应用 多行文本框的应用 b.复选框的框的应用 c.下拉框的应用 d.表单验证 2,表格的应用: a. 表格变色 b.表格展开关闭 d.表格内容筛选 3,多行文本框 ...