最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

zend框架實現(xiàn)支持sql server的操作方法

 更新時間:2016年12月08日 10:45:08   作者:牛逼的霍嘯林  
這篇文章主要介紹了zend框架實現(xiàn)支持sql server的操作方法,結合實例形式分析了zend框架的相關代碼修改、配置文件設置與相關問題注意事項,需要的朋友可以參考下

本文實例講述了zend框架實現(xiàn)支持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, 0, 3)) === '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 數(shù)據(jù)庫配置文件改成:

<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相關內(nèi)容感興趣的讀者可查看本站專題:《Zend FrameWork框架入門教程》、《php優(yōu)秀開發(fā)框架總結》、《Yii框架入門及常用技巧總結》、《ThinkPHP入門教程》、《php面向對象程序設計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家基于Zend Framework框架的PHP程序設計有所幫助。

相關文章

  • ThinkPHP框架基于PDO方式連接數(shù)據(jù)庫操作示例

    ThinkPHP框架基于PDO方式連接數(shù)據(jù)庫操作示例

    這篇文章主要介紹了ThinkPHP框架基于PDO方式連接數(shù)據(jù)庫操作,結合完整實例形式分析了thinkPHP使用PDO方式連接數(shù)據(jù)庫的相關配置、控制器及模板調(diào)用相關操作技巧,需要的朋友可以參考下
    2018-03-03
  • php面向對象中的魔術方法中文說明

    php面向對象中的魔術方法中文說明

    這篇文章主要介紹了php面向對象中的魔術方法中文說明,明白這些方法才好寫面向對象程序,需要的朋友可以參考下
    2014-03-03
  • PHP動態(tài)生成javascript文件的2個例子

    PHP動態(tài)生成javascript文件的2個例子

    這篇文章主要介紹了PHP動態(tài)生成javascript文件的2個例子,需要的朋友可以參考下
    2014-04-04
  • PHP實現(xiàn)微信提現(xiàn)功能(微信商城)

    PHP實現(xiàn)微信提現(xiàn)功能(微信商城)

    這篇文章主要介紹了PHP實現(xiàn)微信提現(xiàn)功能,此類功能在微信商城中經(jīng)常會用到,今天小編通過實例代碼給大家講解,需要的朋友可以參考下
    2019-11-11
  • php微信公眾號開發(fā)之答題連闖三關

    php微信公眾號開發(fā)之答題連闖三關

    這篇文章主要為大家詳細介紹了php微信公眾號開發(fā)之答題連闖三關,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-10-10
  • phpstorm安裝xdebug(phpstudy環(huán)境下)成功運行的操作步驟

    phpstorm安裝xdebug(phpstudy環(huán)境下)成功運行的操作步驟

    這篇文章主要介紹了phpstorm安裝xdebug(phpstudy環(huán)境下)成功運行,本文分步驟給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-09-09
  • php微信公眾平臺開發(fā)(三)訂閱事件處理

    php微信公眾平臺開發(fā)(三)訂閱事件處理

    這篇文章主要介紹了php微信公眾平臺開發(fā)中的訂閱事件處理,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2016-12-12
  • Laravel框架控制器,視圖及模型操作圖文詳解

    Laravel框架控制器,視圖及模型操作圖文詳解

    這篇文章主要介紹了Laravel框架控制器,視圖及模型操作,結合實例形式詳細分析了laravel框架控制器,視圖及模型的基本功能、原理與相關操作使用技巧,需要的朋友可以參考下
    2019-12-12
  • PHP 實現(xiàn)數(shù)組分頁

    PHP 實現(xiàn)數(shù)組分頁

    在日常開發(fā)的業(yè)務環(huán)境中,我們一般都會使用MySQL語句來實現(xiàn)分頁的功能。但是,往往也有些數(shù)據(jù)并不多,或者只是獲取 PHP 中定義的一些數(shù)組數(shù)據(jù)時需要分頁的功能。這時,我們可以在一次查詢中把所有的數(shù)據(jù)取出來,然后在 PHP 的代碼層面進行分頁功能的實現(xiàn)
    2021-06-06
  • php木馬webshell掃描器代碼

    php木馬webshell掃描器代碼

    因為前端時間服務器被放過 所以寫了個webshell掃描器 呵呵 專殺php webshell 不管大馬還是小馬 包括一句話 現(xiàn)在放出代碼來
    2012-01-01

最新評論

贵港市| 宜兰市| 漳平市| 阳春市| 永清县| 新野县| 金溪县| 电白县| 富锦市| 屏南县| 铜陵市| 雷山县| 铜川市| 铁力市| 邳州市| 锡林郭勒盟| 鹤岗市| 蛟河市| 平定县| 岳普湖县| 时尚| 武宣县| 开平市| 玉山县| 义乌市| 河间市| 宾川县| 长垣县| 新竹县| 宜兴市| 玉门市| 会同县| 夏河县| 沂源县| 开阳县| 厦门市| 巍山| 庆云县| 锦屏县| 准格尔旗| 嘉鱼县|