検索
ホームページphp教程php手册PHP 操作クラスを SQL Ralay データベース接続プールに変換する

数据|数据库|数据库连接

原文说明:目前此类只支持Sybase,稍加扩展就可以同时支持其它多种数据库,功能还不完善,但是基本上够用
,另外,还没有写说明文档,先放上来,有需要的朋友可以拿去看看,需要SQL Relay支持哦。
【操作类代码】

 

// pdbconn.inc.php

    /**
     * 全局常量定义
     *
     */
    define("SYBASE", 0);
    define("ORACLE", 1);
    define("SUCCESS", 1);
    define("FAILED", -1);

Define("DEBUG", 1);

/**
* データベース接続クラス
* 開始日: 2006 年 1 月 10 日
* 著者: Qiu Shanke (cntoby@gmail.com)
*
* 機能説明: データベースクエリと接続プールのメンテナンス
* ORACLE は現時点ではサポートされていません
*/
class dbconn { // 現在の接続 ID
var $_cur // var $_dbhost = "localhost" ; // データベースサーバー名
var $_dbport = 9000; // データベースのポート番号
var $_dbuser = "dev" // データベースにログインするためのユーザー名
var $_dbpass = "dev";データベースへの入力
var $_dbsock = "null"; // データベース接続用の Unix ソケット var $_dbflag = SYBASE; // データベースの種類
var $_dbflagS = "sybase"; // SQLRelay のデータベースの種類のフラグ
var $ _dbrtrt = 0 ; // 接続失敗後の再試行にはどれくらいの時間がかかりますか? SQL テキスト var $_lastrt = true boolean var $_queryrs = null; Recordcount = 0; // 今回返されるレコードの総数
var $absolute = 0; // 現在のページ番号 var $pagesize = 0; // 各ページに表示されるレコードの数
var $pagecount = 1 ; // このクエリの合計レコード数
ページ数
var $total = 0; // 合計レコード数
/**
*コンストラクター、この機能の接続と接続プールの初期化 - 使用する - 使用する - ST *DBHOSTデータベースサーバー名
*DBUSER LOGINデータベースユーザー名
*DBPASSログインデータベースパスワードデータベース接続
*dbport データベース ポート番号 *dbflag データベース タイプ、オプションのタイプは Sybase または Oracle です
* *
* @return dbconn
*/
function dbconn() {
$argc = func_num_args( );
$argv = func_get_args(); $argv = >_dbhost = (!empty($argv[0]))?$argv[0]:$this->_dbhost;
            $this->_dbuser = (!empty($argv[1]))?$argv[1]:$this->_dbuser;
$this->dbpass = (!empty($argv[2]))?$argv[2]:$this->_dbpass;
$this->dbsock = (!empty($argv[3]))?$argv[3]:$this->_dbsock;
$this->dbport = (!empty($argv[4]))?$argv[4]:$this->_dbport;
$this->dbflag = (!empty($argv[5]))?$argv[5]:$this->_dbflag;
$this->dbrtrt = (!empty($argv[6]))?$argv[6]:$this->_dbrtrt;
$this->dbtries = (!empty($argv[7]))?$argv[7]:$this->_dbtries;
$this->_debug = generated("DEBUG");

switch ($this->_dbflag) {
case SYBASE:
$this->_conn = @sqlrcon_alloc($this-&g t;_dbhost、$this->_dbport、$this->_dbsock、$this ->_dbuser、$this->_dbpass、$this->_dbrtrt、$this->_dbtries);
$this->_cur = @sqlrcur_alloc($this->_conn);
if(@sqlrcon_identify($this->_conn)!="sybase"||@sqlrcon_ping($this->_conn)!=1) {
return FAILED;
}
休憩。
case ORACLE:
$this->_conn = @sqlrcon_alloc($this->_dbhost, $this->_dbport, $this->_dbsock, $this->_dbuser, _dbpass、 $this->_dbrtrt、$this->_dbtries);
$this->_cur = @sqlrcur_alloc($this->_conn);
if(substring(@sqlrcon_identify($this->_conn), 0, 6)!="oracle"||@sqlrcon_ping($this->_conn)!=1) {
return FAILED;
}
休憩。
デフォルト:
失敗を返します。
休憩。
}
}

/**
*/
function setql($sql = "") {
$this->_cursql = $sq l;
成功を返します。
}
        
/**
*/
function rset() {
$this->rs = null;
$this->pagecount = 1;
$this->recordcount = 0;
$this->_queryrs = null;
$this->_lastrt = true;

成功を返します。
}

/**
*/
function doexec($sql = "") {
$tran = false;
$isa = false;
$this->rset();
if(""==$sql||empty($sql)) {
$sql = $this->_cursql;
}
if(!is_array($sql)) {
if(!eregi("^select", トリム($sql))) {
$tran = true;
}
}else {
$isa = true; { $tran = true ;
休憩。
}
}
}
if ($tran) {
$tmp = @sqlrcur_sendQuery ($this->_cur, "トランザクションの開始");
if($tmp!=1) {
$this->_lastrt = false;
失敗を返します。
}
}
if(!$isa) {
$tmp = @sqlrcur_sendQuery($this->_cur, $sql);
}else {
                for ($i = 0; $i $tmp = @sqlrcur_sendQuery($this->_cur, $sql[$i]);
if($tmp!=1) ブレーク;
}
}
$this->setsql();
if($tmp==1) {
if($tran) @sqlrcur_sendQuery($this->_cur, "トランザクションをコミット");
$this->_lastrt = true;
}else {
if($tran) @sqlrcur_sendQuery($this->_cur, "ロールバック トランザクション");
$this->lastrt = false;
失敗を返します。
}
成功を返します。
}

/**
*/
function doquery_row() {
$this->rset();
if((""==trim($this->_cursql))||empty($this->_cursql)) {
falseを返します。
}
if(SYBASE==$this->_dbflag) {
@sqlrcur_sendQuery($this->_cur, "set rowcount 1");
$tmp = @sqlrcur_sendQuery($this->_cur, $this->_cursql);
if($tmp==1) {
$this->recordcount = @sqlrcur_rowCount($this->_cur);
$this->total = $this->recordcount;
if ($this->recordcount>0) {
$this->rs = @sqlrcur_getRow($this->_cur, 0);
}
}else {
$this->recordcount = -1;
$this->total = $this->recordcount;
@sqlrcur_sendQuery($this->_cur, "set rowcount 0");
失敗を返します。
}
                @sqlrcur_sendQuery($this->_cur, "行数 0 を設定");
}elseif(ORACLE==$this->_dbflag) {
// 暂時不サポート
$sfmt = @ociparse($this->_conn, $this->_ cursql);
$ret = @ociexecute($sfmt, OCI_DEFAULT);
if($ret) {
$this->recordcount = @oci_num_rows($sfmt);
$this->total = $this->recordcount;
if($this->recordcount>0) {
@ocifetchinto($sfmt, &$this->rs);
}
}else {
$this->recordcount = -1;
$this->total = $this->recordcount;
失敗を返します。
}
}
$this->setsql();
成功を返します。
}

/**
*/
function doquery_rows($rowcount = 0) {
if(!eregi("[0-9]+", $rowcount)) { $rowcount = 0;
}
$this->rset();
if((""==trim($this->_cursql))||empty($this->_cursql)) {
失敗を返します。
}
if(SYBASE==$this->_dbflag) {
@sqlrcur_sendQuery($this->_cur, "set rowcount " .strval($rowcount));
$tmp = @sqlrcur_sendQuery($this->_cur, $this->_cursql);
if($tmp==1) {
$this->recordcount = @sqlrcur_rowCount($this->_cur);
$this->total = $this->recordcount;
if($this->レコード数 > 0) {
                        if(0>=$this->pagesize||null==$this->pagesize) {
$this->pagecount = 1;
$startidx = 0;
$endidx = $this->recordcount - 1;
}else {
if($this->absoluteabsolute=1;
$this->pagecount = ceil($this->gt;recordcount/$this->pagesize);
if($this->absolute>gt;$this->pagecount) $this->absolute = $this->pagecount;
$startidx = $this->pagesize * ($this->absolute-1);
$endidx = $this->pagesize * $this->absolute -1;
}
$rcidx = 0;
// 以下保存結果to$this->rc
for($i = $startidx; $i total; $i++) { if($rowcount!= 0&&$rowcount==$i) ブレーク;
$this->rs[$rcidx++] = @sqlrcur_getRow($this->_cur, $i);
}
$this->recordcount = $rcidx;
}
}else {
$this->recordcount = -1;
$this->total = $this->recordcount;
@sqlrcur_sendQuery($this->_cur, "set rowcount 0");
失敗を返します。
}
@sqlrcur_sendQuery($this->_cur, "set rowcount 0");
}elseif(ORACLE==$this->_dbflag) {
                // 暂時不サポートORACLE
// Oracle 処理部分
$sfmt = @ociparse($this->_conn, $this->_cursql);
$ret = @ociexecute($sfmt, OCI_DEFAULT);
if($ret) {
$this->recordcount = @oci_num_rows($sfmt);
$this->total = $this->recordcount;
if($this->recordcount > 0) {
if($this->pagesizepagesize) {
{ $this->pagecount = 1;
$startidx = 0;
$endidx = $this->recordcount - 1;
}else {
if($this->absolute absolute = 1;
$this->pagecount = ceil($this->gt;recordcount/$this->pagesize);
if($this->absolute>gt;$this->pagecount) $this->absolute = $this->pagecount;
$startidx = $this->pagesize * ($this->absolute - 1);
$endidx = $this->pagesize * $this->absolute - 1;
// aaaaaaaaaaaaa
}
}else {
$this->recordcount = -1;
$this->total = $this->recordcount;
失敗を返します。
}
失敗を返します。
}
$this->setsql();
成功を返します。
}

/**
         * 关闭データ连接
*
* @return bool
*/
function dbclose() {
@sqlrcon_free($this->_conn);
@sqlrcur_free($this->_cur);
}

/**
*/
function pagesize($pagesize = 0) {
if(eregi("[1-9]+", $pagesize)&&$pagesize!=0)
$this ->ページサイズ = intval($pagesize);
return $this->pagesize;
}else {
return $this->pagesize;
}
}

/**
*/
関数absolute($absolute = 1) {
if(eregi("[1-9]+", ute)&&$absolute>1) {
$ this->absolute = intval($absolute);
return $this->absolute;
}else {
return $this->absolute;
}
}
}
?>







声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

AI Hentai Generator

AI Hentai Generator

AIヘンタイを無料で生成します。

ホットツール

DVWA

DVWA

Damn Vulnerable Web App (DVWA) は、非常に脆弱な PHP/MySQL Web アプリケーションです。その主な目的は、セキュリティ専門家が法的環境でスキルとツールをテストするのに役立ち、Web 開発者が Web アプリケーションを保護するプロセスをより深く理解できるようにし、教師/生徒が教室環境で Web アプリケーションを教え/学習できるようにすることです。安全。 DVWA の目標は、シンプルでわかりやすいインターフェイスを通じて、さまざまな難易度で最も一般的な Web 脆弱性のいくつかを実践することです。このソフトウェアは、

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

EditPlus 中国語クラック版

EditPlus 中国語クラック版

サイズが小さく、構文の強調表示、コード プロンプト機能はサポートされていません

Dreamweaver Mac版

Dreamweaver Mac版

ビジュアル Web 開発ツール

ゼンドスタジオ 13.0.1

ゼンドスタジオ 13.0.1

強力な PHP 統合開発環境