【php开源代码栏目提醒】:网学会员php开源代码为您提供DbPgsql.class.php参考,解决您在DbPgsql.class.php学习中工作中的难题,参考学习。
<?php
// +----------------------------------------------------------------------
// | ThinkPHP
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <
DbPgsql.class.php为[网学网-网友上传,谢谢支持]。>
// +----------------------------------------------------------------------
// $Id$
/**
+------------------------------------------------------------------------------
* Pgsql鏁版嵁搴撻┍鍔ㄧ被 鎰熻阿鍒樻牸 2007-12-29 瀹屽杽^_^
* 棣栧厛璇峰鍏ョ洰褰曚笅闈㈢殑pgsql.sql 鏂囦欢
+------------------------------------------------------------------------------
* @category Think
* @package Think
* @subpackage Db
* @author liu21st <
DbPgsql.class.php为[网学网-网友上传,谢谢支持]。>
* @version $Id$
+------------------------------------------------------------------------------
*/
Class DbPgsql extends Db{
/**
+----------------------------------------------------------
* 鏋舵瀯鍑芥暟 璇诲彇鏁版嵁搴撻厤缃俊鎭?
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param array $config 鏁版嵁搴撻厤缃暟缁?
+----------------------------------------------------------
*/
public function __construct($config=''){
if ( !extension_loaded('pgsql') ) {
throw_exception(L('_NOT_SUPPERT_').':pgsql');
}
if(!empty($config)) {
$this->config = $config;
}
}
/**
+----------------------------------------------------------
* 杩炴帴鏁版嵁搴撴柟娉?
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
public function connect($config='',$linkNum=0) {
if ( !isset($this->linkID[$linkNum]) ) {
if(empty($config)) $config = $this->config;
$conn = $this->pconnect ? 'pg_pconnect':'pg_connect';
$this->linkID[$linkNum] = $conn(
'host=' . $config['hostname'] .
' port=' . $config['hostport'] .
' dbname=' . $config['database'] .
' user=' . $config['username'] .
' password=' . $config['password']
);
if (pg_connection_status($this->linkID[$linkNum]) !== 0){
throw_exception($this->error(false));
return false;
}
$pgInfo = pg_version($this->linkID[$linkNum]);
$this->dbVersion = $pgInfo['server'];
// 鏍囪杩炴帴鎴愬姛
$this->connected = true;
//娉ㄩ攢鏁版嵁搴撳畨鍏ㄤ俊鎭?
if(1 != C('DB_DEPLOY_TYPE')) unset($this->config);
}
return $this->linkID[$linkNum];
}
/**
+----------------------------------------------------------
* 閲婃斁鏌ヨ缁撴灉
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
*/
public function free() {
@pg_free_result($this->queryID);
$this->queryID = 0;
}
/**
+----------------------------------------------------------
* 鎵ц鏌ヨ 涓昏閽堝 SELECT, SHOW 绛夋寚浠?
* 杩斿洖鏁版嵁闆?
+----------------------------------------------------------
* @access protected
+----------------------------------------------------------
* @param string $str sql鎸囦护
+----------------------------------------------------------
* @return ArrayObject
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
protected function _query($str='') {
$this->initConnect(false);
if ( !$this->_linkID ) return false;
if ( $str != '' ) $this->queryStr = $str;
if (!$this->autoCommit && $this->isMainIps($this->queryStr)) {
$this->startTrans();
}else {
//閲婃斁鍓嶆鐨勬煡璇㈢粨鏋?
if ( $this->queryID ) { $this->free(); }
}
$this->queryTimes ++;
$this->Q(1);
$this->queryID = pg_query($this->_linkID,$this->queryStr );
$this->debug();
if ( !$this->queryID ) {
throw_exception($this->error());
return false;
} else {
$this->numRows = pg_num_rows($this->queryID);
//$this->numCols = pg_num_fields($this->queryID);
$this->resultSet = $this->getAll();
return $this->resultSet;
}
}
/**
+----------------------------------------------------------
* 鎵ц璇彞 閽堝 INSERT, UPDATE 浠ュ強DELETE
+----------------------------------------------------------
* @access protected
+----------------------------------------------------------
* @param string $str sql鎸囦护
+----------------------------------------------------------
* @return integer
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
protected function _execute($str='') {
$this->initConnect(true);
if ( !$this->_linkID ) return false;
if ( $str != '' ) $this->queryStr = $str;
if (!$this->autoCommit && $this->isMainIps($this->queryStr)) {
$this->startTrans();
}else {
//閲婃斁鍓嶆鐨勬煡璇㈢粨鏋?
if ( $this->queryID ) { $this->free(); }
}
$this->writeTimes ++;
$this->W(1);
$this->debug();
$tableName = '';
if(substr($this->queryStr,0,6)=="INSERT"){
$tableName=explode(" ",$this->queryStr);
$tableName=";select last_value from {$tableName[2]}_id_seq;";
}
$result = pg_query($this->_linkID,$this->queryStr.$tableName);
$this->debug();
if ( false === $result ) {
//throw_exception($this->error());
return false;
} else {
$this->numRows = pg_affected_rows($result);
if($tableName!=""){
$result=pg_fetch_array($result);
$this->lastInsID =$result[0];
}
return $this->numRows;
}
}
/**
+----------------------------------------------------------
* 鍚姩浜嬪姟
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @return void
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
public function startTrans() {
//鏁版嵁rollback 鏀寔
if ($this->transTimes == 0) {
pg_exec($this->_linkID,'begin;');
}
$this->transTimes++;
return ;
}
/**
+----------------------------------
上一篇:
DbPdo.class.php
下一篇:
法律专业开题报告范文