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

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

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

本文實(shí)例講述了zend框架實(shí)現(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());
  }
}

這里針對(duì)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ù)庫(kù)配置文件改成:

<db>
  <adapter>PDO_MSSQL</adapter>
<config>
    <host>localhost</host>
    <username>sa</username>
    <password>123456</password>
    <dbname>testdb </dbname>
    <pdoType>sqlsrv</pdoType>
  </config>
</db>

期間遇到中文亂碼問(wèn)題

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_;
} 

針對(duì)不同的類(lèi)型,進(jìn)行不同的處理。

更多關(guān)于zend相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《Zend FrameWork框架入門(mén)教程》、《php優(yōu)秀開(kāi)發(fā)框架總結(jié)》、《Yii框架入門(mén)及常用技巧總結(jié)》、《ThinkPHP入門(mén)教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門(mén)教程》、《php+mysql數(shù)據(jù)庫(kù)操作入門(mén)教程》及《php常見(jiàn)數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家基于Zend Framework框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

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

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

    這篇文章主要介紹了ThinkPHP框架基于PDO方式連接數(shù)據(jù)庫(kù)操作,結(jié)合完整實(shí)例形式分析了thinkPHP使用PDO方式連接數(shù)據(jù)庫(kù)的相關(guān)配置、控制器及模板調(diào)用相關(guān)操作技巧,需要的朋友可以參考下
    2018-03-03
  • php面向?qū)ο笾械哪g(shù)方法中文說(shuō)明

    php面向?qū)ο笾械哪g(shù)方法中文說(shuō)明

    這篇文章主要介紹了php面向?qū)ο笾械哪g(shù)方法中文說(shuō)明,明白這些方法才好寫(xiě)面向?qū)ο蟪绦?,需要的朋友可以參考?/div> 2014-03-03
  • PHP動(dòng)態(tài)生成javascript文件的2個(gè)例子

    PHP動(dòng)態(tài)生成javascript文件的2個(gè)例子

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

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

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

    php微信公眾號(hào)開(kāi)發(fā)之答題連闖三關(guān)

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

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

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

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

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

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

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

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

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

    php木馬webshell掃描器代碼

    因?yàn)榍岸藭r(shí)間服務(wù)器被放過(guò) 所以寫(xiě)了個(gè)webshell掃描器 呵呵 專(zhuān)殺php webshell 不管大馬還是小馬 包括一句話 現(xiàn)在放出代碼來(lái)
    2012-01-01

最新評(píng)論

江安县| 垫江县| 修武县| 嘉峪关市| 平南县| 贵港市| 云梦县| 德阳市| 祁阳县| 沂水县| 汪清县| 六安市| 利川市| 新郑市| 天台县| 湖北省| 玉山县| 崇义县| 隆子县| 大邑县| 射阳县| 吴桥县| 府谷县| 威宁| 长沙县| 兰坪| 清丰县| 密云县| 绩溪县| 台东县| 随州市| 堆龙德庆县| 雷山县| 扬州市| 团风县| 左贡县| 天祝| 安吉县| 永胜县| 中西区| 康定县|