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 ...
随机推荐
- Apache RewriteRule QSA 什么意思
看到下面这段代码: RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.+)$ index.php?url=$1 [QSA,L] The Rewrit ...
- 【剑指offer】面试题34:丑数
题目: 把只包含因子2.3和5的数称作丑数(Ugly Number).例如6.8都是丑数,但14不是,因为它包含因子7. 习惯上我们把1当做是第一个丑数.求按从小到大的顺序的第N个丑数. 思路: 第一 ...
- Sqrt(x) 解答
Question Implement int sqrt(int x). Compute and return the square root of x. Solution 1 -- O(log n) ...
- 《Algorithms 4th Edition》读书笔记——2.4 优先队列(priority queue)-Ⅴ
命题Q.对于一个含有N个元素的基于堆叠优先队列,插入元素操作只需要不超过(lgN + 1)次比较,删除最大元素的操作需要不超过2lgN次比较. 证明.由命题P可知,两种操作都需要在根节点和堆底之间移动 ...
- Oracle判断语句集合(转载)
SELECT decode(sign(to_date('2008-05-01', 'yyyy-MM-dd') - to_date('2008-03-01', 'yy ...
- 《Java程序员面试笔试宝典》之Java变量命名有哪些规则
在Java语言中,变量名.函数名.数组名统称为标识符,Java语言规定标识符只能由字母(a~z,A~Z).数字(0~9).下划线(_)和$组成,并且标识符的第一个字符必须是字母.下划线或$.此外,标识 ...
- jquery 弹出框 showDialog.js具体用法
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAABWwAAAImCAIAAABID1T7AAAgAElEQVR4nO3d329c52Hgff1HvPCNLw
- iTunes 重新提交代码步骤
1.选择View Details 2.右侧Links-Binary Details选项 3.Reject This Binary
- 45 个非常有用的 Oracle 查询语句(转)
这里我们介绍的是 40+ 个非常有用的 Oracle 查询语句,主要涵盖了日期操作,获取服务器信息,获取执行状态,计算数据库大小等等方面的查询.这些是所有 Oracle 开发者都必备的技能,所以快快收 ...
- Android系统默认Home应用程序(Launcher)的启动过程源代码分析
在前面一篇文章中,我们分析了Android系统在启动时安装应用程序的过程,这些应用程序安装好之后,还需要有一个 Home应用程序来负责把它们在桌面上展示出来,在Android系统中,这个默认的Home ...