データベースクラス

  db.php (MySQL用)



  
<?
# **********************************************************
# データベースクラス
# **********************************************************
class DB {
 
	var $Connect;
	var $Result;

	var $nField;
	var $nRow;

	var $Debug;
 
# **********************************************************
# コンストラクタ
# **********************************************************
	function DB( $Server='localhost', $DbName='lightbox', $User='root', $Password='' ) {
		$this->Connect = mysql_connect( $Server, $User, $Password );
		mysql_select_db( $DbName, $this->Connect );
		$this->Debug = FALSE;
	}
 
# **********************************************************
# 接続解除
# **********************************************************
	function Close( ) {
		mysql_close( $this->Connect );
	}
 
# **********************************************************
# クエリー
# **********************************************************
	function Query( $SqlQuery ) {
		$ret = mysql_query( $SqlQuery,$this->Connect );
		if ( $this->Debug ) {
			if ( mysql_errno() != 0 ) {
				print "<B>" . mysql_error() . "</B><BR>";
			}
		}
		return $ret;
	}
 
# **********************************************************
# フェッチ
# **********************************************************
	function Fetch( $Result ) {
		return mysql_fetch_array( $Result );
	}
 
# **********************************************************
# クエリーとフェッチ
# **********************************************************
	function QueryEx( $SqlQuery='' ) {
 
		if ( $SqlQuery != '' ) {
			if ( $this->Debug ) {
				print "<TABLE border=0 cellpadding=5>";
				print "<TH bgcolor=skyblue>$SqlQuery</TD>";
				print "</TABLE>";
			}
			$this->Result = $this->Query( $SqlQuery );
			if ( !$this->Result ) {
				return FALSE;
			}
			$this->nField = mysql_num_fields( $this->Result );
			$this->nRow = mysql_num_rows ( $this->Result );
			return $this->Fetch ( $this->Result );
		}
		else {
			return $this->Fetch ( $this->Result );
		}
 
	}
 
# **********************************************************
# 実行
# **********************************************************
	function Execute( $SqlExec ) {
		$ret = mysql_query( $SqlExec,$this->Connect );
		if ( $this->Debug ) {
			if ( mysql_errno() != 0 ) {
				print "<B>" . mysql_error() . "</B><BR>";
			}
		}
		return $ret;
	}
 
# **********************************************************
# バージョン文字列取得
# **********************************************************
	function Version( ) {
		$Field = $this->QueryEx( "show variables like 'version'" );
		return $Field[1];
	}
 
}
?>
  



  dbMs.php (SQLServer 用)



  
<?
# **********************************************************
# データベースクラス
# **********************************************************
class DB {
 
	var $Connect;
	var $Result;
 
# **********************************************************
# コンストラクタ
# **********************************************************
	function DB( $Server='127.0.0.1', $DbName='lightbox', $User='sa', $Password='' ) {
		if ( !extension_loaded( "mssql" ) ) {
			dl("php_mssql.dll");
		}
		$this->Connect = mssql_connect( $Server, $User, $Password );
		mssql_select_db( $DbName, $this->Connect );
	}
 
# **********************************************************
# 接続解除
# **********************************************************
	function Close( ) {
		mssql_close( $this->Connect );
	}
 
# **********************************************************
# クエリー
# **********************************************************
	function Query( $SqlQuery ) {
		$ret = mssql_query( $SqlQuery,$this->Connect );
		return $ret;
	}
 
# **********************************************************
# フェッチ
# **********************************************************
	function Fetch( $Result ) {
		return mssql_fetch_array( $Result );
	}
 
# **********************************************************
# クエリーとフェッチ
# **********************************************************
	function QueryEx( $SqlQuery='' ) {
 
		if ( $SqlQuery != '' ) {
			$this->Result = $this->Query( $SqlQuery );
			if ( !$this->Result ) {
				return FALSE;
			}
			return $this->Fetch ( $this->Result );
		}
		else {
			return $this->Fetch ( $this->Result );
		}
 
	}
 
# **********************************************************
# 実行
# **********************************************************
	function Execute( $SqlExec ) {
		$ret = mssql_query( $SqlExec,$this->Connect );
		return $ret;
	}
 
# **********************************************************
# バージョン文字列取得
# **********************************************************
	function Version( ) {
		$Field = $this->QueryEx( "sp_server_info @attribute_id = 2" );
		return $Field["attribute_value"];
	}
 
}
?>
  



  dbPs.php (PostgreSQL用)

  
<?
# **********************************************************
# データベースクラス
# **********************************************************
class DB {
 
	var $Connect;
	var $Result;
 
# **********************************************************
# コンストラクタ
# **********************************************************
	function DB(
		$Server='localhost',
		$DbName='lightbox',
		$User='lightbox',
		$Password='' ) {
		if ( !extension_loaded( "pgsql" ) ) {
			dl("php_pgsql.dll");
		}
		$this->Connect = pg_connect(
			"host=$Server" .
			" port=5432" .
			" dbname=$DbName" .
			" user=$User" .
			" password=$Password"
		);
		$this->QueryEx( "SET CLIENT_ENCODING TO 'SJIS'" );
	}
 
# **********************************************************
# 接続解除
# **********************************************************
	function Close( ) {
		pg_close( $this->Connect );
	}
 
# **********************************************************
# クエリー
# **********************************************************
	function Query( $SqlQuery ) {
		$ret = pg_query( $this->Connect, $SqlQuery );
		return $ret;
	}
 
# **********************************************************
# フェッチ
# **********************************************************
	function Fetch( $Result ) {
		return pg_fetch_array( $Result );
	}
 
# **********************************************************
# クエリーとフェッチ
# **********************************************************
	function QueryEx( $SqlQuery='' ) {
 
		if ( $SqlQuery != '' ) {
			$this->Result = $this->Query( $SqlQuery );
			if ( !$this->Result ) {
				return FALSE;
			}
			return $this->Fetch ( $this->Result );
		}
		else {
			return $this->Fetch ( $this->Result );
		}
 
	}
 
# **********************************************************
# 実行
# **********************************************************
	function Execute( $SqlExec ) {
		$ret = pg_query( $this->Connect, $SqlExec );
		return $ret;
	}
 
# **********************************************************
# バージョン文字列取得
# **********************************************************
	function Version( ) {
		$Field = $this->QueryEx( "SHOW SERVER_VERSION" );
		return $Field["server_version"];
	}
 
}
?>
  



  dbOdbc.php (MDB等用)

  
<?
# **********************************************************
# データベースクラス
# **********************************************************
class DB {
 
	var $Connect;
	var $Result;
 
# **********************************************************
# コンストラクタ
# **********************************************************
	function DB( $Dsn='MDB', $User='', $Pass='' ) {
		$this->Connect = odbc_connect( $Dsn, $User, $Pass );
	}
 
# **********************************************************
# 接続解除
# **********************************************************
	function Close( ) {
		odbc_close( $this->Connect );
	}
 
# **********************************************************
# クエリー
# **********************************************************
	function Query( $SqlQuery ) {
		$ret = odbc_exec( $this->Connect, $SqlQuery );
		return $ret;
	}
 
# **********************************************************
# フェッチ
# **********************************************************
	function Fetch( $Result ) {
		$FetchArray = odbc_fetch_array( $Result );
		if ( is_array( $FetchArray ) ) {
			$Cnt = 0;
			foreach( $FetchArray as $Value ) {
				$FetchArray[$Cnt] = $Value;
				$Cnt++;
			}
			return $FetchArray;
		}
		else {
			return FALSE;
		}
	}
 
# **********************************************************
# クエリーとフェッチ
# **********************************************************
	function QueryEx( $SqlQuery='' ) {
 
		if ( $SqlQuery != '' ) {
			$this->Result = $this->Query( $SqlQuery );
			if ( !$this->Result ) {
				return FALSE;
			}
			return $this->Fetch ( $this->Result );
		}
		else {
			return $this->Fetch ( $this->Result );
		}
 
	}
 
# **********************************************************
# 実行
# **********************************************************
	function Execute( $SqlExec ) {
		$ret = odbc_exec( $this->Connect, $SqlExec );
		return $ret;
	}
 
# **********************************************************
# エラーメッセージ取得
# **********************************************************
	function GetError() {
		return odbc_errormsg( $this->Connect );
	}
 
}
?>
  










  infoboard   管理者用   
このエントリーをはてなブックマークに追加





フリーフォントWEBサービス
SQLの窓WEBサービス

SQLの窓フリーソフト

素材

一般WEBツールリンク

SQLの窓

フリーソフト

JSライブラリ