mRs = ($inResult) ? $inResult : NULL; $this->mCursor = $inResult ? ((mysqli_num_rows($inResult)>0) ? 0 : -1) : -1; $this->mFuncFromDB = $inFuncFromDB; // $result = mysqli_fetch_assoc($this->mRs); // $this->mInfo =mysqli_fetch_object($this->mRs); // mysqli_data_seek ($this->mRs ,-1); } // ============================================== // GetRef() // ============================================== // 本クラスが対応しない関数を呼び出したい場合に利用するためのインターフェース // ---------------------------------------------- // return : int mysqli_query(MySQL)/pg_query(PostgreSQL)の結果 public function getRef() { return $this->mRs; } // ============================================== // FetchRow() // ============================================== // カレントレコードをフェッチし、次のレコードへ移動 // ---------------------------------------------- // return : int フェッチしたレコードのレコードポジション public function fetchRow() { // if(!is_null($this->mRs) && is_array($this->mRow = mysqli_fetch_array($this->mRs, MYSQLI_ASSOC))) { if(!is_null($this->mRs) && is_array($this->mRow = mysqli_fetch_assoc($this->mRs))) { if($this->mFuncFromDB!=''){ $func = $this->mFuncFromDB; foreach($this->mRow AS $key => $val) { $this->mRow[$key] = $func($val); } } /* if(is_null($this->mInfo)){ // $this->mInfo =mysqli_fetch_object($this->mRs); } */ $this->mCursor++; return $this->mCursor; } else{ $this->mRow = array(); $this->mCursor = -1; return 0; } } // return : int カレントレコードセット内のレコード数 public function recCount() { return $this->mRs ? mysqli_num_rows($this->mRs) : 0; } public function isEmpty() { return $this->recCount()<1; } // カレントのレコードポジション(レコードセット内での位置)の取得 // ---------------------------------------------- // return : int レコードポジション(1ベース) / 0 = EOF public function recPos() { return ($this->recCount()>0) ? ($this->mCursor ) : 0; } public function isLast() { return $this->recCount() <= $this->recPos(); } // $inrecPos : int 移動先のレコードポジション // return : int 移動後のレコードポジション public function moveTo($inrecPos) { $inrecPos--; if($this->recCount()>$inrecPos) { $result = mysqli_data_seek ($this->mRs, $inrecPos); } else{ $result = false; } if($result) { $this->mCursor = $inrecPos; } else{ $this->mCursor = -1; } return $this -> recPos(); } // カレントレコードを、次のレコードへ移動 // ---------------------------------------------- // return : int 移動後のレコードポジション / 0 = EOF or -1 = BOF public function moveNext(){ return $this -> moveTo($this->mCursor + 2); } // カレントレコードを、先頭のレコードへ移動する // ---------------------------------------------- public function moveFirst(){ return $this -> moveTo(1); } // カレントレコードを、最後のレコードへ移動する // ---------------------------------------------- public function moveLast(){ return $this -> moveTo($this->RecCount()); } // ============================================== // Fields($inFieldName) // ============================================== // カレントレコードのフィールド(列/カラム)データの取得 // ---------------------------------------------- // $inFieldName : string フィールド名 // return : mixed フィールドデータ // フィールド名が無効の場合は '' を返す public function getVal($inFieldName) { return (isset($this->mRow[$inFieldName]))?$this->mRow[$inFieldName]:NULL; } // ============================================== // AsArray() // ============================================== // カレントレコードのフィールド(列/カラム)データを返す // ---------------------------------------------- // return : array フィールドデータ // フィールド名をキー、フィールドデータを値とした連想配列 public function asArray() { return $this->mRow; } /* public function asArrayEx() { // var_dump($this->mInfo); return $this->mRow; } */ } /****************************************************** LSBatchDynaset extends LSDynaset --------------------------------------------------- Batch検索用レコードセット オブジェクト 数万件ヒットしてしまったが、最初の10件だけをfetchして表示する とか、3ページ目(レコードボジション30~39)を表示する というケースで利用する 3ページ目 = ページインデックス = 2 *******************************************************/ class LSBatchDynaset extends LSDynaset { protected $mTotalRecords; // ヒット件数 protected $mcurrentPageIndex; // カレントのページインデックス、0ベース protected $mRecordsPerPage; // 1ページ当たりの最大レコード数 // ============================================== // LSBatchDynaset(&$inResult, $inTotalRecords, $inRecordsPerPage, $incurrentPageIndex) // ============================================== // コンストラクタ // LSDbオブジェクトのselectPageから呼び出されるため、外部から new LSBatchDynaset() しないこと // ---------------------------------------------- // $inResult : LSDbオブジェクトから返されるクエリの実行結果 // mysqli_query(MySQL)/pg_query(PostgreSQL)の結果 // $inTotalRecords : 抽出されたレコード総数 // $inRecordsPerPage : 1ページ当たりの最大レコード数 // $incurrentPageIndex : カレントのページインデックス、0ベース public function __construct(&$inResult, &$inFuncFromDB, $inTotalRecords, $inRecordsPerPage, $incurrentPageIndex) { $this -> mTotalRecords = $inTotalRecords; $this -> mcurrentPageIndex = $incurrentPageIndex; $this -> mRecordsPerPage = $inRecordsPerPage; parent::__construct($inResult, $inFuncFromDB); } // ============================================== // TotalRecords() // ============================================== // ヒットしたレコード総数の取得 // ---------------------------------------------- // return : int レコード総数(本オブジェクトが保持するレコードセット内のレコード以外も含む) public function totalRecords(){ return $this -> mTotalRecords; } // ============================================== // RecordsPerPage() // ============================================== // 1ページ当たりの最大レコード数の取得 // ---------------------------------------------- // return : int 1ページであたりの最大レコード数(本オブジェクトのレコードセット内の最大レコード数) public function recordsPerPage(){ return $this -> mRecordsPerPage; } // ============================================== // currentPageIndex() // ============================================== // カレントのページインデックス、0ベースの取得 // ---------------------------------------------- // return : int 現在のページのページインデックス(0ベース) public function currentPageIndex(){ return $this -> mcurrentPageIndex; } // ============================================== // totalPages() // ============================================== // 全ページ数の取得 // ヒットしたレコード数と1ページ当たりの最大レコード数からページ総数を計算する // 1ページ当たりの最大レコード数=50 // ヒットしたレコード数=101 // の場合、3が返る // ---------------------------------------------- // return : int 全ページ数 public function totalPages(){ if(($this -> mRecordsPerPage)!=0){ return (integer)ceil($this->mTotalRecords/$this -> mRecordsPerPage); } else{ return 0; } } // ============================================== // maxPageIndex() // ============================================== // ページインデックス(0ベース)の最大値の取得 // totalPages() から1引いた値 // ---------------------------------------------- // return : int ページインデックスの最大値 public function maxPageIndex(){ return $this -> totalPages() -1; } // ============================================== // isPrevious() // ============================================== // 前のページが存在するかの判定 // 1ページ目であることの判定 // ---------------------------------------------- // return : true 存在する // false 存在しない public function isPrevious(){ return $this -> mcurrentPageIndex>0; } // ============================================== // isNext() // ============================================== // 次のページが存在するかの判定 // 最後のページかどうかの判定 // ---------------------------------------------- // return : true 存在する // false 存在しない public function isNext(){ return $this -> mcurrentPageIndex < $this -> maxPageIndex(); } // カレントページ以降に存在するページ数を返す // ---------------------------------------------- // return : int カレントページ以降に存在するページ数 public function countNext(){ if ($this -> mcurrentPageIndex < $this -> maxPageIndex()) { if(($this -> maxPageIndex() - $this -> mcurrentPageIndex) == 1) { return $this -> mTotalRecords - (($this -> mcurrentPageIndex + 1) * $this -> mRecordsPerPage); } else{ return $this -> mRecordsPerPage; } } else{ return 0; } } // ============================================== // recPos() // ============================================== // カレントページの先頭レコードのレコードポジションを返す // ---------------------------------------------- // return : int 現在のページの先頭レコードのレコードポジション(1ベース) public function recPos(){ return parent::recPos() + ($this -> currentPageIndex() * $this -> RecordsPerPage()); } } class LSPageNavigation extends LSBatchDynaset{ protected $funcPrev ; protected $funcIndex ; protected $funcNext ; protected $mLinkUrl; public function __construct($inRs, $inLink, $inFuncPrev='CreatePreviousNavi', $inFuncIndex='CreatePageNavi', $inFuncNext='CreateNextNavi'){ parent::LSBatchDynaset($inRs->mRs, $inRs -> mFuncFromDB, $inRs->mTotalRecords, $inRs->mRecordsPerPage, $inRs->mcurrentPageIndex); $this->mLinkUrl = $inLink; $this->funcPrev = $inFuncPrev; $this->funcIndex = $inFuncIndex; $this->funcNext = $inFuncNext; } public function getPrevTag(){ if($this->isPrevious()){ return call_user_func_array($this->funcPrev, array($this->mRecordsPerPage, $this->currentPageIndex(), $this->mLinkUrl)); }else{ return ""; } } public function getNextTag(){ if($this->countNext()){ return call_user_func_array($this->funcNext, array($this->mRecordsPerPage, $this->currentPageIndex(), $this->countNext(), $this->mLinkUrl)); }else{ return ""; } } public function getPageIndexTag(){ if($this->totalPages()>1){ return call_user_func_array($this->funcIndex, array($this->mRecordsPerPage, $this->mcurrentPageIndex, $this->totalPages(), $this->TotalRecords(), $this->mLinkUrl)); }else{ return ""; } } } // CPIなど [character_set_server ujis] なサーバ用 function LSDbSJis2Euc($inVal) { $inVal= mb_convert_encoding($inVal, "EUC", "SJIS"); return $inVal; } function LSDbEuc2SJis($inVal) { $inVal = mb_convert_encoding($inVal, "SJIS","EUC"); return $inVal; } function LSDbUTF82Euc($inVal) { $inVal = mb_convert_encoding($inVal, "EUC", "UTF-8"); return $inVal; } function LSDbEuc2UTF8($inVal) { $inVal = mb_convert_encoding($inVal, "UTF-8", "EUC"); return $inVal; } function LSDbUTF82SJis($inVal) { $inVal = mb_convert_encoding($inVal, "SJIS", "UTF-8"); return $inVal; } function LSDbSJis2UTF8($inVal) { $inVal = mb_convert_encoding($inVal, "UTF-8", "SJIS"); return $inVal; } /* Variable_name Value character_set_client utf8 character_set_connection utf8 character_set_database utf8 character_set_filesystem binary character_set_results utf8 character_set_server ujis character_set_system utf8 character_sets_dir /usr/local/share/mysql/charsets/ */ class LSDb { protected $mLink; // MySQLリンクID protected $mResult; // クエリ実行結果の結果(result)ID protected $mFuncToDB; // データベースへデータを書き込む際に呼ばれる文字コード変換関数 protected $mFuncFromDB; // データベースからデータを取得する際に呼ばれる文字コード変換関数 protected $debugFunc = ''; // $inFuncToDB : データベースへデータを書き込む際に呼ばれる文字コード変換関数 // $inFuncFromDB : データベースからデータを取得する際に呼ばれる文字コード変換関数 // $inDBName : 接続先のMySqlデータベース名 // $inUser : データベースアカウント(ユーザー名) // $inPwd : データベースアカウント(パスワード) // $inHost : データベースサーバーホスト名 // ポートを指定したい場合は host:port のように指定する // TLS8 のデフォルトは、'localhost:/var/lib/mysql/mysql.sock' となる // return : 接続に失敗した場合はエラーメッセージ(string)をprintする // printするた゜けであり、trigger_error は利用していない // /* LSDbsEuc2UTF8 LSDbUTF82Euc */ public function __construct($inFuncToDB = '', $inFuncFromDB = '' ,$inDBName='', $inUser = '', $inPwd = '', $inHost='', $inDebugFunc='') { global $gCom_DbDebugFunc; if($inDBName=='') { $inDBName = gCom_DbName; } if($inUser=='') { $inUser = gCom_DbUser; } if($inPwd=='') { $inPwd = gCom_DbPwd; } if($inHost=='') { $inHost = gCom_DbCon; } if($inDebugFunc=='') { $inDebugFunc = (is_callable($gCom_DbDebugFunc))?$gCom_DbDebugFunc:""; } $this->setDebugFunc($inDebugFunc); // 170425 T.Fujii Modified 汎用化 // 170223 S.Uchida Modified for CPI Server // $this -> mLink = mysqli_connect($inHost, $inUser, $inPwd); $this -> mLink = mysqli_connect($inHost, $inUser, $inPwd, $inDBName, gEnv_DbPort); mysqli_set_charset($this -> mLink , gEnv_DbCharSet); /* if(!($this -> mLink)) { //print "Error in LSDb() : Failed to connect.
Host : $inHost
User : $inUser
Pwd : $inPwd
"; $this->debug("Error in LSDb() : Failed to connect.
Host : $inHost
"); } elseif( !(mysqli_select_db($this->mLink, $inDBName)) ) { $this->debug("Could not select DB in LSDb()!
Host : $inHost
"); $this->debug("Error in LSDb() : Failed to select DB($inDBName).
Host : $inHost
"); } */ $this -> mFuncToDB = $inFuncToDB; $this -> mFuncFromDB = $inFuncFromDB; } // LSDb Factory public static function createDbObject($inForce = false ,$inFuncToDB = '' ,$inFuncFromDB = '' ,$inDBName='', $inUser = '', $inPwd = '', $inHost='', $inDebugFunc=''){ global $gObj_LSDb; $confArray = array($inFuncToDB,$inFuncFromDB,$inDBName, $inUser, $inPwd, $inHost, $inDebugFunc); $confKey = serialize($confArray); if($inForce){ return new LSDb($inFuncToDB,$inFuncFromDB,$inDBName, $inUser, $inPwd, $inHost, $inDebugFunc); }elseif(!isset($gObj_LSDb[$confKey])){ $gObj_LSDb[$confKey] = new LSDb($inFuncToDB,$inFuncFromDB,$inDBName, $inUser, $inPwd, $inHost, $inDebugFunc); } return $gObj_LSDb[$confKey]; } public function setToFunc($inFuncName){ if(is_callable($inFuncName)){ $this->mFuncToDB = $inFuncName; } } public function setFromFunc($inFuncName){ if(is_callable($inFuncName)){ $this->mFuncFromDB = $inFuncName; } } public function getLastError(){ return mysqli_error ($this -> mLink); } // ============================================== // 連想配列から区切り文字(デフォルトではカンマ区切り)のテキストを生成する // (本クラス内部で利用する)ユーティリティメソッド // array('a' => 1, 'b' => 2) を渡すと、"a='1', b='2'" を返す // ---------------------------------------------- // $inKeyValueArray : 連想配列 array(fieldName => fieldValue, ..... ) // $inDelimita : 区切り文字 // return : string カンマ区切りのテキスト protected function createPhrase_($inKeyValueArray, $inRawRows=null){ $str = ''; if(is_array($inKeyValueArray)){ $count = 0; // if(($func = $this -> mFuncToDB) == '') { foreach($inKeyValueArray as $key => $value){ if(!empty($str)){ $str .= ','; } if(is_numeric($value) || isset($inRawRows[$key])){ $str .= "$key=".$value; }else{ $str .= "$key='".addslashes($value)."'"; } } /* } else{ foreach($inKeyValueArray as $key => $value){ if(!empty($str)){ $str .= ','; } var_dump($key.'--'.$inRawRows[$key]); if(isset($inRawRows[$key])){ $str .= "$key=".$value; } else{ $str .= "$key='".addslashes($func($value))."'"; } } } */ } return $str; } // ============================================== // トランザクション  // ---------------------------------------------- // トランザクションを開始 public function beginTransaction() { $result = $this->rawQuery('START TRANSACTION'); } // コミット public function commit() { $result = $this->rawQuery('COMMIT'); } // ロールバック public function rollback() { $result = $this->rawQuery('ROLLBACK'); } // 非自動コミットモードへ切り替える // デフォルトでは、自動コミットモード(テーブルを更新するステートメント // を実行すると直ちにその更新がディスクに格納される)で稼動 public function disableAutocommit() { $result = $this->rawQuery('SET AUTOCOMMIT=0'); } // ============================================== // テーブルロック メソッド // ---------------------------------------------- // テーブルをグローバルにロックする // サーバへの接続が閉じられると、現在のスレッドがロックしている // テーブルのロックはすべて暗黙的に解除される(MySQLの仕様) // 例)LOCK TABLES trans READ, customer WRITE; public function lockTables($inTables) { $result = $this->rawQuery("LOCK TABLES $inTables"); } // ロックされたテーブルのロックを解除する public function unLockTables() { $result = $this->rawQuery('UNLOCK TABLES'); } // ========================================================================= // 汎用SQL文実行 メソッド // 文字コードの変換が行われないので注意! // ========================================================================= // ---------------------------------------------- // getRs 汎用SQL文実行 // ---------------------------------------------- // SQL文を実行し、結果のレコードセット(LSDynasetオブジェクト)を返す // 文字コードの変換が行われないので注意! // 後述select()メソッドでは対応できないSQL文(サブクエリ等)で利用 // ---------------------------------------------- // $inQuery : SQL文 // return : レコードセット(LSDynasetオブジェクト) // エラーの場合はエラーメッセージ(string)をprintする // public function getRs($inQuery) { $result = $this->rawQuery($inQuery); if($result) { return new LSDynaset($result, $this -> mFuncFromDB); } else{ $this->debug($inQuery); //print "
Query error : LSDb -> getRs($inQuery)"; return 0; } } // ---------------------------------------------- // Query 汎用SQL文実行 // ---------------------------------------------- // SQL文実行し、mysqli_queryの結果ID(resultID)を返す // レコードセットを期待しないSQL文で利用する // ---------------------------------------------- // $inQuery : SQL文 // return : mysqli_queryの結果ID(resultID)を返す // エラーの場合はエラーメッセージ(string)をprintし(int)-1を返す public function query($inQuery) { $result = $this->rawQuery($inQuery); if($result) { return mysqli_insert_id($this->mLink); } else{ $this->debug($inQuery); return -1; } } public function rawQuery($inQuery){ // echo "
\nrawQuery($inQuery)\n
";
			$this->debug($inQuery);
			$result = mysqli_query($this->mLink, $inQuery);
			return $result;
		}
		
		
		//	==============================================
		//	 SQL文実行 メソッド
		//	----------------------------------------------

		//	----------------------------------------------
		//	UPDATE SQL文の実行 レコードデータの更新
		//	----------------------------------------------
		//	$inTableName		:	string	テーブル名
		//	$inKeyValueArray	:	array	更新後のデータ	array('fieldName2' => value1, 'fieldName2' => value2)  
		//	$inWhere			:	更新対象となるレコードの検索条件(WHERE句)
		//	return				:	エラーの場合は負
		//							エラーの場合はエラーメッセージ(string)をprint( Query($inQuery) ) 

		public function update($inTableName, &$inKeyValueArray, $inWhere = '', $inRawRows=null){
			if(($inTableName!='') && (is_array($inKeyValueArray) && count($inKeyValueArray))){
				$strQuery = $this->createPhrase_($inKeyValueArray,$inRawRows);
				$strQuery = "UPDATE $inTableName SET $strQuery";
				if($inWhere != '') {
					$strQuery .= " WHERE $inWhere";
				}
				$ret = $this->Query($strQuery);
				if($ret!=-1){
					return $this->affectedRow();
				};
			}
			return -1;
		}
		
		public function insertOrUpdate($inTableName,$inArrayData){	//	181010
			$result = 0;
			if($inTableName && is_array($inArrayData) ){
				$keys = array_keys($inArrayData);
				$values = array_values($inArrayData);
				
				$strQuery = "INSERT INTO $inTableName (".implode(',',$keys).") VALUES ";
				$vArray = [];
				foreach($values AS $idx => $val){
					$vArray[] = is_string($val) ? '"'.mysqli_real_escape_string($this->mLink,$val).'"':$val;	//	181119
				}
				$valStr = '('.implode(',',$vArray).')';
				$strQuery .= $valStr .' ON DUPLICATE KEY UPDATE ';
				$updates = [];
				foreach($keys AS $idx => $field){
					$updates[] =  $field.'=VALUES('.$field.')';
				}
				$strQuery .= implode(', ',$updates);
				$result = $this->Query($strQuery);
			}
			return $result;
		}
	
		
		
		//	$inFields=['field1', 'field2',...]
		//	$inValuesArray = [$val1, #val2, ...]
		public function insertOrUpdateMany($inTableName ,$inFields, $inValuesArray){	//	181010
			$result = 0;
			if($inTableName && is_array($inFields)  && is_array($inValuesArray) ){
	//			$keys = array_keys($inArrayData);
	//			$values = array_values($inArrayData);
				
				$strQuery = "INSERT INTO $inTableName (".implode(',',$inFields).") VALUES ";
				$valArray = [];
				foreach($inValuesArray AS $idx => $values){
					$vArray = [];
					foreach($values AS $idx2 => $val){
						$vArray[] = is_string($val) ? '"'.mysqli_real_escape_string($this->mLink,$val).'"':$val;	//	181119
					}
					$valArray[] = '('.implode(',',$vArray).')';
				}
				$strQuery .=implode(',',$valArray).' ON DUPLICATE KEY UPDATE ';
				$updates = [];
				foreach($inFields AS $idx => $field){
					$updates[] =  $field.'=VALUES('.$field.')';
				}
				$strQuery .= implode(', ',$updates);
				$result = $this->Query($strQuery);
			}
			return $result;
		}
	
		
		
		//	----------------------------------------------
		//	INSERT SQL文の実行	新規レコードの追加
		//	----------------------------------------------
		//	$inTableName		:	string	テーブル名
		//	$inKeyValueArray	:	array	追加するデータ	array('fieldName2' => value1, 'fieldName2' => value2)  
		//	return				:	AUTO_INCREMENTEDカラム用に生成されたIDを返す。
		//							AUTO_INCREMENTの値を生成しない場合には0を返す。
		//							通常は追加されたレコードの主キー
		//							エラーの場合はエラーメッセージ(string)をprintし( Query($inQuery) ) - 1 を返す

		public function insert($inTableName, $inKeyValueArray, $inIgnore='', $inRawRows=null){
			$newId = -1;
			if(($inTableName!='') && (count($inKeyValueArray))){
				$strSetPhrase = $this->createPhrase_($inKeyValueArray,$inRawRows);
				$strQuery = "INSERT ".$inIgnore." INTO $inTableName SET $strSetPhrase";
				$newId = $this->Query($strQuery);
			}
			return $newId;
		}

		
		public function insertMany($inTableName, $inFields, $inValues){
			$newId = -1;
			if($inTableName && is_array($inFields) && count($inFields) && is_array($inValues) && count($inValues)){
				$strQuery = "INSERT INTO $inTableName (".implode(',',$inFields).") VALUES ";
				$valArray = [];
				foreach($inValues AS $idx => $valuesArray){
				//	$valArray[] = '('.implode(',',$valuesArray).')';
					$vArray = [];
					foreach($valuesArray AS $idx2 => $val){
						$vArray[] = is_string($val) ? '"'.$val.'"':$val;
					}
					$valArray[] = '('.implode(',',$vArray).')';
				}
				$strQuery .=implode(',',$valArray);
		//	 	var_dump( $strQuery );	
				$newId = $this->Query($strQuery);
			}
			return $newId;
		}

		
		/*
		
update PMemberFavorite SET
favSort =
	case itmId
		WHEN 143 THEN 1
		WHEN 310 THEN 2
		WHEN 124 THEN 3
		WHEN 116 THEN 4
		WHEN 136 THEN 5
		WHEN 134 THEN 6
		WHEN 308 THEN 7
END
, favDateUpdate = NOW()
WHERE memId=8

$case['favSort,itmId'][] = [ $rec['id'],$rec['sort'] ];
$case['favDateUpdate,itmId'][] = [ $rec['id'], $now ];
	*/

		static public function escapeStr($inVal){	//	181027
			return is_string($inVal) ? '"'.$inVal.'"':$inVal;
		} 
		//	バルクアップデート
		public function updateMany($inTable,$inWhere,$inCase){	//	181027
			$sets = [];
			foreach($inCase AS $fieldUpdate => $casePhrase){
				$field = explode(',',$fieldUpdate);
				$phrase = $field[0].'= CASE '.$field[1].' ';
				$whenArray = [];
				foreach($casePhrase AS $caseField => $valArray){
					$whenArray[] = ' WHEN '.self::escapeStr( $valArray[0]).' THEN '.self::escapeStr( $valArray[1]);
				}
				$sets[] = $phrase.implode(' ',$whenArray).' END';
			}
			$query = 'UPDATE '.$inTable.' SET '.implode(',',$sets);
			if($inWhere){
				$query .=' WHERE '.$inWhere;
			}
			
			return $this->query($query);
			
			//	$valArray[] = '('.implode(',',$vArray).')';
		}



		//	----------------------------------------------
		//	REPLACE SQL文の実行	新規レコードの追加
		//	----------------------------------------------
		//	$inTableName		:	string	テーブル名
		//	$fields				:	array	[field1, field2, ... fieldN];
		//	$ivalueArray		:	array	[[value1,value2,...valueN],[value1,value2,...valueN],...,[value1,value2,...valueN]] 
		//	return				:	INSERTの時は1、UPDATEの時は2(更新が無いと0)。 
		//							100件のINSERT ON DUPLICATE KEY UPDATEを行ったとして、 
		//							1戻り値が101だった場合、1件がUPDATEで残り99件はINSERTです。 
		//							1102であれば、2件がUPDATEで残り98件はINSERTです。 
		//							「戻り値 - INSERT ON DUPLICATE KEY UPDATEした数」でUPDATEの数

		public function replace($inTableName, $fields, $inIgnore='', $inRawRows=null){
			$result = 0;
			return $result;
		}

		//	----------------------------------------------
		//	DELETE SQL文の実行 レコードの削除
		//	----------------------------------------------
		//	$inTableName		:	string	テーブル名
		//	$inWhere			:	削除するレコードの検索条件(WHERE句)
		//	return				:	削除されたレコード数
		//							WHERE節のないDELETEクエリーであった場合、全レコードが
		//							テーブルから削除されるが0を返す。 

		//	DELETE t1,t2 FROM t1,t2,t3 WHERE t1.id=t2.id AND t2.id=t3.id
		//	は
		//	DELETE FROM t1,t2 USING t1,t2,t3 WHERE t1.id=t2.id AND t2.id=t3.id
		//	と記述して対応(テーブル t1 と t2 内の一致するレコードだけが削除)
			
		public function	delete($inTableName, $inWhere = '')
		{
			$strQuery = "DELETE FROM $inTableName";
			if($inWhere != '') {
				$strQuery .= " WHERE $inWhere";
			}
			return ($this->rawQuery($strQuery))?mysqli_affected_rows($this->mLink) : 0;
		}
		
		
		//	----------------------------------------------
		//	SELECT SQL文の実行 	レコードの抽出(検索照会)
		//	----------------------------------------------
		//	$inTableName	:	string	テーブル名
		//	$inWhere		:	レコードの検索条件(WHERE句)
		//	$inSort			:	レコードの検索条件(ORDER BY 句)
		//	$inGroup		:	レコードの検索条件(ORDER BY 句)
		//	$inLock			:	ロック条件(LOCK IN SHARE MODE/FOR UPDATE)
		//	$inFields		:	ソート条件(ORDER BY 句)
		//	return			:	レコードセット(LSDynasetオブジェクト)
		//						エラーの場合はエラーメッセージ(string)をprint( Query($inQuery) ) 
		
		public function	select($inTableName, $inWhere = '', $inSort = '', $inFields = '*',  $inGroup = '', $inLock = '')
		{
			if($inWhere){
				$inWhere = ' WHERE '.$inWhere;
			}
			if($inSort){
				$inSort = ' ORDER BY '.$inSort;
			}
			if($inGroup){
				$inGroup = ' GROUP BY '.$inGroup;
			}
			$strQuery = "SELECT $inFields FROM $inTableName $inWhere $inGroup $inSort $inLock";
			$result = $this->rawQuery($strQuery);
			return	new LSDynaset($result, $this -> mFuncFromDB);
		}
		

		//	----------------------------------------------
		//	SELECT SQL文の実行 		1レコードのみの抽出
		//		TConfig(全体の設定値を保存するテーブル)等、1レコードしかないような
		//		テーブルで利用する    cDBConf.php から利用されている
		//	----------------------------------------------
		//	$inTableName		:	string	テーブル名
		//	$inPKeyFieldName	:	string	主キーのフィールド名
		//	$inPKeyFieldValue	:	int		主キーの値
		//	return			:	レコードセット(LSDynasetオブジェクト)
		//						エラーの場合はエラーメッセージ(string)をprint( Query($inQuery) ) 
		
		public function	selectOneRecord($inTableName, $inPKeyFieldName='id', $inPKeyFieldValue=0)
		{
			$strQuery = 'SELECT * FROM '.$inTableName.' WHERE '.$inPKeyFieldName."='".$inPKeyFieldValue."'";
			$result = $this->rawQuery($strQuery);
			return	new LSDynaset($result, $this -> mFuncFromDB);
		}

		

		//	==============================================
		//	 selectPage		Batch検索用 SELECT SQL文の実行
		//	----------------------------------------------
		//	 	LSBatchDynaset オブジェクトを生成
		//	----------------------------------------------
		//	$inTableName	:	string	テーブル名
		//	$inWhere		:	レコードの検索条件(WHERE句)
		//	$inSort			:	レコードの検索条件(ORDER BY 句)
		//	$inGroup		:	レコードの検索条件(ORDER BY 句)
		//	$inFields		:	ソート条件(ORDER BY 句)
		//	$inPageIndex	:	ソート条件(ORDER BY 句)
		//	$inRecsPerPage	:	ソート条件(ORDER BY 句)
		//	return			:	レコードセット(LSBatchDynasetオブジェクト)
		//						エラーの場合はエラーメッセージ(string)をprintし、(int)0を返す
		public function	selectPage($inPageIndex, $inRecsPerPage, $inTableName, $inWhere='', $inSort='', $inFields = '*',  $inGroup = '')
		{
		$numOfRec  = 0;

			if($inWhere){
				$inWhere = ' WHERE '.$inWhere;
			}
			if($inSort){
				$inSort = ' ORDER BY '.$inSort;
			}
			if($inGroup){
				$inGroup = ' GROUP BY '.$inGroup;
			}
			
			
			$strQuery 		= "FROM $inTableName $inWhere $inGroup $inSort";
			if($inRecsPerPage < 1){
				$inRecsPerPage = 1;
			}
			
			if($inPageIndex<1){
					$inPageIndex = 0;
			}
			
			$startIndex = $inPageIndex * $inRecsPerPage;
			$strQueryTemp 	= "SELECT SQL_CALC_FOUND_ROWS $inFields $strQuery  LIMIT $startIndex, $inRecsPerPage";
			$result = $this->rawQuery($strQueryTemp);
			$result2 = $this->rawQuery("SELECT FOUND_ROWS()");
			$result2 = mysqli_fetch_array($result2, MYSQLI_ASSOC);
			$numOfRec = (int)$result2['FOUND_ROWS()'];
			
			return	new LSBatchDynaset($result, $this -> mFuncFromDB, $numOfRec, $inRecsPerPage, $inPageIndex);
		}
		/*
		public function	selectPage($inPageIndex, $inRecsPerPage, $inTableName, $inWhere='', $inSort='', $inFields = '*',  $inGroup = '')
		{
			$numOfRec  = 0;

			if($inWhere){
				$inWhere = ' WHERE '.$inWhere;
			}
			if($inSort){
				$inSort = ' ORDER BY '.$inSort;
			}
			if($inGroup){
				$inGroup = ' GROUP BY '.$inGroup;
			}
			
			
			$strQuery 		= "FROM $inTableName $inWhere $inGroup $inSort";
			$strQueryTemp 	= "SELECT count(*) AS NumOfRec FROM $inTableName $inWhere";
			//$strQueryTemp 	= "SELECT * FROM ".$inTableName.$inWhere.$inGroup;
			//$strQueryTemp 	= "SELECT count(*) FROM ".$inTableName.$inWhere.$inGroup;
			$result = $this->rawQuery($strQueryTemp);
			if($result){
				//$numOfRec = mysqli_num_rows($result);
				$tmp = mysqli_fetch_assoc($result);
				$numOfRec = ($tmp && is_array($tmp)) ? $tmp["NumOfRec"]:0;
				//var_dump($numOfRec);
			}
			else{
				return 0;
			}
//			print "
$numOfRec -|- $inPageIndex -|- $inRecsPerPage -|- $strQueryTemp -|- $strQuery
"; if($inRecsPerPage < 1){ $inRecsPerPage = 1; } $numOfPages = (integer)ceil(($numOfRec)/$inRecsPerPage); if($inPageIndex<1){ $inPageIndex = 0; } elseif($inPageIndex >= $numOfPages) { $inPageIndex = $numOfPages - 1; } $startIndex = $inPageIndex * $inRecsPerPage; //print "
$inPageIndex ----$numOfPages --- $inRecsPerPage --- $numOfRec
"; $strQueryTemp = "SELECT $inFields $strQuery LIMIT $startIndex, $inRecsPerPage"; //print $strQueryTemp.'
'; $result = $this->rawQuery($strQueryTemp); return new LSBatchDynaset($result, $this -> mFuncFromDB, $numOfRec, $inRecsPerPage, $inPageIndex); } */ // ---------------------------------------------- // 直前のSQL文実行で変更されたレコード数を得る // ---------------------------------------------- // return : int 直前のSQL文実行で変更されたレコード数 public function affectedRow(){ return mysqli_affected_rows($this->mLink); } // ---------------------------------------------- // 直近のINSERTで生成されたIDを得る // ---------------------------------------------- // return : int 直前のINSERTで生成されたID public function insertId(){ return mysqli_insert_id($this->mLink); } // ---------------------------------------------- // 直前のSQL文を実行した結果の結果ID(resultID)を返す // 本クラスが対応しない関数を呼び出したい場合に利用するためのインターフェース // ---------------------------------------------- // return : int 結果ID(resultID) public function getRef(){ return $this->mLink; } public function setDebugFunc($inFunc){ if(is_callable($inFunc)){ $this->debugFunc = $inFunc; } } public function getDebugFunc(){ if($this->debugFunc != ""){ return $this->debugFunc; } return false; } protected function debug($inQuery){ if($func = $this->getDebugFunc()){ call_user_func($func, $inQuery); } } public function setSqlDebug(){ // 180729 非推奨になったcreate_functionを無名関数で書き換え $callback = function($inQuery){ print "
\n■■■■■ ".($inQuery)."
\n"; debug_print_backtrace(); print "\n
\n"; }; $this->setDebugFunc($callback); } }; /* function debugSql($inQuery){ echo $inQuery.'
'; } */
Fatal error: Uncaught Error: Class "LSDb" not found in /var/www/vhosts/gerogle.jp/www/g1/lsc/lib/core/LSDbConf.php:37 Stack trace: #0 /var/www/vhosts/gerogle.jp/www/g1/lsc/lib/core/LSUpfileG2.php(51): include_once() #1 /var/www/vhosts/gerogle.jp/www/g1/lsc/conf/gCommon.php(69): include_once('...') #2 /var/www/vhosts/gerogle.jp/www/g1/lsc/conf/gCommon.php(165): {closure:/var/www/vhosts/gerogle.jp/www/g1/lsc/conf/gCommon.php:68}() #3 /var/www/vhosts/gerogle.jp/www/g1/lsc/conf/gCommonPub.php(18): include_once('...') #4 /var/www/vhosts/gerogle.jp/www/g1/lsc/conf/gConfPub.php(10): include_once('...') #5 /var/www/vhosts/gerogle.jp/www/g1/lsc/pub/base.php(30): include_once('...') #6 /var/www/vhosts/gerogle.jp/www/g1/lsc/pub/dispatcher.php(28): include_once('...') #7 {main} thrown in /var/www/vhosts/gerogle.jp/www/g1/lsc/lib/core/LSDbConf.php on line 37