Subversion Repositories qbpwcf-lib(archive)

Rev

Rev 915 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 liveuser 1
<?php
2
 
3
/*
4
 
5
	QBPWCF, Quick Build PHP website Component base on Fedora Linux.
843 liveuser 6
    Copyright (C) 2014~2025 Min-Jhin,Chen
1 liveuser 7
 
8
    This file is part of QBPWCF.
9
 
10
    QBPWCF is free software: you can redistribute it and/or modify
11
    it under the terms of the GNU General Public License as published by
12
    the Free Software Foundation, either version 3 of the License, or
13
    (at your option) any later version.
14
 
15
    QBPWCF is distributed in the hope that it will be useful,
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
    GNU General Public License for more details.
19
 
20
    You should have received a copy of the GNU General Public License
21
    along with QBPWCF.  If not, see <http://www.gnu.org/licenses/>.
22
 
23
*/
24
namespace qbpwcf;
25
 
26
/*
248 liveuser 27
類別說明:
28
跟mysql/mariadb操作有關的類別
29
備註:
66 liveuser 30
建議加上pdo的支援,以便無痛支援多種資料庫。
31
https://www.php.net/manual/en/mysql.php
32
https://www.php.net/manual/en/mysqlinfo.library.choosing.php
33
https://blog.markgdi.com/article/quick-start-operation-mysql-using-php-pdo/
1 liveuser 34
*/
35
class db{
36
 
37
	/*
38
	#函式說明:
39
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
40
	#回傳結果:
41
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
42
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
43
	#$result["function"],當前執行的函式名稱.
44
	#必填參數:
45
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
46
	#$arguments,陣列,為呼叫方法時所用的參數.
47
	#參考資料:
48
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
49
	*/
50
	public function __call($method,$arguments){
51
 
52
		#取得當前執行的函式
53
		$result["function"]=__FUNCTION__;
54
 
55
		#設置執行不正常
56
		$result["status"]="false";
57
 
58
		#設置執行錯誤
59
		$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
60
 
61
		#設置所丟入的參數
62
		$result["error"][]=$arguments;
63
 
64
		#回傳結果
65
		return $result;
66
 
67
		}#function __call end
68
 
69
	/*
70
	#函式說明:
71
	#當前類別被呼叫的靜態方法不存在時,將會執行該函數,回報該方法不存在.
72
	#回傳結果:
73
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
74
	#$reuslt["error"],執行不正常結束的錯訊息陣列.
75
	#$result["function"],當前執行的函式名稱.
76
	#必填參數:
77
	#$method,物件,為物件實體或類別名稱,會自動置入該參數.
78
	#$arguments,陣列,為呼叫方法時所用的參數.
79
	#參考資料:
80
	#__call=>http://php.net/manual/en/language.oop5.overloading.php#object.callstatic
81
	*/
82
	public static function __callStatic($method,$arguments){
83
 
84
		#取得當前執行的函式
85
		$result["function"]=__FUNCTION__;
86
 
87
		#設置執行不正常
88
		$result["status"]="false";
89
 
90
		#設置執行錯誤
91
		$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
92
 
93
		#設置所丟入的參數
94
		$result["error"][]=$arguments;
95
 
96
		#回傳結果
97
		return $result;
98
 
99
		}#function __callStatic end
100
 
101
	/*
43 liveuser 102
	#函式說明:
1 liveuser 103
	#連線到mysql-server,會回傳一個陣列
104
	#回傳結果:
105
	#$result["status"],若連線成功則爲"true",連線失敗則爲"false"。
106
	#$result["function"],當前執行的函數名稱
107
	#$result["connectInformation"],爲回傳的mysql連線資訊。
108
	#$result["error"],爲錯誤訊息陣列
109
	#必填參數:
110
	#$conf["dbAddress"],字串,爲mysql-Server的位置。
111
	$conf["dbAddress"]=$dbAddress;
112
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號。
113
	$conf["dbAccount"]=$dbAccount;
43 liveuser 114
	#可省略參數:
1 liveuser 115
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
116
	#$conf["dbPassword"]=$dbPassword;
126 liveuser 117
	#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,預設不使用
1 liveuser 118
	#$conf["dbPort"]="3306";
185 liveuser 119
	#參考資料:
120
	#無.
43 liveuser 121
	#備註:
122
	#無.
1 liveuser 123
	*/	
124
	public static function mysqlConnect(&$conf){
125
 
126
		#初始化要回傳的內容
127
		$result=array();
128
 
129
		#取得當前執行的函數名稱
130
		$result["function"]=__FUNCTION__;
131
 
132
		#如果 $conf 不為陣列
133
		if(gettype($conf)!="array"){
134
 
135
			#設置執行失敗
136
			$result["status"]="false";
137
 
138
			#設置執行錯誤訊息
139
			$result["error"][]="\$conf變數須為陣列形態";
140
 
141
			#如果傳入的參數為 null
142
			if($conf==null){
143
 
144
				#設置執行錯誤訊息
145
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
146
 
147
				}#if end
148
 
149
			#回傳結果
150
			return $result;
151
 
152
			}#if end
153
 
154
		#檢查參數
43 liveuser 155
		#函式說明:
1 liveuser 156
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
157
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
158
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
159
		#$result["function"],當前執行的函式名稱.
160
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
161
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
162
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
163
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
164
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
165
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
166
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
43 liveuser 167
		#必填參數:
1 liveuser 168
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
169
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
170
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
171
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount");
172
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
173
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
174
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
175
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
43 liveuser 176
		#可省略參數:
1 liveuser 177
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
178
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
179
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
180
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort");
181
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
182
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
183
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
184
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null);
185
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
186
		#$conf["arrayCountEqualCheck"][]=array();
43 liveuser 187
		#參考資料:
1 liveuser 188
		#array_keys=>http://php.net/manual/en/function.array-keys.php
189
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
190
		unset($conf["variableCheck::checkArguments"]);
191
 
192
		#如果檢查失敗
193
		if($checkResult["status"]=="false"){
194
 
195
			#設置錯誤識別
196
			$result["status"]="fasle";
197
 
198
			#設置錯誤訊息
199
			$result["error"]=$checkResult;
200
 
201
			#回傳解果
202
			return $result;
203
 
204
			}#if end
205
 
206
		#如果 $checkResult["status"]等於"false";
207
		if($checkResult["passed"]=="false"){
208
 
209
			#設置錯誤識別
210
			$result["status"]="fasle";
211
 
212
			#設置錯誤訊息
213
			$result["error"]=$checkResult;
214
 
215
			#回傳解果
216
			return $result;
217
 
218
			}#if end
219
 
126 liveuser 220
		#如果是 localhost
221
		if($conf["dbAddress"]==="localhost"){
222
 
223
			#卸除dbPort變數
224
			unset($conf["dbPort"]);
225
 
226
			}#if end
227
 
1 liveuser 228
		#如果密碼爲空,則爲不使用密碼進行連綫		
229
		if(!isset($conf["dbPassword"])){
230
 
231
			#如果沒設定 dbPort
232
			if(!isset($conf["dbPort"])){
233
 
234
				#設定資料庫位置與帳號,並連線
235
				#若連線失敗
236
				if(!($result["connectInformation"]=@mysqli_connect($conf["dbAddress"],$conf["dbAccount"]))){
237
 
238
					#設置連線失敗的提示
239
					$result["error"][]="連線失敗,請檢查帳號是否正確.";
240
 
241
					#取得連線時的錯誤編號
242
					$result["error"][]=mysqli_connect_errno();
243
 
244
					#取得連線時的錯誤訊息
245
					$result["error"][]=mysqli_connect_error();
246
 
247
					#設置執行失敗
248
					$result["status"]="false";
249
 
250
					#回傳結果
251
					return $result;
252
 
253
					}#if end
254
 
255
				}#if end
256
 
257
			#反之
258
			else{
259
 
260
				#設定資料庫位置與port與帳號,並連線
261
				#若連線失敗
262
				if(!($result["connectInformation"]=@mysqli_connect($conf["dbAddress"].":".$conf["dbPort"],$conf["dbAccount"]))){
263
 
264
					#設置連線失敗的提示
265
					$result["error"][]="連線失敗,請檢查帳號是否正確.";
266
 
267
					#取得連線時的錯誤編號
268
					$result["error"][]=mysqli_connect_errno();
269
 
270
					#取得連線時的錯誤訊息
271
					$result["error"][]=mysqli_connect_error();
272
 
273
					#設置執行失敗
274
					$result["status"]="false";
275
 
276
					#回傳結果
277
					return $result;
278
 
279
					}#if end
280
 
281
				}#else end
282
 
283
			}#if end
284
 
285
		#反之代表要使用密碼
286
		else{
287
 
288
			#如果沒設定 dbPort
289
			if(!isset($conf["dbPort"])){
290
 
291
				#設定資料庫位置、帳號、密碼,並連綫
292
				if(!($result["connectInformation"]=@mysqli_connect($conf["dbAddress"],$conf["dbAccount"],$conf["dbPassword"]))){
293
 
294
					#設置連線失敗的提示
295
					$result["error"][]="連線失敗,請檢查帳號密碼是否正確.";
296
 
297
					#取得連線時的錯誤編號
298
					$result["error"][]=mysqli_connect_errno();
299
 
300
					#取得連線時的錯誤訊息
301
					$result["error"][]=mysqli_connect_error();
302
 
303
					#設置執行失敗
304
					$result["status"]="false";
305
 
306
					#回傳結果
307
					return $result;
308
 
309
					}#if end
310
 
311
				}#if end
312
 
313
			#反之	
314
			else{
315
 
316
				#設定資料庫位置、帳號、密碼,並連綫
317
				if(!($result["connectInformation"]=@mysqli_connect($conf["dbAddress"].":".$conf["dbPort"],$conf["dbAccount"],$conf["dbPassword"]))){
318
 
319
					#設置連線失敗的提示
320
					$result["error"][]="連線失敗,請檢查帳號密碼是否正確.";
321
 
322
					#取得連線時的錯誤編號
323
					$result["error"][]=mysqli_connect_errno();
324
 
325
					#取得連線時的錯誤訊息
326
					$result["error"][]=mysqli_connect_error();
327
 
328
					#設置執行失敗
329
					$result["status"]="false";
330
 
331
					#回傳結果
332
					return $result;
333
 
334
					}#if end
335
 
336
				}#else end
337
 
338
			}#else end
339
 
340
		#使編碼為utf8
341
		if(!(mysqli_query($result["connectInformation"],'SET NAMES UTF8'))){
342
 
343
			#設置連線編碼失敗的提示
344
			$result["error"][]="設置連線編碼失敗.";
345
 
346
			#取得連線時的錯誤編號
347
			$result["error"][]=mysqli_connect_errno();
348
 
349
			#取得連線時的錯誤訊息
350
			$result["error"][]=mysqli_connect_error();
351
 
352
			#設置執行失敗
353
			$result["status"]="false";
354
 
355
			#回傳結果
356
			return $result;
357
 
358
			}#if end
359
 
360
		#設定 CHARACTER_SET_CLIENT 為 utf8
361
		if(!(mysqli_query($result["connectInformation"],'SET CHARACTER_SET_CLIENT=utf8'))){
362
 
363
			#設置連線編碼失敗的提示
364
			$result["error"][]="設置連線編碼失敗.";
365
 
366
			#取得連線時的錯誤編號
367
			$result["error"][]=mysqli_connect_errno();
368
 
369
			#取得連線時的錯誤訊息
370
			$result["error"][]=mysqli_connect_error();
371
 
372
			#設置執行失敗
373
			$result["status"]="false";
374
 
375
			#回傳結果
376
			return $result;
377
 
378
			}#if end
379
 
380
		#設定 CHARACTER_SET_RESULTS 為 utf8
381
		if(!(mysqli_query($result["connectInformation"],'SET CHARACTER_SET_RESULTS=utf8'))){
382
 
383
			#設置連線編碼失敗的提示
384
			$result["error"][]="設置連線編碼失敗.";
385
 
386
			#取得連線時的錯誤編號
387
			$result["error"][]=mysqli_connect_errno();
388
 
389
			#取得連線時的錯誤訊息
390
			$result["error"][]=mysqli_connect_error();
391
 
392
			#設置執行失敗
393
			$result["status"]="false";
394
 
395
			#回傳結果
396
			return $result;
397
 
398
			}#if end
399
 
400
		#執行正常
401
		$result["status"]="true";
402
 
403
		#回傳結果
404
		return $result;	 
405
 
406
		}#function mysqlConnect end
407
 
408
	/*
409
	#函式說明:
410
	#關閉與mysql的連線,會回傳一個陣列。
43 liveuser 411
	#回傳結果::
1 liveuser 412
	#$result["status"],若連線成功則爲"true",連線失敗則爲"false".
413
	#$result["connectInformation"],爲回傳的mysql連線資訊。
414
	#$result["error"],爲錯誤訊息陣列.	
415
	#必填參數:
343 liveuser 416
	#$conf["mysqli"],字串,mysqli物件.
417
	$conf["mysqli"]=$mysqli;
43 liveuser 418
	#可省略參數:
343 liveuser 419
	#無.
185 liveuser 420
	#參考資料:
421
	#無.
43 liveuser 422
	#備註:
343 liveuser 423
	#無.
1 liveuser 424
	*/	
425
	public static function mysqlClose(&$conf){
426
 
427
		#初始化要回傳的內容
428
		$result=array();
429
 
430
		#取得當前執行的函數名稱
431
		$result["function"]=__FUNCTION__;
432
 
433
		#如果 $conf 不為陣列
434
		if(gettype($conf)!="array"){
435
 
436
			#設置執行失敗
437
			$result["status"]="false";
438
 
439
			#設置執行錯誤訊息
440
			$result["error"][]="\$conf變數須為陣列形態";
441
 
442
			#如果傳入的參數為 null
443
			if($conf==null){
444
 
445
				#設置執行錯誤訊息
446
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
447
 
448
				}#if end
449
 
450
			#回傳結果
451
			return $result;
452
 
453
			}#if end
454
 
455
		#檢查參數
43 liveuser 456
		#函式說明:
1 liveuser 457
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
458
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
459
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
460
		#$result["function"],當前執行的函式名稱.
461
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
462
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
463
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
464
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
465
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
466
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
467
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
43 liveuser 468
		#必填參數:
1 liveuser 469
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
470
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
471
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
343 liveuser 472
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mysqli");
1 liveuser 473
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
343 liveuser 474
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array(null);
1 liveuser 475
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
476
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
43 liveuser 477
		#可省略參數:
1 liveuser 478
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
343 liveuser 479
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1 liveuser 480
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
343 liveuser 481
		#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort");
1 liveuser 482
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
343 liveuser 483
		#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
1 liveuser 484
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
343 liveuser 485
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null);
1 liveuser 486
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
487
		#$conf["arrayCountEqualCheck"][]=array();
43 liveuser 488
		#參考資料:
1 liveuser 489
		#array_keys=>http://php.net/manual/en/function.array-keys.php
490
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
491
		unset($conf["variableCheck::checkArguments"]);
492
 
493
		#如果檢查失敗
494
		if($checkResult["status"]=="false"){
495
 
496
			#設置錯誤識別
497
			$result["status"]="false";
498
 
499
			#設置錯誤訊息
500
			$result["error"]=$checkResult;
501
 
502
			#回傳解果
503
			return $result;
504
 
505
			}#if end
506
 
507
		#如果 $checkResult["status"]等於"false";
508
		if($checkResult["passed"]=="false"){
509
 
510
			#設置錯誤識別
511
			$result["status"]="false";
512
 
513
			#設置錯誤訊息
514
			$result["error"]=$checkResult;
515
 
516
			#回傳解果
517
			return $result;
518
 
519
			}#if end
520
 
521
		#關閉與資料庫的連線如果成功
343 liveuser 522
		if(@mysqli_close($conf["mysqli"])){
1 liveuser 523
 
524
			#則回傳"true"
525
			$result["status"]="true";
526
 
527
			}#if end
528
 
529
		#連線失敗回傳"false"
530
		else{
531
 
532
			#設置連線編碼失敗的提示
533
			$result["error"][]="關閉連線失敗.";
534
 
535
			#取得連線時的錯誤編號
536
			$result["error"][]=mysqli_connect_errno();
537
 
538
			#取得連線時的錯誤訊息
539
			$result["error"][]=mysqli_connect_error();
540
 
541
			#設置執行失敗
542
			$result["status"]="false";
543
 
544
			}#else end
545
 
343 liveuser 546
		#儲存mysqli物件
547
		$result["connectInformation"]=$conf["mysqli"];
1 liveuser 548
 
549
		#設置執行正常
550
		$result["status"]="true";
551
 
552
		#回傳結果
553
		return $result;	 
554
 
555
		}#funciton mysqlClose end
556
 
557
	/*
43 liveuser 558
	#函式說明:
1 liveuser 559
	#連線到資料庫,結果會回傳一個陣列.
560
	#$result["status"],若連線成功則爲"true",連線失敗則爲"false".
561
	#$result["connectInformation"],爲回傳的mysql連線資訊.
562
	#$result["error"],錯誤訊息	.
563
	#$result["function"],當前執行的函數名稱.
564
	#必填參數:
565
	#$conf["dbAddress"],字串,爲mysql-Server的位置。
566
	$conf["dbAddress"]=$dbAddress;
567
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號。
568
	$conf["dbAccount"]=$dbAccount;
569
	#$conf["dbName"],字串,爲要連的資料庫名稱
570
	$conf["dbName"]="";
43 liveuser 571
	#可省略參數:
1 liveuser 572
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
573
	#$conf["dbPassword"]=$dbPassword;
574
	#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
575
	#$conf["dbPort"]="3306";
185 liveuser 576
	#參考資料:
577
	#無.
43 liveuser 578
	#備註:
579
	#無.
1 liveuser 580
	*/
581
	public static function dbConnect(&$conf){
582
 
583
		#初始化要回傳的內容
584
		$result=array();
585
 
586
		#取得當前執行的函數名稱
587
		$result["function"]=__FUNCTION__;
588
 
589
		#如果 $conf 不為陣列
590
		if(gettype($conf)!="array"){
591
 
592
			#設置執行失敗
593
			$result["status"]="false";
594
 
595
			#設置執行錯誤訊息
596
			$result["error"][]="\$conf變數須為陣列形態";
597
 
598
			#如果傳入的參數為 null
599
			if($conf==null){
600
 
601
				#設置執行錯誤訊息
602
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
603
 
604
				}#if end
605
 
606
			#回傳結果
607
			return $result;
608
 
609
			}#if end
610
 
611
		#檢查參數
43 liveuser 612
		#函式說明:
1 liveuser 613
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
614
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
615
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
616
		#$result["function"],當前執行的函式名稱.
617
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
618
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
619
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
620
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
621
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
622
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
623
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
43 liveuser 624
		#必填參數:
1 liveuser 625
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
626
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
627
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
628
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","dbName");
629
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
630
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
631
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
632
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
43 liveuser 633
		#可省略參數:
1 liveuser 634
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
635
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
636
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
637
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort");
638
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
639
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
640
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
641
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null);
642
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
643
		#$conf["arrayCountEqualCheck"][]=array();
43 liveuser 644
		#參考資料:
1 liveuser 645
		#array_keys=>http://php.net/manual/en/function.array-keys.php
646
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
647
		unset($conf["variableCheck::checkArguments"]);
648
 
649
		#如果檢查失敗
650
		if($checkResult["status"]=="false"){
651
 
652
			#設置錯誤識別
340 liveuser 653
			$result["status"]="false";
1 liveuser 654
 
655
			#設置錯誤訊息
656
			$result["error"]=$checkResult;
657
 
658
			#回傳解果
659
			return $result;
660
 
661
			}#if end
662
 
663
		#如果 $checkResult["status"]等於"false";
664
		if($checkResult["passed"]=="false"){
665
 
666
			#設置錯誤識別
340 liveuser 667
			$result["status"]="false";
1 liveuser 668
 
669
			#設置錯誤訊息
670
			$result["error"]=$checkResult;
671
 
672
			#回傳解果
673
			return $result;
674
 
675
			}#if end
676
 
43 liveuser 677
		#函式說明:
1 liveuser 678
		#連線到mysql-server,會回傳一個陣列
679
		#回傳結果:
680
		#$result["status"],若連線成功則爲"true",連線失敗則爲"false"。
681
		#$result["function"],當前執行的函數名稱
682
		#$result["connectInformation"],爲回傳的mysql連線資訊。
683
		#$result["error"],爲錯誤訊息陣列
684
		#必填參數:
685
		$conf["db"]["mysqlConnect"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置。
686
		$conf["db"]["mysqlConnect"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號。
43 liveuser 687
		#可省略參數:
1 liveuser 688
 
689
		#如果 $conf["dbPassword"] 有設定
690
		if(isset($conf["dbPassword"])){
691
 
692
			$conf["db"]["mysqlConnect"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
693
 
694
			}#if end
695
 
696
		#如果有設置 $conf["dbPort"]
697
		if(isset($conf["dbPort"])){
698
 
699
			$conf["db"]["mysqlConnect"]["dbPort"]=$conf["dbPort"];#字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
700
 
701
			}#if end	
702
 
703
		$con=db::mysqlConnect($conf["db"]["mysqlConnect"]);
704
		unset($conf["db"]["mysqlConnect"]);
705
 
706
		#如果連線失敗
707
		if($con["status"]=="false"){
708
 
709
			#提示訊息
710
			$result["error"]=$con;
711
 
712
			#設置執行失敗
713
			$result["status"]="false";
714
 
715
			#回傳結果
716
			return $result;
717
 
718
			}#if end
719
 
720
		#選取資料庫
721
		#如果連線失敗
722
		if(!(mysqli_select_db($con["connectInformation"],$conf["dbName"]))){
723
 
724
			#設置連線失敗的提示
725
			$result["error"][]="選取資料庫失敗";
726
 
727
			#取得連線時的錯誤編號
728
			$result["error"][]=mysqli_connect_errno();
729
 
730
			#取得連線時的錯誤訊息
731
			$result["error"][]=mysqli_connect_error();
732
 
733
			#設置執行失敗
734
			$result["status"]="false";
735
 
736
			#回傳結果
737
			return $result;	 
738
 
739
			}#if end
740
 
741
		#取得mysqli物件
742
		$result["connectInformation"]=$con["connectInformation"];
743
 
744
		#設置執行正常
745
		$result["status"]="true";
746
 
747
		#回傳結果
748
		return $result;	 
749
 
750
		}#function dbConnect end
751
 
752
	/*
43 liveuser 753
	#函式說明:
1 liveuser 754
	#執行mysql指令
43 liveuser 755
	#回傳結果::
1 liveuser 756
	#$result["status"],"true"為執行成功;"false"為執行失敗。
757
	#$result["error"],錯誤訊息的陣列
758
	#$result["function"],當前執行的涵式
759
	#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
760
	#$result["queryConn"],mysql用來查尋的連資源. 
338 liveuser 761
	#$result["queryString"],要執行的sql內容.
1 liveuser 762
	#必填參數:
763
	#$conf["dbSql"],字串,要執行sql語法
764
	$conf["dbSql"]="";
43 liveuser 765
	#可省略參數:
1 liveuser 766
	#$conf["dbLink"],物件,mysqli物件,由mysqli_connect()回傳的物件內容,若為數值則改用賬號密碼等資訊進行連線,反之則沿用連線物件.
767
	$conf["dbLink"]="";
768
	#$conf["dbAddress"],字串,爲mysql-Server的位置。
769
	$conf["dbAddress"]=$dbAddress;
770
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號。
771
	$conf["dbAccount"]=$dbAccount; 
772
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
773
	#$conf["dbPassword"]=$dbPassword;
774
	#$conf["dbName"],字串,爲要連的資料庫名稱
775
	#$conf["dbName"]="";
776
	#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
777
	#$conf["dbPort"]="3306";
345 liveuser 778
	#$conf["autoClose"],字串,"true"代表要自動斷線,預設為"true"會自動斷線
779
	#$conf["autoClose"]="true";
185 liveuser 780
	#參考資料:
781
	#無.
43 liveuser 782
	#備註:
783
	#無.
1 liveuser 784
	*/
785
	public static function execMysqlQuery(&$conf){
786
 
787
		#初始化要回傳的內容
788
		$result=array();
789
 
790
		#取得當前執行的函數名稱
791
		$result["function"]=__FUNCTION__;
792
 
793
		#如果 $conf 不為陣列
794
		if(gettype($conf)!="array"){
795
 
796
			#設置執行失敗
797
			$result["status"]="false";
798
 
799
			#設置執行錯誤訊息
800
			$result["error"][]="\$conf變數須為陣列形態";
801
 
802
			#如果傳入的參數為 null
803
			if($conf===null){
804
 
805
				#設置執行錯誤訊息
806
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
807
 
808
				}#if end
809
 
810
			#回傳結果
811
			return $result;
812
 
813
			}#if end
814
 
815
		#檢查參數
43 liveuser 816
		#函式說明:
1 liveuser 817
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
818
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
819
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
820
		#$result["function"],當前執行的函式名稱.
821
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
822
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
823
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
824
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
825
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
826
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
827
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
43 liveuser 828
		#必填參數:
1 liveuser 829
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
830
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
831
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
832
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbSql");
833
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
834
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
835
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
836
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
43 liveuser 837
		#可省略參數:
1 liveuser 838
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
839
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
840
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
343 liveuser 841
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbLink","dbAddress","dbAccount","dbPassword","dbName","dbPort","autoClose","mysqli");
1 liveuser 842
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
343 liveuser 843
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("object","string","string","string","string","string","string",null);
1 liveuser 844
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
343 liveuser 845
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null,null,null,"true",null);
1 liveuser 846
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
847
		#$conf["arrayCountEqualCheck"][]=array();
43 liveuser 848
		#參考資料:
1 liveuser 849
		#array_keys=>http://php.net/manual/en/function.array-keys.php
850
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
851
		unset($conf["variableCheck::checkArguments"]);
852
 
853
		#如果檢查失敗
854
		if($checkResult["status"]=="false"){
855
 
856
			#設置錯誤識別
857
			$result["status"]="fasle";
858
 
859
			#設置錯誤訊息
860
			$result["error"]=$checkResult;
861
 
862
			#回傳解果
863
			return $result;
864
 
865
			}#if end
866
 
867
		#如果 $checkResult["status"]等於"false";
343 liveuser 868
		if($checkResult["passed"]==="false"){
1 liveuser 869
 
870
			#設置錯誤識別
871
			$result["status"]="fasle";
872
 
873
			#設置錯誤訊息
874
			$result["error"]=$checkResult;
875
 
876
			#回傳解果
877
			return $result;
878
 
879
			}#if end
880
 
881
		#如果沒有 dbLink
882
		if(!isset($conf["dbLink"])){
883
 
884
			#初始化儲存mysqli物件的變數
885
			$con="";
886
 
887
			#如果有指定資料庫
888
			if(isset($conf["dbName"])){
889
 
43 liveuser 890
				#函式說明:
1 liveuser 891
				#連線到資料庫,結果會回傳一個陣列.
892
				#$result["status"],若連線成功則爲"true",連線失敗則爲"false".
893
				#$result["connectInformation"],爲回傳的mysql連線資訊.
894
				#$result["error"],錯誤訊息	.
895
				#$result["function"],當前執行的函數名稱.
43 liveuser 896
				#必填參數:
1 liveuser 897
				$conf["db::dbConnect"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
898
				$conf["db::dbConnect"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
899
				$conf["db::dbConnect"]["dbName"]=$conf["dbName"];#爲要連的資料庫名稱
43 liveuser 900
				#可省略參數:
1 liveuser 901
 
902
				#如果 $conf["dbPassword"] 有設置
903
				if(isset($conf["dbPassword"])){
904
 
905
					$conf["db::dbConnect"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
906
 
907
					}#if end
908
 
909
				#如果有設置 $conf["dbPort"] 
910
				if(isset($conf["dbPort"])){
911
 
912
					#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
913
					$conf["db::dbConnect"]["dbPort"]=$conf["dbPort"];
914
 
915
					}#if end
916
 
917
				$con=db::dbConnect($conf["db::dbConnect"]);
918
				unset($conf["db::dbConnect"]);
919
 
920
				#如果連線失敗
921
				if($con["status"]=="false"){
922
 
923
					#設置執行失敗的訊息
924
					$result["status"]="false";
925
 
926
					#紀錄錯誤訊息
927
					$result["error"]=$con;
928
 
929
					#回傳結果
930
					return $result;
931
 
932
					}#if end
933
 
934
				#儲存mysqli物件
935
				$result["queryConn"]=$con["connectInformation"];
936
 
937
				}#if end
938
 
939
			#反之沒有指定資料庫	
940
			else{
941
 
942
				#連線到mysql
43 liveuser 943
				#函式說明:
1 liveuser 944
				#連線到mysql-server,會回傳一個陣列
945
				#回傳結果:
946
				#$result["connectStatus"],若連線成功則爲0,連線失敗則爲1。
947
				#$result["connectInformation"],爲回傳的mysql連線資訊。
948
				#$result["error"],爲錯誤訊息
949
				#必填參數:
950
				$conf["db"]["mysqlConnect"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置。
951
				$conf["db"]["mysqlConnect"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號。
43 liveuser 952
				#可省略參數:
1 liveuser 953
 
954
				#如果 $conf["dbPassword"] 有設置
955
				if(isset($conf["dbPassword"])){
956
 
957
					$conf["db"]["mysqlConnect"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
958
 
959
					}#if end
960
 
961
				#如果有設置 $conf["dbPort"] 
962
				if(isset($conf["dbPort"])){
963
 
964
					#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
965
					$conf["db::dbConnect"]["dbPort"]=$conf["dbPort"];
966
 
967
					}#if end
968
 
969
				$con=db::mysqlConnect($conf["db"]["mysqlConnect"]);
970
				unset($conf["db"]);
971
 
972
				#如果連線失敗
973
				if($con["status"]=="false"){
974
 
975
					#設置執行失敗的訊息
976
					$result["status"]="false";
977
 
978
					#紀錄錯誤訊息
979
					$result["error"]=$con;
980
 
981
					#回傳結果
982
					return $result;
983
 
984
					}#if end
985
 
986
				#儲存mysqli物件
987
				$result["queryConn"]=$con["connectInformation"];	
988
 
989
				}#else end
990
 
991
			}#if end
992
 
993
		#反之存在 $conf["dbLink"]
994
		else{
995
 
996
			#取得db物件
997
			$result["queryConn"]=$conf["dbLink"];
998
 
999
			}#else end
1000
 
337 liveuser 1001
		#設置sql的查詢語言
1002
		$result["queryStringOri"]=$conf["dbSql"];
1 liveuser 1003
 
338 liveuser 1004
		#設置sql的查詢語言
1005
		$result["queryString"]=$conf["dbSql"];
337 liveuser 1006
 
1 liveuser 1007
		#進行查詢
1008
		#如果有錯誤訊息
1009
		if(!($mysqli_query=mysqli_query($result["queryConn"],$result["queryString"]))){
1010
 
1011
			#設置執行失敗的訊息
1012
			$result["status"]="false";
1013
 
1014
			#設置提示執行mysql語法失敗
1015
			$result["error"][]="執行mysql語法失敗";
1016
 
1017
			#取得錯誤訊息
1018
			$result["error"]["mysqlErrorNo"]=mysqli_errno($result["queryConn"]);
1019
			$result["error"]["mysqlErrorDetail"]=mysqli_error($result["queryConn"]);
1020
 
1021
			#回傳結果
1022
			return $result;
1023
 
1024
			}#if end
1025
 
1026
		#取得正確的mysqli_resource
1027
		$result["queryResource"]=$mysqli_query;
1028
 
1029
		#如果要自動斷線
1030
		if($conf["autoClose"]==="true"){
1031
 
1032
			#連線結束
1033
			#函式說明:
1034
			#關閉與mysql的連線,會回傳一個陣列。
43 liveuser 1035
			#回傳結果::
1 liveuser 1036
			#$result["status"],若連線成功則爲"true",連線失敗則爲"false".
1037
			#$result["connectInformation"],爲回傳的mysql連線資訊。
1038
			#$result["error"],爲錯誤訊息陣列.		
43 liveuser 1039
			#必填參數:
343 liveuser 1040
			#$conf["mysqli"],字串,mysqli物件.
1041
			$conf["db::mysqlClose"]["mysqli"]=$result["queryConn"];
344 liveuser 1042
			$mysqlClose=db::mysqlClose($conf["db::mysqlClose"]);
343 liveuser 1043
			unset($conf["db::mysqlClose"]);
1 liveuser 1044
 
1045
			#如果關閉mysql連線失敗
1046
			if($mysqlClose["status"]=="false"){
1047
 
1048
				#設置執行失敗的訊息
1049
				$result["status"]="false";
1050
 
1051
				#紀錄錯誤訊息
1052
				$result["error"]=$mysqlClose;
1053
 
1054
				#回傳結果
1055
				return $result;
1056
 
1057
				}#if end
1058
 
1059
			}#if end
1060
 
1061
		#設置執行成功的訊息
1062
		$result["status"]="true";	
1063
 
1064
		#回傳查詢後的結果
1065
		return $result;
1066
 
1067
		}#function execMysqlQuery end
1068
 
1069
	/*
43 liveuser 1070
	#函式說明:
1 liveuser 1071
	#用shell執行mysql指令.
43 liveuser 1072
	#回傳結果::
1 liveuser 1073
	#$result["status"],"true"為執行成功;"false"為執行失敗。
1074
	#$result["error"],錯誤訊息的陣列
1075
	#$result["function"],當前執行的涵式
1076
	#$result["queryString"],mysql查詢的語言.
1077
	#必填參數:
1078
	#$conf["fileArgu"],字串,變數__FILE__的內容.
1079
	$conf["fileArgu"]=__FILE__;
1080
	#$conf["dbSql"],字串,要執行sql語法
1081
	$conf["dbSql"]="";
1082
	#$conf["dbAddress"],字串,爲mysql-Server的位置。
1083
	$conf["dbAddress"]=$dbAddress;
1084
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號。
1085
	$conf["dbAccount"]=$dbAccount; 
43 liveuser 1086
	#可省略參數:
288 liveuser 1087
	#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
1088
	#$conf["pre"]=array();
1 liveuser 1089
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
1090
	#$conf["dbPassword"]=$dbPassword;
1091
	#$conf["dbName"],字串,爲要連的資料庫名稱
1092
	#$conf["dbName"]="";
1093
	#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
1094
	#$conf["dbPort"]="3306";
185 liveuser 1095
	#參考資料:
1096
	#無.
43 liveuser 1097
	#備註:
1098
	#無.
1 liveuser 1099
	*/
1100
	public static function shell(&$conf){
1101
 
1102
		#初始化要回傳的內容
1103
		$result=array();
1104
 
1105
		#取得當前執行的函數名稱
1106
		$result["function"]=__FUNCTION__;
1107
 
1108
		#如果 $conf 不為陣列
1109
		if(gettype($conf)!="array"){
1110
 
1111
			#設置執行失敗
1112
			$result["status"]="false";
1113
 
1114
			#設置執行錯誤訊息
1115
			$result["error"][]="\$conf變數須為陣列形態";
1116
 
1117
			#如果傳入的參數為 null
1118
			if($conf===null){
1119
 
1120
				#設置執行錯誤訊息
1121
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1122
 
1123
				}#if end
1124
 
1125
			#回傳結果
1126
			return $result;
1127
 
1128
			}#if end
1129
 
1130
		#檢查參數
43 liveuser 1131
		#函式說明:
1 liveuser 1132
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1133
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1134
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
1135
		#$result["function"],當前執行的函式名稱.
1136
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1137
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1138
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
1139
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
1140
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
1141
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
1142
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
43 liveuser 1143
		#必填參數:
1 liveuser 1144
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
1145
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
1146
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
1147
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","dbSql","dbAccount");
1148
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
1149
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
1150
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
1151
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
43 liveuser 1152
		#可省略參數:
1 liveuser 1153
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
1154
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
1155
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
1156
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pre","dbAddress","dbPassword","dbName","dbPort");
1157
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
288 liveuser 1158
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","string","string");
1 liveuser 1159
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
1160
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,"localhost",null,null,"3306");
1161
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
1162
		#$conf["arrayCountEqualCheck"][]=array();
43 liveuser 1163
		#參考資料:
1 liveuser 1164
		#array_keys=>http://php.net/manual/en/function.array-keys.php
1165
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
1166
		unset($conf["variableCheck::checkArguments"]);
1167
 
1168
		#如果檢查失敗
1169
		if($checkResult["status"]=="false"){
1170
 
1171
			#設置錯誤識別
329 liveuser 1172
			$result["status"]="false";
1 liveuser 1173
 
1174
			#設置錯誤訊息
1175
			$result["error"]=$checkResult;
1176
 
1177
			#回傳解果
1178
			return $result;
1179
 
1180
			}#if end
1181
 
1182
		#如果 $checkResult["status"]等於"false";
1183
		if($checkResult["passed"]=="false"){
1184
 
1185
			#設置錯誤識別
1186
			$result["status"]="false";
1187
 
1188
			#設置錯誤訊息
1189
			$result["error"]=$checkResult;
1190
 
1191
			#回傳解果
1192
			return $result;
1193
 
1194
			}#if end
1195
 
1196
		#shell不接受「`」
43 liveuser 1197
		#函式說明:
1 liveuser 1198
		#處理字串避免網頁出錯
43 liveuser 1199
		#回傳結果::
1 liveuser 1200
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1201
		#$result["function"],當前執行的函數.
1202
		#$result["content"],爲處理好的字串.
1203
		#$result["error"],錯誤訊息陣列.
1204
		#$result["argu"],使用的參數. 
43 liveuser 1205
		#必填參數:
1 liveuser 1206
		$conf["stringProcess::correctCharacter"]["stringIn"]=$conf["dbSql"];#爲要處理的字串
43 liveuser 1207
		#可省略參數:
1 liveuser 1208
		$conf["stringProcess::correctCharacter"]["selectedCharacter"]=array("`");#爲被選擇要處理的字串/字元,須爲陣列值。
1209
			#若不設定則預設爲要將這些字串作替換 ("<",">","=","//","'","$","%","&","|","/*","*","#","\"").
1210
			#特殊字元,「\n」代表換行,「\t」代表tab鍵的間隔
1211
		$conf["stringProcess::correctCharacter"]["changeTo"]=array("");#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串).
1212
		#備註:
1213
		#無.
1214
		$correctCharacter=stringProcess::correctCharacter($conf["stringProcess::correctCharacter"]);
1215
		unset($conf["stringProcess::correctCharacter"]);
1216
 
1217
		#如果檢查失敗
1218
		if($correctCharacter["status"]=="false"){
1219
 
1220
			#設置錯誤識別
1221
			$result["status"]="false";
1222
 
1223
			#設置錯誤訊息
1224
			$result["error"]=$correctCharacter;
1225
 
1226
			#回傳解果
1227
			return $result;
1228
 
1229
			}#if end
1230
 
1231
		#取得處理後的 sql
1232
		$sql=$correctCharacter["content"];	
1233
 
325 liveuser 1234
		#避免亂碼
326 liveuser 1235
		$sql="SET NAMES UTF8;"."SET CHARACTER_SET_CLIENT=utf8;"."SET CHARACTER_SET_RESULTS=utf8;".$sql;
325 liveuser 1236
 
1 liveuser 1237
		#初始化參數
1238
		$argu=array();
1239
 
1240
		#精簡的參數
320 liveuser 1241
		$argu[]=$sql;
1 liveuser 1242
		$argu[]="|";
1243
		$argu[]="mysql";
1244
		$argu[]="-u";
1245
		$argu[]=$conf["dbAccount"];	
1246
 
1247
		#如果有設置 $conf["dbPassword"]
1248
		if(isset($conf["dbPassword"])){
1249
 
1250
			#加上密碼參數
1251
			$argu[]="-p".$conf["dbPassword"];
1252
 
1253
			}#if end
1254
 
1255
		#加上 位置參數
1256
		$argu[]="-h".$conf["dbAddress"];
1257
 
1258
		#如果有設置 $conf["dbName"]
1259
		if(isset($conf["dbName"])){
1260
 
1261
			#加上資料庫名稱參數
1262
			$argu[]=$conf["dbName"];
1263
 
1264
			}#if end
1265
 
443 liveuser 1266
		#建立暫存的檔案
1267
 
1268
		#將指令寫入暫存的檔案裡面
1269
 
43 liveuser 1270
		#函式說明:
1 liveuser 1271
		#呼叫shell執行系統命令,並取得回傳的內容.
43 liveuser 1272
		#回傳結果:
1 liveuser 1273
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1274
		#$result["error"],錯誤訊息陣列.
1275
		#$result["function"],當前執行的函數名稱.
1276
		#$result["argu"],使用的參數.
1277
		#$result["cmd"],執行的指令內容.
1278
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
1279
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
1280
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
1281
		#$result["running"],是否還在執行.
1282
		#$result["pid"],pid.
1283
		#$result["statusCode"],執行結束後的代碼.
1284
		#必填的參數
288 liveuser 1285
		#$conf["command"],字串,要執行的指令與.
1286
		$conf["external::callShell"]["command"]="echo";
1 liveuser 1287
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1288
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];		
1289
		#可省略參數:
1290
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
1291
		$conf["external::callShell"]["argu"]=$argu;
1292
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
1293
		#$conf["arguIsAddr"]=array();	
288 liveuser 1294
 
310 liveuser 1295
		#如果有參數
313 liveuser 1296
		if(count($argu)>0){
310 liveuser 1297
 
324 liveuser 1298
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
1299
			$conf["external::callShell"]["thereIsShellVar"]=array();
1300
 
310 liveuser 1301
			#針對每個參數
314 liveuser 1302
			for($i=0;$i<count($argu);$i++){
310 liveuser 1303
 
1304
				#第一個參數
1305
				if($i===0){
1306
 
324 liveuser 1307
					#含有shell變數
1308
					$conf["external::callShell"]["thereIsShellVar"][$i]="true";
310 liveuser 1309
 
1310
					}#if end
1311
 
1312
				#反之
1313
				else{
1314
 
324 liveuser 1315
					#不含有shell變數
1316
					$conf["external::callShell"]["thereIsShellVar"][$i]="false";
310 liveuser 1317
 
1318
					}#else 
1319
 
1320
				}#for end
1321
 
1322
			}#if end
1323
 
288 liveuser 1324
		#如果有設置 pre
1325
		if(isset($conf["pre"])){
1326
 
1327
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
1328
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
1329
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
1330
			$conf["external::callShell"]["pre"]=$conf["pre"];
1331
 
1332
			}#if end
1333
 
1 liveuser 1334
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
1335
		#$conf["enablePrintDescription"]="true";
1336
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
1337
		#$conf["printDescription"]="";
1338
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
283 liveuser 1339
		$conf["external::callShell"]["escapeshellarg"]="true";
1 liveuser 1340
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
1341
		#$conf["username"]="";
1342
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
1343
		#$conf["password"]="";
1344
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
1345
		#$conf["useScript"]="";
1346
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
1347
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
1348
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
1349
		#$conf["inBackGround"]="";
1350
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
1351
		#$conf["getErr"]="false";
329 liveuser 1352
		#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
1353
		$conf["external::callShell"]["doNotRun"]="true";
1 liveuser 1354
		#備註:
1355
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
1356
		#參考資料:
1357
		#exec=>http://php.net/manual/en/function.exec.php
1358
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
1359
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
1360
		$callShell=external::callShell($conf["external::callShell"]);
1361
		unset($conf["external::callShell"]);
1362
 
443 liveuser 1363
		#debug
1364
		#var_dump($callShell);
1365
		#exit;
1366
 
1 liveuser 1367
		#如果檢查參數作業出錯
1368
		if($callShell["status"]=="false"){
1369
 
329 liveuser 1370
			/* debug
328 liveuser 1371
			$fsock=fopen("/var/www/html/log/log.txt","a");
1372
			fwrite($fsock,"func:".__CLASS__." line:".__LINE__.":".print_r($callShell,true).PHP_EOL.PHP_EOL);
1373
			fclose($fsock);
329 liveuser 1374
			*/
328 liveuser 1375
 
1 liveuser 1376
			#設置執行錯誤識別
1377
			$result["status"]="false";
1378
 
1379
			#設置錯誤訊息
1380
			$result["error"]=$callShell;
1381
 
1382
			#回傳結果
1383
			return $result;
1384
 
1385
			}#if end
329 liveuser 1386
 
1387
		#函式說明:
1388
		#連線到 unixDomainSockServer 提供的 unix domain socket.
1389
		#回傳結果:
1390
		#$result["status"],"true"代表執行正常;"false"代表執行不正常.
1391
		#$result["error"],錯誤訊息陣列.
1392
		#$result["function"],當前執行的函式名稱.
1393
		#$result["content"],取得的回應.
1394
		#必填參數:
1395
		#$conf["sock"],字串,要連線的unix domain socket.
334 liveuser 1396
		$conf["sock::unixDomainSockClient"]["sock"]=qbpwcf_usock_path;
329 liveuser 1397
		#可省略參數:
1398
		#$conf["id"],字串,取得的id,若無此值,則會得到新的數值.
1399
		#$conf["id"]="";
1400
		#$conf["cmd"],字串,要執行的指令,當$conf["id"]參數合法時,才會執行.
443 liveuser 1401
		$conf["sock::unixDomainSockClient"]["cmd"]=$callShell["escape"]["cmd"];
329 liveuser 1402
		#$conf["param"],參數陣列.
443 liveuser 1403
		$conf["sock::unixDomainSockClient"]["param"]=$callShell["escape"]["argu"];
1404
		#$conf["escaped"],字串,param參數是否已經escaped了,預設為"false",反之為"true".
1405
		$conf["sock::unixDomainSockClient"]["escaped"]="true";
329 liveuser 1406
		#$conf["clear"],字串,設為"true"代表要清除過期的用戶連線.
1407
		#$conf["clear"]="true";
1408
		#參考資料:
1409
		#http://php.net/manual/en/function.stream-socket-client.php
1410
		#http://php.net/manual/en/function.stream-get-contents.php
1411
		#備註:
1412
		#無.
443 liveuser 1413
		$paramsOfUnixDomainSockClient=$conf["sock::unixDomainSockClient"];
329 liveuser 1414
		$unixDomainSockClient=sock::unixDomainSockClient($conf["sock::unixDomainSockClient"]);
1415
		unset($conf["sock::unixDomainSockClient"]);
1416
 
1417
		#如果執行失敗
1418
		if($unixDomainSockClient["status"]==="false"){
1419
 
1420
			#設置執行錯誤識別
1421
			$result["status"]="false";
1 liveuser 1422
 
329 liveuser 1423
			#設置錯誤訊息
1424
			$result["error"]=$unixDomainSockClient;
1425
 
1426
			#回傳結果
1427
			return $result;
1428
 
1429
			}#if end
1430
 
443 liveuser 1431
		#取得json回應
1432
		$jsonRes=json_decode($unixDomainSockClient["content"]);
1433
 
1434
		#如果執行失敗
1435
		if($jsonRes===null){
1436
 
1437
			#設置執行錯誤識別
1438
			$result["status"]="false";
1439
 
1440
			#設置錯誤訊息
1441
			$result["error"]=$unixDomainSockClient;
1442
 
1443
			#回傳結果
1444
			return $result;
1445
 
1446
			}#if end
1447
 
1448
		#如果沒有產生新id
1449
		if(!isset($jsonRes->id)){
1450
 
1451
			#設置執行錯誤識別
1452
			$result["status"]="false";
1453
 
1454
			#設置錯誤訊息
1455
			$result["error"]=$unixDomainSockClient;
1456
 
1457
			#回傳結果
1458
			return $result;
1459
 
1460
			}#if end
1461
 
1462
		#用新的id再傳送一次要求給 qbpwcf_usock_path
1463
		$paramsOfUnixDomainSockClient["id"]=$jsonRes->id;		
1464
		$unixDomainSockClient=sock::unixDomainSockClient($paramsOfUnixDomainSockClient);
1465
		unset($paramsOfUnixDomainSockClient);
1466
 
1467
		#var_dump($unixDomainSockClient);
1468
 
1469
		#如果執行失敗
1470
		if($unixDomainSockClient["status"]==="false"){
1471
 
1472
			#設置執行錯誤識別
1473
			$result["status"]="false";
1474
 
1475
			#設置錯誤訊息
1476
			$result["error"]=$unixDomainSockClient;
1477
 
1478
			#回傳結果
1479
			return $result;
1480
 
1481
			}#if end
1482
 
1 liveuser 1483
		#執行正常
1484
		$result["status"]="true";
1485
 
298 liveuser 1486
		#設置執行的結果
443 liveuser 1487
		$result["content"]=$unixDomainSockClient;
298 liveuser 1488
 
1 liveuser 1489
		#回傳結果
1490
		return $result;
1491
 
1492
		}#function shell end
1493
 
1494
	/*
43 liveuser 1495
	#函式說明:
1 liveuser 1496
	#建立資料庫,會回傳一個陣列。
1497
	#回傳結果:
1498
	#$result["status"],成功爲"true",失敗爲"false".
1499
	#$result["error"],錯誤訊息.
1500
	#$result["function"],當前執行的函數名稱.
1501
	#必填參數:
1502
	#$conf["dbAddress"],字串,爲mysql-Server的位置。
1503
	$conf["dbAddress"]=$dbAddress;
1504
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號。
1505
	$conf["dbAccount"]=$dbAccount;
1506
	#$conf["newDatabaseName"],字串,爲要新增的資料庫名稱.
1507
	$conf["newDatabaseName"]="";
5 liveuser 1508
	#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,預設為3306.
1509
	$conf["dbPort"]="3306";
43 liveuser 1510
	#可省略參數: 
1 liveuser 1511
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
1512
	#$conf["dbPassword"]=$dbPassword;
1513
	#$conf["dbName"],字串,爲要連的資料庫名稱
1514
	#$conf["dbName"]="";
1515
	#參考資料:
1516
	#maraiDB-createDatabase => https://mariadb.com/kb/en/mariadb/mariadb-documentation/data-types/string-data-types/data-types-character-sets-and-collations/setting-character-sets-and-collations/
43 liveuser 1517
	#備註:
1518
	#無.
1 liveuser 1519
	*/
1520
	public static function createDatabase($conf){
1521
 
1522
		#初始化錯誤訊息 
1523
		$result=array();
1524
 
1525
		#取得當前執行的函數名稱
1526
		$result["function"]=__FUNCTION__;
1527
 
1528
		#如果 $conf 不為陣列
1529
		if(gettype($conf)!="array"){
1530
 
1531
			#設置執行失敗
1532
			$result["status"]="false";
1533
 
1534
			#設置執行錯誤訊息
1535
			$result["error"][]="\$conf變數須為陣列形態";
1536
 
1537
			#如果傳入的參數為 null
1538
			if($conf==null){
1539
 
1540
				#設置執行錯誤訊息
1541
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1542
 
1543
				}#if end
1544
 
1545
			#回傳結果
1546
			return $result;
1547
 
1548
			}#if end
1549
 
1550
		#檢查參數
43 liveuser 1551
		#函式說明:
1 liveuser 1552
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 1553
		#回傳結果:
1 liveuser 1554
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1555
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1556
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 1557
		#必填參數:
1 liveuser 1558
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
1559
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbPassword","newDatabaseName","dbPort");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 1560
		#可省略參數:
1 liveuser 1561
		$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
1562
		#$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
1563
		#備註:
1564
		#功能與checkExistAndType函式相同
1565
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
1566
		unset($conf["variableCheck"]["isexistMuti"]);
1567
 
1568
		#如果 $checkResult["passed"] 等於 "fasle"
1569
		if($checkResult["passed"]=="false"){
1570
 
1571
			#設置錯誤識別
1572
			$result["status"]="false";
1573
 
1574
			#設置錯誤訊息
1575
			$result["error"]=$checkResult;
1576
 
1577
			#回傳結果
1578
			return $result;
1579
 
1580
			}#if end
1581
 
1582
		#建立資料庫的sql語法
1583
		$sql="CREATE DATABASE ".$conf["newDatabaseName"]."  CHARACTER SET='utf8' COLLATE='utf8_unicode_ci'";
1584
 
43 liveuser 1585
		#函式說明:
1 liveuser 1586
		#執行mysql指令
43 liveuser 1587
		#回傳結果::
1 liveuser 1588
		#$result["status"],"true"為執行成功;"false"為執行失敗。
1589
		#$result["error"],錯誤訊息的陣列
1590
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
1591
		#$result["queryString"],mysql查詢的語言
1592
		#查詢號的解果,需要解析。
43 liveuser 1593
		#必填參數:
1 liveuser 1594
		$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
1595
		$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
1596
		$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
43 liveuser 1597
		#可省略參數: 
1 liveuser 1598
 
1599
		#如果 $conf["dbPassword"] 有設定
1600
		if(isset($conf["dbPassword"])){
1601
 
1602
			$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
1603
 
1604
			}#if end
443 liveuser 1605
 
1 liveuser 1606
		#如果 $conf["dbPort"] 有設定
1607
		if(isset($conf["dbPort"])){
1608
 
1609
			#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
1610
			$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
1611
 
1612
			}#if end
1613
 
1614
		$db["execMysqlQuery"]=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
1615
		unset($conf["db"]["execMysqlQuery"]);
1616
 
1617
		#如果 $db["execMysqlQuery"]["status"] 等於 "false"
1618
		if($db["execMysqlQuery"]["status"]=="false"){
1619
 
1620
			#設置錯誤識別
1621
			$result["status"]="false";
1622
 
1623
			#設置錯誤訊息
1624
			$result["error"]=$db["execMysqlQuery"];
1625
 
1626
			#回傳結果
1627
			return $result;
1628
 
1629
			}#if end
1630
 
1631
		#執行道這邊代表執行正確
1632
		$result["status"]="true";
1633
 
1634
		#回傳結果
1635
		return $result;
1636
 
1637
		}#function createDatabase end
1638
 
1639
	/*
43 liveuser 1640
	#函式說明:
1 liveuser 1641
	#建立資料表,會回傳一個陣列。
43 liveuser 1642
	#回傳結果:
1 liveuser 1643
	#$result["status"],若成功則爲"true",失敗則爲"false"。
1644
	#$result["error"],錯誤訊息的陣列。
1645
	#$result["sql"],要執行的sql語法。
1646
	#$result["function"],當前執行的函數名稱.
43 liveuser 1647
	#必填參數:
1 liveuser 1648
	#$conf["dbAddress"],字串,爲mysql-Server的位置
1649
	$conf["dbAddress"]=$dbAddress;
1650
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
1651
	$conf["dbAccount"]=$dbAccount;
1652
	#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱	
1653
	$conf["selectedDataBaseName"]=$dbName;
1654
	#$conf["newDataTableName"],字串,爲要新增的資料表名稱.
1655
	$conf["newDataTableName"]="";
1656
	#$conf["newDataTableColmunName"],字串,為新資料表的欄位名稱.
1657
	$conf["newDataTableColmunName"]=array("id","lastUpdatedTime");
43 liveuser 1658
	#$conf["newDataTableColmunType"],字串陣列,為新資料表的欄位儲存的型態,常見的有:int,用來儲存整數;double,用來儲存有小數點的數值;timestamp,用來儲存時間;char,用來儲存任何東西,儲存成字元
1 liveuser 1659
	$conf["newDataTableColmunType"]=array("int","timestamp");
43 liveuser 1660
	#$conf["newDataTableColmunDefault"],字串陣列,為該欄位的預設值,若為currentTime則為當前時間;若為updatedCurrentTime則為初始為當前時間,之後每更動一次就更新為當次時間;若為null則代表空值;若為""則為不設定;以外的內容視為指定的數值.
1 liveuser 1661
	$conf["newDataTableColmunDefault"]=array("","updatedCurrentTime");
43 liveuser 1662
	#$conf["newDataTableColmunLength"],字串陣列,為新資料表的欄位儲存的長度,""代表不指定長度.
1 liveuser 1663
	$conf["newDataTableColmunLength"]=array("","");
43 liveuser 1664
	#$conf["newDataTableColmunNull"],字串陣列,為新資料表的欄位是否可為NULL.若為no則代表不能為null;若為yes則代表可以為null.
1 liveuser 1665
	$conf["newDataTableColmunNull"]=array("no","no");	
1666
	#$conf["newDataTableColmunAutoAdd"],字串陣列,為新資料表的欄位是否自動+1
1667
	$conf["newDataTableColmunAutoAdd"]=array("true","");
43 liveuser 1668
	#$conf["newDataTableColmunKeyType"],字串陣列,為該欄位的鍵屬性:primary key代表主鍵;留"",代表不指定。
1 liveuser 1669
	$conf["newDataTableColmunKeyType"]=array("primary key","");
43 liveuser 1670
	#可省略參數:
1 liveuser 1671
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
1672
	#$conf["dbPassword"]=$dbPassword;
1673
	#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
1674
	#$conf["dbPort"]="3306";
185 liveuser 1675
	#參考資料:
1676
	#無.
43 liveuser 1677
	#備註:
1678
	#無.
1 liveuser 1679
	*/
1680
	public static function createDataTable($conf){
1681
 
1682
		#初始化要回傳的結果
1683
		$result=array();
1684
 
1685
		#取得當前執行的函數名稱
1686
		$result["function"]=__FUNCTION__;
1687
 
1688
		#如果 $conf 不為陣列
1689
		if(gettype($conf)!="array"){
1690
 
1691
			#設置執行失敗
1692
			$result["status"]="false";
1693
 
1694
			#設置執行錯誤訊息
1695
			$result["error"][]="\$conf變數須為陣列形態";
1696
 
1697
			#如果傳入的參數為 null
1698
			if($conf==null){
1699
 
1700
				#設置執行錯誤訊息
1701
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1702
 
1703
				}#if end
1704
 
1705
			#回傳結果
1706
			return $result;
1707
 
1708
			}#if end
1709
 
43 liveuser 1710
		#函式說明:
1 liveuser 1711
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 1712
		#回傳結果:
1 liveuser 1713
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
1714
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
1715
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 1716
		#必填參數:
1 liveuser 1717
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
1718
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","newDataTableName","newDataTableColmunName","newDataTableColmunType","newDataTableColmunLength","newDataTableColmunDefault","newDataTableColmunNull","newDataTableColmunAutoAdd","newDataTableColmunKeyType");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 1719
		#可省略參數:
1 liveuser 1720
		#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
1721
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
1722
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
1723
		unset($conf["variableCheck"]["isexistMuti"]);
1724
 
1725
		#如果檢查動作不正常
1726
		if($checkResult["status"]=="false"){
1727
 
1728
			#設置執失敗訊息
1729
			$result["status"]="false";
1730
 
1731
			#設置錯誤訊息
1732
			$result["error"]=$checkResult;
1733
 
1734
			#回傳錯誤訊息
1735
			return $result;
1736
 
1737
			}#if end
1738
 
1739
		#如果檢查不通過
1740
		if($checkResult["passed"]=="false"){
1741
 
1742
			#設置執失敗訊息
1743
			$result["status"]="false";
1744
 
1745
			#設置錯誤訊息
1746
			$result["error"]=$checkResult;
1747
 
1748
			#回傳錯誤訊息
1749
			return $result;
1750
 
1751
			}#if end
1752
 
1753
		#建立資料表的語法
1754
		$sql="create table ".$conf["selectedDataBaseName"].".".$conf["newDataTableName"];
1755
 
1756
		#加上指定欄位內容的開頭
1757
		$sql=$sql."(";
1758
 
1759
		#針對每個欄位
1760
		for($i=0;$i<count($conf["newDataTableColmunName"]);$i++){
1761
 
1762
			#接上欄位名稱
1763
			$sql=$sql.$conf["newDataTableColmunName"][$i];
1764
 
1765
			#接上欄位儲存型態
1766
			$sql=$sql." ".$conf["newDataTableColmunType"][$i];
1767
 
1768
			#如果有設定資料長度
1769
			if($conf["newDataTableColmunLength"][$i]!=""){
1770
 
1771
				#接上欄位儲存長度
1772
				$sql=$sql." (".$conf["newDataTableColmunLength"][$i].")";
1773
 
1774
				}#if end
1775
 
1776
			#如果有設定值
1777
			if($conf["newDataTableColmunDefault"][$i]!=""){
1778
 
1779
				switch($conf["newDataTableColmunDefault"][$i]){
1780
 
1781
					#如果設為 currentTime
1782
					case "currentTime":
1783
 
1784
						#設定語法
1785
						$sql=$sql." default CURRENT_TIMESTAMP";
1786
 
1787
						#跳出switch
1788
						break;
1789
 
1790
					#如果設為updatedCurrentTime
1791
					case "updatedCurrentTime":
1792
 
1793
						#設定語法
1794
						$sql=$sql." default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP";
1795
 
1796
						#跳出switch
1797
						break;
1798
 
1799
					#如果設為 null
1800
					case "null":
1801
 
1802
						#設定語法
1803
						$sql=$sql." default null";
1804
 
1805
						#跳出switch
1806
						break;
1807
 
1808
					#如果不為以上數值
1809
					default :
1810
 
1811
						#設定語法
1812
						$sql=$sql." default ".$conf["newDataTableColmunDefault"][$i];
1813
 
1814
						#跳出switch
1815
						break;
1816
 
1817
					}#switch end
1818
 
1819
				}#if end
1820
 
1821
			#如果有設定不能為NULL
1822
			if($conf["newDataTableColmunNull"][$i]=="no"){
1823
 
1824
				$sql=$sql." NOT NULL";
1825
 
1826
				}#if end
1827
 
1828
			#如果有設定要自動加1
1829
			if($conf["newDataTableColmunAutoAdd"][$i]=="true"){
1830
 
1831
				#加上自動加1的語句
1832
				$sql=$sql." auto_increment";
1833
 
1834
				}#if end
1835
 
1836
			#如果有設定鍵的屬性
1837
			if($conf["newDataTableColmunKeyType"][$i]!=""){
1838
 
1839
				$sql=$sql." ".$conf["newDataTableColmunKeyType"][$i];
1840
 
1841
				}#if end
1842
 
1843
			#如果不是最後一個欄位
1844
			if($i!=count($conf["newDataTableColmunName"])-1){
1845
 
1846
				#加上逗號
1847
				$sql=$sql.",";					
1848
 
1849
				}#if end
1850
 
1851
			}#for end
1852
 
1853
		#加上指定欄位內容的結束
1854
		$sql=$sql.") DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;";
1855
 
1856
		#取得sql語法
1857
		$result["sql"]=$sql;
1858
 
1859
		#var_dump($sql);
1860
 
43 liveuser 1861
		#函式說明:
1862
		#回傳結果::
1 liveuser 1863
		#$result["status"],"true"為執行成功;"false"為執行失敗。
1864
		#$result["error"],錯誤訊息的陣列
1865
		#查詢號的解果,需要解析。
43 liveuser 1866
		#必填參數:
1 liveuser 1867
		$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
1868
		$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
1869
		$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
43 liveuser 1870
		#可省略參數: 
1 liveuser 1871
 
1872
		#如果有設定密碼
1873
		if(isset($conf["dbPassword"])){
1874
 
1875
			$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
1876
 
1877
			}#if end
1878
 
1879
		#如果 $conf["dbPort"] 有設定
1880
		if(isset($conf["dbPort"])){
1881
 
1882
			#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
1883
			$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
1884
 
1885
			}#if end
1886
 
1887
		$queryResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
1888
		unset($conf["db"]["execMysqlQuery"]);
1889
 
1890
		#如果執行 sql 失敗
1891
		if($queryResult["status"]=="false"){
1892
 
1893
			#設置執行失敗訊息
1894
			$result["status"]="false";
1895
 
1896
			#設置錯誤訊息
1897
			$result["error"]=$queryResult["error"];
1898
 
1899
			#回傳結果				
1900
			return $result;
1901
 
1902
			}#if end
1903
 
1904
		#設置執成功訊息
1905
		$result["status"]="true";
1906
 
1907
		#回傳結果
1908
		return $result;
1909
 
1910
		}#function createDataTable end
1911
 
1912
	/*
43 liveuser 1913
	#函式說明:
1 liveuser 1914
	#新增資料表的欄位
43 liveuser 1915
	#回傳結果:
1 liveuser 1916
	#$result["status"],"true",代表執行成功;"false"代表執行失敗
1917
	#$result["error"],錯誤訊息陣列
1918
	#$result["sql"],執行的sql內容
1919
	#$result["function"],當前執行的函數名稱
43 liveuser 1920
	#必填參數:
1 liveuser 1921
	#$conf["dbAddress"],字串,爲mysql-Server的位置.
1922
	$conf["dbAddress"]=$dbAddress;
1923
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號.
1924
	$conf["dbAccount"]=$dbAccount;#爲用於連入mysql-Server時要使用的帳號.
1925
	#$conf["selectedDataBaseName"],字串,爲目標資料表所屬的資料庫.
1926
	$conf["selectedDataBaseName"]="";
1927
	#$conf["selectedDataTableName"],字串,爲目標資料表所屬的資料庫.
1928
	$conf["selectedDataTableName"]="";
1929
	#$conf["addedColumnName"],字串,要增加的欄位名稱.
1930
	$conf["addedColumnName"]="";
43 liveuser 1931
	#$conf["newDataTableColmunType"],字串,為新資料表的欄位儲存的型態,常見的有:#int,用來儲存整數.#double,用來儲存有小數點的數值.#timestamp,用來儲存時間.#varchar,最多可以儲存65535個字元,請記得使用$conf["newDataTableColmunLength"]參數指定長度.#char,用來儲存任何東西,儲存成字元,最大長限制為255.#tinytext,儲存長度限制為255,根據實際使用大小來調整儲存大小.#text,儲存大量文字,不能當索引鍵.
1 liveuser 1932
	$conf["newDataTableColmunType"]="char";
43 liveuser 1933
	#可省略參數: 
1 liveuser 1934
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
1935
	#$conf["dbPassword"]=$dbPassword;
1936
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
1937
	#$conf["dbPort"]="3306";
1938
	#$conf["newDataTableColmunLength"],字串,為新資料表的欄位儲存的長度.
1939
	#$conf["newDataTableColmunLength"]="";
43 liveuser 1940
	#$conf["newDataTableColmunDefault"],字串,為該欄位的預設值.#currentTime,當前時間.#updatedCurrentTime,初始為當前時間,之後每更動一次就更新為當次時間.#null,代表空值.#以外的內容視為指定的數值.
1 liveuser 1941
	#$conf["newDataTableColmunDefault"]="";
43 liveuser 1942
	#$conf["newDataTableColmunNotNull"],字串,為新資料表的欄位不可為NULL.#"true"代表不能為null.#"false"代表可以為null.
1 liveuser 1943
	#$conf["newDataTableColmunNotNull"]="true";#
1944
	#$conf["newDataTableColmunAutoAdd"],字串,為新資料表的欄位是否自動+1
1945
	#$conf["newDataTableColmunAutoAdd"]="true";
1946
	#$conf["newDataTableColmunKeyType"],字串,為該欄位的鍵屬性:"primary key"爲主鍵、"index"爲索引鍵、"foreign key"爲外鍵
1947
	#$conf["newDataTableColmunKeyType"]="primary key";
1948
	#$conf["foreignDb"]="";#外鍵參考的資料庫,預設為$conf["selectedDataBaseName"].
1949
	#$conf["foreignDb"]=$conf["selectedDataBaseName"];
1950
	#$conf["foreignTable"],字串,外鍵參考的資料表
1951
	#$conf["foreignTable"]="";
1952
	#$conf["foreignTableColumn"],字串,外鍵參考的資料表欄位
1953
	#$conf["foreignTableColumn"]="";
1954
	#$conf["onUpdateAction"],字串,當外鍵參考的欄位資料修改時,外鍵要如何回應?"CASCADE"會將有所關聯的紀錄行也會進行刪除或修改。"SET NULL"代表會將有所關聯的紀錄行設定成 NULL。"NO ACTION"代表有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
1955
	#$conf["onUpdateAction"]="CASCADE";#
1956
	#$conf["onDeleteAction"],字串,當外鍵參考的欄位資料移除時,外鍵要如何回應?"CASCADE"會將有所關聯的紀錄行也會進行刪除或修改。"SET NULL"代表會將有所關聯的紀錄行設定成 NULL。"NO ACTION"代表有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
1957
	#$conf["onDeleteAction"]="SET NULL";	
1958
	#$conf["comment"],字串,欄位的註解,預設不使用.
1959
	#$conf["comment"]="";
43 liveuser 1960
	#參考資料:
1 liveuser 1961
	#儲存型態=>https://mariadb.com/kb/en/data-types/
43 liveuser 1962
	#備註:
1963
	#無.
1 liveuser 1964
	*/
1965
	public static function addColumn(&$conf){
1966
 
1967
		#初始化要回傳的結果
1968
		$result=array();
1969
 
1970
		#記錄當前執行的函數名稱
1971
		$result["function"]=__FUNCTION__;
1972
 
1973
		#如果 $conf 不為陣列
1974
		if(gettype($conf)!="array"){
1975
 
1976
			#設置執行失敗
1977
			$result["status"]="false";
1978
 
1979
			#設置執行錯誤訊息
1980
			$result["error"][]="\$conf變數須為陣列形態";
1981
 
1982
			#如果傳入的參數為 null
1983
			if($conf==null){
1984
 
1985
				#設置執行錯誤訊息
1986
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
1987
 
1988
				}#if end
1989
 
1990
			#回傳結果
1991
			return $result;
1992
 
1993
			}#if end
1994
 
1995
		#檢查參數
43 liveuser 1996
		#函式說明:
1 liveuser 1997
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
1998
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
1999
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2000
		#$result["function"],當前執行的函式名稱.
2001
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2002
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2003
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2004
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
2005
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2006
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2007
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
43 liveuser 2008
		#必填參數:
1 liveuser 2009
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2010
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
2011
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2012
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName","addedColumnName");
2013
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
2014
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string");
2015
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2016
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
43 liveuser 2017
		#可省略參數:
1 liveuser 2018
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2019
		#$conf["canBeEmptyString"]="false";
2020
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2021
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort","newDataTableColmunType","newDataTableColmunLength","newDataTableColmunDefault","newDataTableColmunNotNull","newDataTableColmunAutoAdd","newDataTableColmunKeyType","foreignDb","foreignTable","foreignTableColumn","onUpdateAction","onDeleteAction","comment");
2022
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
2023
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string","string","string","string","string","string","string","string");
2024
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2025
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null,null,null,null,null,"\$conf[\"selectedDataBaseName\"]",null,null,null,null,null);
2026
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2027
		#$conf["arrayCountEqualCheck"][]=array();
43 liveuser 2028
		#參考資料:
1 liveuser 2029
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2030
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
2031
		unset($conf["variableCheck::checkArguments"]);
2032
 
2033
		#如果檢查過程有錯
2034
		if($checkResult["status"]=="false"){
2035
 
2036
			#設置執行失敗的訊息
2037
			$result["status"]="false";
2038
 
2039
			#設置錯誤訊息
2040
			$result["error"]=$checkResult;
2041
 
2042
			#回傳結果
2043
			return $result;
2044
 
2045
			}#if end
2046
 
2047
		#如果檢查不通過
2048
		if($checkResult["passed"]=="false"){
2049
 
2050
			#設置執行失敗的訊息
2051
			$result["status"]="false";
2052
 
2053
			#設置錯誤訊息
2054
			$result["error"]=$checkResult;
2055
 
2056
			#回傳結果
2057
			return $result;
2058
 
2059
			}#if end
2060
 
2061
		#組合sql語言
2062
		$sql="alter table `".$conf["selectedDataTableName"]."` add `".$conf["addedColumnName"]."`";
2063
 
2064
		#接上欄位儲存型態
2065
		$sql=$sql." ".$conf["newDataTableColmunType"];
2066
 
2067
		#如果資料形態爲 "double、float"
2068
		if($conf["newDataTableColmunType"]=="double" || $conf["newDataTableColmunType"]=="float" ){
2069
 
2070
			#則取消資料長度的限制
2071
			unset($conf["newDataTableColmunLength"]);
2072
 
2073
			}#if end	
2074
 
2075
		#如果有設定資料長度,且資料儲存型態不為 tinytext 與 text
2076
		if(isset($conf["newDataTableColmunLength"]) && $conf["newDataTableColmunType"]!="tinytext" && $conf["newDataTableColmunType"]!="text"){
2077
 
2078
			#接上欄位儲存長度
2079
			$sql=$sql." (".$conf["newDataTableColmunLength"].")";
2080
 
2081
			}#if end
2082
 
2083
		#如果資料形態不爲 "double、float、"
2084
		if($conf["newDataTableColmunType"]!="double" && $conf["newDataTableColmunType"]!="float" && $conf["newDataTableColmunType"]!="int"){
2085
 
2086
			#指定欄CHARACTER SET爲utf8,COLLATE爲utf8_unicode_ci
2087
			$sql=$sql." CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'";
2088
 
2089
			}#if end
2090
 
2091
		#如果有設定預設值
2092
		if(isset($conf["newDataTableColmunDefault"])){
2093
 
2094
			#如果 $conf["newDataTableColmunType"] 不等於 "tinytext" 也不等於 "text"
2095
			if($conf["newDataTableColmunType"]!="tinytext" && $conf["newDataTableColmunType"]!="text"){
2096
 
2097
				#根據 $conf["newDataTableColmunDefault"] 的數值內容
2098
				switch($conf["newDataTableColmunDefault"]){
2099
 
2100
					#如果設為 currentTime
2101
					case "currentTime":
2102
 
2103
						#設定語法
2104
						$sql=$sql." default CURRENT_TIMESTAMP";
2105
 
2106
						#跳出switch
2107
						break;
2108
 
2109
					#如果設為updatedCurrentTime
2110
					case "updatedCurrentTime":
2111
 
2112
						#設定語法
2113
						$sql=$sql." default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP";
2114
 
2115
						#跳出switch
2116
						break;
2117
 
2118
					#如果設為 null
2119
					case "null":
2120
 
2121
						#設定語法
2122
						$sql=$sql." default null";
2123
 
2124
						#跳出switch
2125
						break;
2126
 
2127
					#如果不為以上數值
2128
					default :
2129
 
2130
						#設定語法
2131
						$sql=$sql." default '".$conf["newDataTableColmunDefault"]."'";
2132
 
2133
						#跳出switch
2134
						break;
2135
 
2136
					}#switch end
2137
 
2138
				}#if end
2139
 
2140
			}#if end
2141
 
2142
		#如果有設定不能為NUL
2143
		if(isset($conf["newDataTableColmunNotNull"])){
2144
 
2145
			#如果 $conf["newDataTableColmunNotNull"] 等於 "true"
2146
			if($conf["newDataTableColmunNotNull"]=="true"){
2147
 
2148
				$sql=$sql." NOT NULL";
2149
 
2150
				}#if end
2151
 
2152
			}#if end
2153
 
2154
			#如果有設定要自動加1
2155
			if(isset($conf["newDataTableColmunAutoAdd"])){
2156
 
2157
				#如果 $conf["newDataTableColmunAutoAdd"] 設為 "true"
2158
				if($conf["newDataTableColmunAutoAdd"]=="true"){
2159
 
2160
					#加上自動加1的語句
2161
					$sql=$sql." auto_increment";
2162
 
2163
					}#if end
2164
 
2165
				}#if end
2166
 
2167
		#如果有設定註解
2168
		if(isset($conf["comment"])){
2169
 
2170
			#設定其註解
2171
			$sql=$sql." COMMENT '".$conf["comment"]."' ";
2172
 
2173
			}#if end		
2174
 
2175
		#如果有設定鍵的屬性
2176
		if(isset($conf["newDataTableColmunKeyType"])){
2177
 
2178
			#如果爲 primary key 
2179
			if($conf["newDataTableColmunKeyType"]=="primary key"){
2180
 
2181
				#設定其鍵值
2182
				$sql=$sql." ".$conf["newDataTableColmunKeyType"];
2183
 
2184
				}#if end
2185
 
2186
			}#if end
2187
 
2188
		#執行sql語法
43 liveuser 2189
		#函式說明:
1 liveuser 2190
		#執行mysql指令
43 liveuser 2191
		#回傳結果::
1 liveuser 2192
		#$result["status"],"true"為執行成功;"false"為執行失敗。
2193
		#$result["error"],錯誤訊息的陣列
2194
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
2195
		#$result["queryString"],mysql查詢的語言
2196
		#查詢號的解果,需要解析。
43 liveuser 2197
		#必填參數:
1 liveuser 2198
		$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
2199
		$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
2200
		$conf["db"]["execMysqlQuery"]["dbSql"]=$sql.";";#要執行sql語法
43 liveuser 2201
		#可省略參數:
1 liveuser 2202
 
2203
		#如果 $conf["dbPassword"] 有設定
2204
		if(isset($conf["dbPassword"])){
2205
 
2206
			#設定其密碼
2207
			$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
2208
 
2209
			}#if end
2210
 
2211
		$conf["db"]["execMysqlQuery"]["dbName"]=$conf["selectedDataBaseName"];#為是否要指定資料庫,預設不指定.
2212
 
2213
		#如果有設定 $conf["dbPort"]	
2214
		if(isset($conf["dbPort"])){
2215
 
2216
			#設定 $conf["dbPort"]
2217
			$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
2218
 
2219
			}#if end			
2220
 
2221
		$queryResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
2222
		unset($conf["db"]["execMysqlQuery"]);
2223
 
2224
		#如果有錯誤
2225
		if($queryResult["status"]=="false"){
2226
 
2227
			#設置錯誤訊息
2228
			$result["status"]="false";
2229
 
2230
			#設置錯誤提示
2231
			$result["error"]=$queryResult;
2232
 
2233
			#回傳結果
2234
			return $result;
2235
 
2236
			}#if end
2237
 
2238
		#取得執行的sql語法
2239
		$result["sql"][]=$queryResult["queryString"];
2240
 
2241
		#如果 $conf["newDataTableColmunKeyType"] 存在
2242
		if(isset($conf["newDataTableColmunKeyType"])){
2243
 
2244
			#如果爲 index
2245
			if($conf["newDataTableColmunKeyType"]=="index"){
2246
 
43 liveuser 2247
				#函式說明:
1 liveuser 2248
				#新增資料表的欄位
43 liveuser 2249
				#回傳結果:
1 liveuser 2250
				#$result["status"],"true",代表執行成功;"false"代表執行失敗.
2251
				#$result["function"],當前執行的函數名稱.
2252
				#$result["error"],錯誤訊息陣列.
2253
				#$result["sql"],執行的sql字串.
43 liveuser 2254
				#必填參數:
1 liveuser 2255
				$conf["db::setColumnIndex"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
2256
				$conf["db::setColumnIndex"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
2257
				$conf["db::setColumnIndex"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
2258
				$conf["db::setColumnIndex"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
2259
				$conf["db::setColumnIndex"]["indexedColumnName"]=$conf["addedColumnName"];#要設爲index的欄位名稱
43 liveuser 2260
				#可省略參數:
1 liveuser 2261
 
2262
				#如果 $conf["dbPassword"] 有設定
2263
				if(isset($conf["dbPassword"])){
2264
 
2265
					$conf["db::setColumnIndex"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
2266
 
2267
					}#if end
2268
 
2269
				#如果有設定 $conf["dbPort"]	
2270
				if(isset($conf["dbPort"])){
2271
 
2272
					#設定 $conf["dbPort"]
2273
					$conf["db::setColumnIndex"]["dbPort"]=$conf["dbPort"];
2274
 
2275
					}#if end	
2276
 
2277
				$setColumnIndex=db::setColumnIndex($conf["db::setColumnIndex"]);
2278
				unset($conf["db::setColumnIndex"]);
2279
 
2280
				#如果建立index失敗
2281
				if($setColumnIndex["status"]=="false"){
2282
 
2283
					#設置執行失敗
2284
					$result["status"]="false";
2285
 
2286
					#設置錯誤訊息
2287
					$result["error"]=$setColumnIndex;
2288
 
2289
					#回傳結果
2290
					return $result;
2291
 
2292
					}#if end
2293
 
2294
				#取得執行的sql語法
2295
				$result["sql"][]=$setColumnIndex["sql"];
2296
 
2297
				}#if end
2298
 
2299
			}#if end
2300
 
2301
		#如果 $conf["newDataTableColmunKeyType"] 有設定
2302
		if(isset($conf["newDataTableColmunKeyType"])){	
2303
 
2304
			#如果爲 foreign key
2305
			if($conf["newDataTableColmunKeyType"]=="foreign key"){
2306
 
43 liveuser 2307
				#函式說明:
1 liveuser 2308
				#修改資料表的欄位
43 liveuser 2309
				#回傳結果:
1 liveuser 2310
				#$result["status"],"true",代表執行成功;"false"代表執行失敗.
2311
				#$result["error"],錯誤訊息陣列.
2312
				#$result["function"],當前執行的函數名稱.
2313
				#$result["sql"][$i],第$i+1個執行的sql語法字串陣列.
43 liveuser 2314
				#必填參數:
1 liveuser 2315
				$conf["db::editColumn"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
2316
				$conf["db::editColumn"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
2317
				$conf["db::editColumn"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
2318
				$conf["db::editColumn"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料表
2319
				$conf["db::editColumn"]["editedColumnName"]=$conf["addedColumnName"];#要修改的欄位名稱
43 liveuser 2320
				#可省略參數: 
1 liveuser 2321
 
2322
				#如果 $conf["dbPassword"] 有設定
2323
				if(isset($conf["dbPassword"])){
2324
 
2325
					$conf["db::editColumn"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
2326
 
2327
					}#if end
2328
 
2329
				#$conf["newColumnName"]="";#要修改成的欄位名稱,預設與$conf["dbInformation"]["editedColumnName"]一樣。
2330
				#$conf["newDataTableColmunType"]="";#為新資料表的欄位儲存的型態,常見的有:
2331
					#int,用來儲存整數.
2332
					#double,用來儲存有小數點的數值.
2333
					#timestamp,用來儲存時間.
2334
					#varchar,可以儲存65536個字元.
2335
					#char,用來儲存任何東西,儲存成字元,長度限制為255.
2336
					#tinytest,來儲存大量的文字,會更據使用量調整儲存大小,長度限制跟char一樣.
2337
					#text,用來儲存大量的文字,不能作為索引值
2338
				#$conf["newDataTableColmunLength"]="";#為新資料表的欄位儲存的長度,""代表不限制長度
2339
				#$conf["newDataTableColmunDefault"]="";#為該欄位的預設值
2340
					#"",代表不指定預設值
2341
					#currentTime,當前時間;
2342
					#updatedCurrentTime,初始為當前時間,之後每更動一次就更新為當次時間
2343
					#null,代表空值
2344
					#以外的內容視為指定的數值
2345
				#$conf["newDataTableColmunNotNull"]="";#為新資料表的欄位不可為NULL否:
2346
					#true代表不能為null,
2347
					#false代表可以為null。
2348
				#$conf["newDataTableColmunAutoAdd"]="true";#為新資料表的欄位是否自動+1
2349
				$conf["db::editColumn"]["newDataTableColmunKeyType"]="foreign key";#為該欄位的鍵屬性:""為移除鍵的設定、"primary key"爲主鍵、"index"爲索引鍵、"foreign key"為外鍵
2350
				$conf["db::editColumn"]["foreignKeyDb"]=$conf["foreignDb"];#若要設定foreign key的話,則要提供參考的資料庫,預設為$conf["selectedDataBaseName"].
2351
				$conf["db::editColumn"]["foreignKeyReferenceTable"]=$conf["foreignTable"];#若要設定foreign key的話,則要提供參考的資料表
2352
				$conf["db::editColumn"]["foreignKeyReferenceColumn"]=$conf["foreignTableColumn"];#若要設定foreign key的話,則要提供參考的資料表欄位
2353
 
2354
				#如果有設定 $conf["onUpdateAction"]
2355
				if(isset($conf["onUpdateAction"])){
2356
 
2357
					$conf["db::editColumn"]["foreignKeyUpdateAction"]=$conf["onUpdateAction"];#若要設定foreign key的話,可以指定參考的資料表欄位更新時該欄位該怎麼處理,預設為"CASCADE",會將有所關聯的紀錄行也會進行刪除或修改。"SET NULL"代表會將有所關聯的紀錄行設定成 NULL。"NO ACTION"代表有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
2358
 
2359
					}#if end
2360
 
2361
				#如果有設定 $conf["onDeleteAction"]
2362
				if(isset($conf["onDeleteAction"])){
2363
 
2364
					$conf["db::editColumn"]["foreignKeyDeleteAction"]=$conf["onDeleteAction"];#若要設定foreign key的話,可以指定參考的資料表欄位移除時該欄位該怎麼處理,預設為"SET NULL",會將有所關聯的紀錄行設定成 NULL。"NO ACTION"代表有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
2365
 
2366
					}#if end
2367
 
2368
				#如果有設定 $conf["dbPort"]	
2369
				if(isset($conf["dbPort"])){
2370
 
2371
					#設定 $conf["dbPort"]
2372
					$conf["db::editColumn"]["dbPort"]=$conf["dbPort"];
2373
 
2374
					}#if end
2375
 
2376
				$editColumn=db::editColumn($conf["db::editColumn"]);
2377
				unset($conf["db::editColumn"]);
2378
 
2379
				#如果設置為foreign失敗
2380
				if($editColumn["status"]=="false"){
2381
 
2382
					#設置執行失敗
2383
					$result["status"]="false";
2384
 
2385
					#設置錯誤訊息
2386
					$result["error"]=$editColumn;
2387
 
2388
					#回傳結果
2389
					return $result;
2390
 
2391
					}#if end	
2392
 
2393
				#有幾個執行的sql語法就執行幾次
2394
				for($i=0;$i<count($editColumn["sql"]);$i++){
2395
 
2396
					#取得執行的sql語法
2397
					$result["sql"][]=$editColumn["sql"][$i];
2398
 
2399
					}#for end
2400
 
2401
				}#if end
2402
 
2403
			}#if end
2404
 
2405
		#執行到這邊代表執行成功
2406
 
2407
		#設置成功訊息
2408
		$result["status"]="true";
2409
 
2410
		#回傳結果
2411
		return $result;
2412
 
2413
		}#function addColumn end
2414
 
2415
	/*
43 liveuser 2416
	#函式說明:
1 liveuser 2417
	#修改資料表的欄位
43 liveuser 2418
	#回傳結果:
1 liveuser 2419
	#$result["status"],"true",代表執行成功;"false"代表執行失敗.
2420
	#$result["error"],錯誤訊息陣列.
2421
	#$result["function"],當前執行的函數名稱.
2422
	#$result["sql"][$i],第$i+1個執行的sql語法字串陣列.
43 liveuser 2423
	#必填參數:
1 liveuser 2424
	#$conf["dbAddress"],字串,爲mysql-Server的位置.
2425
	$conf["dbAddress"]=$dbAddress;
2426
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號.
2427
	$conf["dbAccount"]=$dbAccount;
2428
	#$conf["selectedDataBaseName"],字串,爲目標資料表所屬的資料庫.
2429
	$conf["selectedDataBaseName"]="";
2430
	#$conf["selectedDataTableName"],字串,爲目標資料表所屬的資料表.
2431
	$conf["selectedDataTableName"]="";
2432
	#$conf["editedColumnName"],字串,要修改的欄位名稱.
2433
	$conf["editedColumnName"]="";
43 liveuser 2434
	#可省略參數: 
1 liveuser 2435
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
2436
	#$conf["dbPassword"]=$dbPassword;
2437
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
2438
	#$conf["dbPort"]="3306";
2439
	#$conf["newColumnName"],字串,要修改成的欄位名稱,預設與$conf["editedColumnName"]一樣。
2440
	#$conf["newColumnName"]=$conf["editedColumnName"];
43 liveuser 2441
	#$conf["newDataTableColmunType"],字串,為新資料表的欄位儲存的型態,常見的有:int,用來儲存整數;double,用來儲存有小數點的數值;timestamp,用來儲存時間;varchar,可以儲存65536個字元;char,用來儲存任何東西,儲存成字元,長度限制為255;tinytest,來儲存大量的文字,會更據使用量調整儲存大小,長度限制跟char一樣;text,用來儲存大量的文字,不能作為索引值
1 liveuser 2442
	#$conf["newDataTableColmunType"]="";
2443
	#$conf["newDataTableColmunLength"]=,字串,為新資料表的欄位儲存的長度,""代表不限制長度.
2444
	#$conf["newDataTableColmunLength"]="";
43 liveuser 2445
	#$conf["newDataTableColmunDefault"],字串,為該欄位的預設值:"",代表不指定預設值;currentTime,當前時間;updatedCurrentTime,初始為當前時間,之後每更動一次就更新為當次時間;null,代表空值;以外的內容視為指定的數值.
1 liveuser 2446
	#$conf["newDataTableColmunDefault"]="";
43 liveuser 2447
	#$conf["newDataTableColmunNotNull"],字串,為新資料表的欄位不可為NULL否:true代表不能為null;false代表可以為null.
1 liveuser 2448
	#$conf["newDataTableColmunNotNull"]="";
2449
	#$conf["newDataTableColmunComment"],字串,欄位的註解.
2450
	#$conf["newDataTableColmunComment"]="";
2451
	#$conf["newDataTableColmunAutoAdd"],字串,為新資料表的欄位是否自動+1
2452
	#$conf["newDataTableColmunAutoAdd"]="true";
2453
	#$conf["newDataTableColmunKeyType"],字串,為該欄位的鍵屬性:""為移除鍵的設定、"primary key"爲主鍵、"index"爲索引鍵、"foreign key"為外鍵.
2454
	#$conf["newDataTableColmunKeyType"]="";
2455
	#$conf["foreignKeyDb"],字串,若要設定foreign key的話,則要提供參考的資料庫,預設為$conf["selectedDataBaseName"].
2456
	#$conf["foreignKeyDb"]="";
2457
	#$conf["foreignKeyReferenceTable"],字串,若要設定foreign key的話,則要提供參考的資料表.
2458
	#$conf["foreignKeyReferenceTable"]="";
2459
	#$conf["foreignKeyReferenceColumn"],字串,若要設定foreign key的話,則要提供參考的資料表欄位.
2460
	#$conf["foreignKeyReferenceColumn"]="";
2461
	#$conf["foreignKeyUpdateAction"],字串,若要設定foreign key的話,可以指定參考的資料表欄位更新時該欄位該怎麼處理,預設為"CASCADE",會將有所關聯的紀錄行也會進行刪除或修改。"SET NULL"代表會將有所關聯的紀錄行設定成 NULL。"NO ACTION"代表有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
2462
	#$conf["foreignKeyUpdateAction"]="";
2463
	#$conf["foreignKeyDeleteAction"],字串,若要設定foreign key的話,可以指定參考的資料表欄位移除時該欄位該怎麼處理,預設為"SET NULL",會將有所關聯的紀錄行設定成 NULL。"NO ACTION"代表有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
2464
	#$conf["foreignKeyDeleteAction"]="SET NULL";
185 liveuser 2465
	#參考資料:
2466
	#無.
43 liveuser 2467
	#備註:
2468
	#無.
1 liveuser 2469
	*/
2470
	public static function editColumn(&$conf){
2471
 
2472
		#初始化要回傳的內容
2473
		$result=array();
2474
 
2475
		#取得當前執行的函數名稱
2476
		$result["function"]=__FUNCTION__;
2477
 
2478
		#如果 $conf 不為陣列
2479
		if(gettype($conf)!="array"){
2480
 
2481
			#設置執行失敗
2482
			$result["status"]="false";
2483
 
2484
			#設置執行錯誤訊息
2485
			$result["error"][]="\$conf變數須為陣列形態";
2486
 
2487
			#如果傳入的參數為 null
2488
			if($conf==null){
2489
 
2490
				#設置執行錯誤訊息
2491
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
2492
 
2493
				}#if end
2494
 
2495
			#回傳結果
2496
			return $result;
2497
 
2498
			}#if end
2499
 
2500
		#檢查參數
43 liveuser 2501
		#函式說明:
1 liveuser 2502
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
2503
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
2504
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
2505
		#$result["function"],當前執行的函式名稱.
2506
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
2507
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
2508
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
2509
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
2510
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
2511
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
2512
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
43 liveuser 2513
		#必填參數:
1 liveuser 2514
		#$conf["db::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
2515
		$conf["db::checkArguments"]["varInput"]=&$conf;
2516
		#$conf["db::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
2517
		$conf["db::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName","editedColumnName");
2518
		#$conf["db::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
2519
		$conf["db::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string");
2520
		#$conf["db::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
2521
		$conf["db::checkArguments"]["referenceVarKey"]="db::checkArguments";
43 liveuser 2522
		#可省略參數:
1 liveuser 2523
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
2524
		#$conf["canBeEmptyString"]="false";
2525
		#$conf["db::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
2526
		$conf["db::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort","newColumnName","newDataTableColmunType","newDataTableColmunLength","newDataTableColmunDefault","newDataTableColmunNotNull","newDataTableColmunAutoAdd","newDataTableColmunKeyType","foreignKeyDb","foreignKeyReferenceTable","foreignKeyReferenceColumn","foreignKeyUpdateAction","foreignKeyDeleteAction","newDataTableColmuComment");
2527
		#$conf["db::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
2528
		$conf["db::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string","string","string","string","string","string","string","string","string");
2529
		#$conf["db::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
2530
		$conf["db::checkArguments"]["skipableVarDefaultValue"]=array(null,null,$conf["editedColumnName"],null,null,null,null,null,null,"\$conf[\"selectedDataBaseName\"]",null,null,null,null,null);
2531
		#$conf["db::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
2532
		#$conf["db::checkArguments"]["arrayCountEqualCheck"][]=array();
43 liveuser 2533
		#參考資料:
1 liveuser 2534
		#array_keys=>http://php.net/manual/en/function.array-keys.php
2535
		$checkResult=variableCheck::checkArguments($conf["db::checkArguments"]);
2536
		unset($conf["db::checkArguments"]);
2537
 
2538
		#如果檢查有誤
2539
		if($checkResult["status"]=="false"){
2540
 
2541
			#設置執行失敗的訊息
2542
			$result["status"]="false";
2543
 
2544
			#設置錯誤訊息
2545
			$result["error"]=$checkResult;
2546
 
2547
			#回傳結果
2548
			return $result;
2549
 
2550
			}#if end
2551
 
2552
		#如果檢查不通過
2553
		if($checkResult["passed"]=="false"){
2554
 
2555
			#設置執行失敗的訊息
2556
			$result["status"]="false";
2557
 
2558
			#設置錯誤訊息
2559
			$result["error"]=$checkResult;
2560
 
2561
			#回傳結果
2562
			return $result;
2563
 
2564
			}#if end
2565
 
2566
		#取得目標資料表的所有資訊
43 liveuser 2567
		#函式說明:
1 liveuser 2568
		#取得資料表所有欄位的詳細資訊
2569
		#回傳的內容:
2570
		#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
2571
		#$result["error"],錯誤訊息陣列
2572
		#$result["sql"],執行的sql語法
2573
		#$result["oriInput"],原始的資料表欄位資訊
2574
		#$result["everyLine"],逐行的欄位資訊
2575
		#$result["tableName"],當前查詢的資料表名稱
2576
		#$result["engine"],資料表使用的儲存引擎
2577
		#$result["charset"],資料表預設的編碼
2578
		#$result["columnName"][$i],各欄位的名稱陣列,$i爲0開始的數字,也可以使用欄位的名稱。
2579
		#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲0開始的數字,也可以使用欄位的名稱。
2580
		#$result["columnVarType"][$i],各欄位變數儲存的型態,$i爲0開始的數字,也可以使用欄位的名稱.
2581
		#$result["columnVarLengthLimit"][$i],個欄位變數的長度限制,若不存在其限制,則為"",$i爲0開始的數字,也可以使用欄位的名稱.
2582
		#$result["columnNull"][$i],各欄位是否可以爲null,"true"爲可以爲null;"false"爲可不以爲"null",$i爲0開始的數字,也可以使用欄位的名稱。
2583
		#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲0開始的數字,也可以使用欄位的名稱。
2584
		#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲0開始的數字,也可以使用欄位的名稱。
2585
		#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲0開始的數字,也可以使用欄位的名稱。
2586
		#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲0開始的數字,也可以使用欄位的名稱。
2587
		#$result["columnCollate"][$i],各欄位使用的Collate,$i爲0開始的數字,也可以使用欄位的名稱。
2588
		#$result["columnComment"][$i],各欄位的註解,$i爲1開始的數字,也可以使用欄位的名稱。
2589
		#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
2590
		#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
2591
		#$result["keyConstraintName"][$j],該資料表用於識別索引鍵的CONSTRAINT名稱陣列,$j爲0開始的數字,也可以使用欄位的名稱。
2592
		#$result["primaryKey"],該資料表的主鍵
2593
		#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
2594
		#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲0開始的數字,也可以使用欄位的名稱。
2595
		#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列,$k爲0開始的數字,也可以使用欄位的名稱。
2596
		#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲0開始的數字,,也可用欄位的名稱來找value.
2597
		#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲0開始的數字,也可用欄位的名稱來找value.
2598
		#$result["foreignKey"]["onUpdateAction"][$i],當參照的欄位資料更新時,會怎麼同步,$i爲0開始的數字,也可用欄位的名稱來找value.
2599
		#$result["foreignKey"]["onDeleteAction"][$i],當參照的欄位資料移除時,會怎麼同步,$i爲0開始的數字,也可用欄位的名稱來找value.
43 liveuser 2600
		#必填參數:
1 liveuser 2601
		$conf["db"]["getTableColumnDetailInfo"]["dbAddress"]=$conf["dbAddress"];#資料庫的網路位置
2602
		$conf["db"]["getTableColumnDetailInfo"]["dbAccount"]=$conf["dbAccount"];#連線到資料庫要用的帳號
2603
		$conf["db"]["getTableColumnDetailInfo"]["selectedDataBase"]=$conf["selectedDataBaseName"];#連線到資料庫要選擇的資料庫
2604
		$conf["db"]["getTableColumnDetailInfo"]["selectedDataTable"]=$conf["selectedDataTableName"];#連線到資料庫要檢視的資料表
43 liveuser 2605
		#可省略參數:
1 liveuser 2606
 
2607
		#如果有設定連線密碼
2608
		if(isset($conf["dbPassword"])){
2609
 
2610
			$conf["db"]["getTableColumnDetailInfo"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
2611
 
2612
			}#if end
2613
 
2614
		#如果有設定 $conf["dbPort"]	
2615
		if(isset($conf["dbPort"])){
2616
 
2617
			#設定 $conf["dbPort"]
2618
			$conf["db"]["getTableColumnDetailInfo"]["dbPort"]=$conf["dbPort"];
2619
 
2620
			}#if end	
2621
 
2622
		$oriColumnInfo=db::getTableColumnDetailInfo($conf["db"]["getTableColumnDetailInfo"]);
2623
		unset($conf["db"]["getTableColumnDetailInfo"]);
2624
 
2625
		#debug
2626
		#var_dump($oriColumnInfo);
2627
		#exit;
2628
 
2629
		#如果查詢資料表資訊失敗
2630
		if($oriColumnInfo["status"]=="false"){
2631
 
2632
			#設定執行失敗的識別
2633
			$result["status"]="false";
2634
 
2635
			#設定錯誤訊息
2636
			$result["error"]=$oriColumnInfo;
2637
 
2638
			#回傳結果
2639
			return $result;
2640
 
2641
			}#if end
2642
 
2643
		#檢視目標欄位的鍵屬性
2644
		#var_dump($oriColumnInfo);
2645
 
2646
		#如果沒有定新的欄位明稱
2647
		if(!isset($conf["newColumnName"])){
2648
 
2649
			#則設定為原始欄位的名稱
2650
			$conf["newColumnName"]=$oriColumnInfo["columnName"][$conf["editedColumnName"]];
2651
 
2652
			}#if end
2653
 
2654
		#如果 $conf["newDataTableColmunType"] 沒有設定 
2655
		if(!isset($conf["newDataTableColmunType"])){
2656
 
2657
			#$oriColumnInfo["columnVarTypeAndLengthLimit"][$conf["editedColumnName"]];
2658
 
2659
			#則設定為原始欄位的儲存型態
2660
			$conf["newDataTableColmunType"]=$oriColumnInfo["columnVarType"][$conf["editedColumnName"]];
2661
 
2662
			}#if end
2663
 
2664
		#以下要檢查
2665
 
2666
		#如果新資料型態不等於 "tinytext" 跟 "text"
2667
		if($conf["newDataTableColmunType"]!="tinytext" && $conf["newDataTableColmunType"]!="text"){
2668
 
2669
			#如果沒有設定 $conf["newDataTableColmunLength"]
2670
			if(!isset($conf["newDataTableColmunLength"])){
2671
 
2672
				#則設定為原始欄位的儲存長度
2673
				$conf["newDataTableColmunLength"]=$oriColumnInfo["columnVarLengthLimit"][$conf["editedColumnName"]];
2674
 
2675
				}#if end
2676
 
2677
			#如果 $conf["newDataTableColmunLength"] 不為 ""
2678
			if($conf["newDataTableColmunLength"]!=""){
2679
 
2680
				#則加上 「(」與「)」
2681
				$conf["newDataTableColmunLength"]="(".$conf["newDataTableColmunLength"].")";
2682
 
2683
				#屬性後面加上長度
2684
				$conf["newDataTableColmunType"]=$conf["newDataTableColmunType"].$conf["newDataTableColmunLength"];
2685
 
2686
				}#if end
2687
 
2688
			}#if end
2689
 
2690
		#如果 $conf["newDataTableColmunDefault"] 不存在
2691
		if(!isset($conf["newDataTableColmunDefault"])){
2692
 
2693
			#則設定為原始欄位的預設數值
2694
			$conf["newDataTableColmunDefault"]="default \"".$oriColumnInfo["columnDefault"][$conf["editedColumnName"]]."\"";
2695
 
2696
			#如果 $oriColumnInfo["columnDefault"][$conf["editedColumnName"]] 為 ""
2697
			if($oriColumnInfo["columnDefault"][$conf["editedColumnName"]]==""){
2698
 
2699
				#則將 $conf["newDataTableColmunDefault"] 設為
2700
				$conf["newDataTableColmunDefault"]="";
2701
 
2702
				}#if end
2703
 
2704
			#如果 $oriColumnInfo["columnDefault"][$conf["editedColumnName"]] 為 "NULL"
2705
			if($oriColumnInfo["columnDefault"][$conf["editedColumnName"]]=="NULL"){
2706
 
2707
				#則將 $conf["newDataTableColmunDefault"] 設為
2708
				$conf["newDataTableColmunDefault"]="";
2709
 
2710
				}#if end
2711
 
2712
			#如果 $oriColumnInfo["columnDefault"][$conf["editedColumnName"]] 為 "沒有指定"
2713
			if($oriColumnInfo["columnDefault"][$conf["editedColumnName"]]=="沒有指定"){
2714
 
2715
				#則將 $conf["newDataTableColmunDefault"] 設為
2716
				$conf["newDataTableColmunDefault"]="";
2717
 
2718
				}#if end
2719
 
2720
			}#if end
2721
 
2722
		#反之有設定 $conf["newDataTableColmunDefault"]
2723
		else{
2724
 
2725
			#當 $conf["newDataTableColmunType"] 不等於 "text" 與 "tinytest" 時,才能用預設值。
2726
			if($conf["newDataTableColmunType"]!="text" && $conf["newDataTableColmunType"]!="tinytest" ){
2727
 
2728
				#判斷 $conf["newDataTableColmunDefault"] 的數值
2729
				#currentTime,當前時間;
2730
				#updatedCurrentTime,初始為當前時間,之後每更動一次就更新為當次時間
2731
				#null,代表空值
2732
				#以外的內容視為指定的數值
2733
				switch($conf["newDataTableColmunDefault"]){
2734
 
2735
					#如果是
2736
					case "currentTime":
2737
 
2738
						#則將 $conf["newDataTableColmunDefault"] 設為 " default CURRENT_TIMESTAMP "
2739
						$conf["newDataTableColmunDefault"]=" default CURRENT_TIMESTAMP ";
2740
 
2741
						#跳出 switch 
2742
						break;
2743
 
2744
					#如果是 "updatedCurrentTime"
2745
					case "updatedCurrentTime":
2746
 
2747
						#則將 $conf["newDataTableColmunDefault"] 設為 " default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP "
2748
						$conf["newDataTableColmunDefault"]=" default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP ";
2749
 
2750
						#跳出 switch 
2751
						break;
2752
 
2753
					#如果是 "null"
2754
					case "null":
2755
 
2756
						#則將 $conf["newDataTableColmunDefault"] 設為 " default null "
2757
						$conf["newDataTableColmunDefault"]=" default null ";
2758
 
2759
						#跳出 switch 
2760
						break;
2761
 
2762
					#如果是 "NULL"
2763
					case "NULL":
2764
 
2765
						#則將 $conf["newDataTableColmunDefault"] 設為 " default null "
2766
						$conf["newDataTableColmunDefault"]=" default NULL ";
2767
 
2768
						#跳出 switch 
2769
						break;
2770
 
2771
					#如果是 ""
2772
					case "":
2773
 
2774
						#則代表不設定預設值
2775
						$conf["newDataTableColmunDefault"]="";
2776
 
2777
						break;
2778
 
2779
					#如果為其他內容	
2780
					default :
2781
 
2782
						#套用自訂的預設值
2783
						$conf["newDataTableColmunDefault"]=" default '".$conf["newDataTableColmunDefault"]."'";		
2784
 
2785
					}#switch end
2786
 
2787
				}#if end
2788
 
2789
			}#else end
2790
 
2791
		#如果 $conf["newDataTableColmunNotNull"] 沒有設定
2792
		if(!isset($conf["newDataTableColmunNotNull"])){
2793
 
2794
			#則按照原始欄位的設定
2795
 
2796
			#如果 $oriColumnInfo["columnNotNull"][$conf["editedColumnName"]] 等於 "true"
2797
			if($oriColumnInfo["columnNotNull"][$conf["editedColumnName"]]=="true"){
2798
 
2799
				#則代表不能為 null
2800
				$conf["newDataTableColmunNotNull"]=" not null";
2801
 
2802
				}#if end
2803
 
2804
			#反之 $oriColumnInfo["columnNotNull"][$conf["editedColumnName"]] 等於 "false"
2805
			else{
2806
 
2807
				#則代表可以為 null
2808
				#將 $conf["newDataTableColmunNotNull"] 置換為 ""
2809
				$conf["newDataTableColmunNotNull"]="";
2810
 
2811
				}#if end
2812
 
2813
			}#if end
2814
 
2815
		#反之 如果 $conf["newDataTableColmunNotNull"] 有設定
2816
		else{
2817
 
2818
			#如果 $conf["newDataTableColmunNotNull"] 為 "true"
2819
			if($conf["newDataTableColmunNotNull"]=="true"){
2820
 
2821
				#則置換為 "not null"
2822
				$conf["newDataTableColmunNotNull"]="not null";
2823
 
2824
				}#if end
2825
 
2826
			#如果 $conf["newDataTableColmunNotNull"] 為 "false"
2827
			if($conf["newDataTableColmunNotNull"]=="false"){
2828
 
2829
				#則置換為 ""
2830
				$conf["newDataTableColmunNotNull"]="";
2831
 
2832
				}#if end
2833
 
2834
			}#else end
2835
 
2836
		#如果 $conf["newDataTableColmunAutoAdd"] 沒有設定
2837
		if(!isset($conf["newDataTableColmunAutoAdd"])){
2838
 
2839
			#原始欄位的設定為 true 的話
2840
			if($oriColumnInfo["columnAutoIncrement"][$conf["editedColumnName"]]=="true"){
2841
 
2842
				#則按照原始欄位的設定
2843
				$conf["newDataTableColmunAutoAdd"]="auto_increment";
2844
 
2845
				}#if end
2846
 
2847
			#反之代表沒有設定
2848
			else{
2849
 
2850
				#設為 ""
2851
				$conf["newDataTableColmunAutoAdd"]="";
2852
 
2853
				}#else end
2854
 
2855
			}#if end
2856
 
2857
		#反之代表 $conf["newDataTableColmunAutoAdd"] 有設定
2858
		else{
2859
 
2860
			#如果 $conf["newDataTableColmunAutoAdd"] 等於 "true"
2861
			if($conf["newDataTableColmunAutoAdd"]=="true"){
2862
 
2863
				#則將 $conf["newDataTableColmunAutoAdd"] 設為 auto_increment
2864
				$conf["newDataTableColmunAutoAdd"]="auto_increment";
2865
 
2866
				}#if end
2867
 
2868
			#反之 $conf["newDataTableColmunAutoAdd"] 不等於 "true"
2869
			else{
2870
 
2871
				#則將 $conf["newDataTableColmunAutoAdd"] 設為 ""
2872
				$conf["newDataTableColmunAutoAdd"]="";
2873
 
2874
				}#else end				
2875
 
2876
			}#else end
2877
 
2878
		#如果 $conf["newDataTableColmunType"] 為 "char" 或 "text"	
2879
		if($conf["newDataTableColmunType"]=="char" || $conf["newDataTableColmunType"]=="text"){
2880
 
2881
			#CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci',設定為utf8
2882
			$utf8="CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'";
2883
 
2884
			}#if end
2885
 
2886
		#反之不是字元或文字
2887
		else{
2888
 
2889
			#則設為""
2890
			$utf8="";
2891
 
2892
			}#else end	
2893
 
2894
		#如果有設定 $conf["newDataTableColmunComment"]
2895
		if(isset($conf["newDataTableColmunComment"])){
2896
 
2897
			#如果 $conf["newDataTableColmunComment"] 等於 ""
2898
			if($conf["newDataTableColmunComment"]==""){
2899
 
2900
				#設置為"沒有註解"
2901
				$comment=" COMMENT '沒有註解'";
2902
 
2903
				}#if end
2904
 
2905
			#反之設置指定的註解字串
2906
			else{
2907
 
2908
				#設置註解
2909
				$comment=" COMMENT '".$conf["newDataTableColmunComment"]."'";
2910
 
2911
				}#else end
2912
 
2913
			}#if end
2914
 
2915
		#反之
2916
		else{
2917
 
2918
			#如果原始沒有註解
2919
			if(!isset($oriColumnInfo["colmunComment"][$conf["editedColumnName"]])){
2920
 
2921
				#設為空字串
2922
				$comment="";
2923
 
2924
				}#if end
2925
 
2926
			#反之
2927
			else{
2928
 
2929
				#設為原始的註解
2930
				$comment=" COMMENT '".$oriColumnInfo["colmunComment"][$conf["editedColumnName"]]."'";
2931
 
2932
				}#else end
2933
 
2934
			}#else end	
2935
 
2936
		#組合sql語法
2937
		$sql="alter table ".$conf["selectedDataBaseName"].".".$conf["selectedDataTableName"]." change `".$conf["editedColumnName"]."` `".$conf["newColumnName"]."` ".$conf["newDataTableColmunType"]." ".$utf8." ".$conf["newDataTableColmunDefault"]." ".$conf["newDataTableColmunNotNull"]." ".$conf["newDataTableColmunAutoAdd"]." ".$comment." ;";
2938
 
2939
		#執行 sql 語法
43 liveuser 2940
		#函式說明:
1 liveuser 2941
		#執行mysql指令
43 liveuser 2942
		#回傳結果::
1 liveuser 2943
		#$result["status"],"true"為執行成功;"false"為執行失敗。
2944
		#$result["error"],錯誤訊息的陣列
2945
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
2946
		#$result["queryString"],mysql查詢的語言
2947
		#查詢號的解果,需要解析。
43 liveuser 2948
		#必填參數:
1 liveuser 2949
		$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
2950
		$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
2951
		$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
43 liveuser 2952
		#可省略參數: 
1 liveuser 2953
 
2954
		#如果有設定連線密碼
2955
		if(isset($conf["dbPassword"])){
2956
 
2957
			$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
2958
 
2959
			}#if end
2960
 
2961
		#如果有設定 $conf["dbPort"]	
2962
		if(isset($conf["dbPort"])){
2963
 
2964
			#設定 $conf["dbPort"]
2965
			$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
2966
 
2967
			}#if end	
2968
 
2969
		$sqlExecResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
2970
		unset($conf["db"]["execMysqlQuery"]);
2971
 
2972
		#如果執行 sql 語法錯誤
2973
		if($sqlExecResult["status"]=="false"){
2974
 
2975
			#設定執行失敗的識別
2976
			$result["status"]="false";
2977
 
2978
			#設定錯誤訊息
2979
			$result["error"]=$sqlExecResult;
2980
 
2981
			#回傳結果
2982
			return $result;
2983
 
2984
			}#if end
2985
 
2986
		#取得執行的sql語法
2987
		$result["sql"][]=$sqlExecResult["queryString"];
2988
 
2989
		#如果 $conf["newDataTableColmunKeyType"] 有設定
2990
		if(isset($conf["newDataTableColmunKeyType"])){
2991
 
2992
			#取得其key為何種
43 liveuser 2993
			#函式說明:
1 liveuser 2994
			#取得資料表所有欄位的詳細資訊
2995
			#回傳的內容:
2996
			#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
2997
			#$result["error"],錯誤訊息陣列
2998
			#$result["sql"],執行的sql語法
2999
			#$result["oriInput"],原始的資料表欄位資訊
3000
			#$result["everyLine"],逐行的欄位資訊
3001
			#$result["tableName"],當前查詢的資料表名稱
3002
			#$result["engine"],資料表使用的儲存引擎
3003
			#$result["charset"],資料表預設的編碼
3004
			#$result["columnName"][$i],各欄位的名稱陣列,$i爲0開始的數字,也可以使用欄位的名稱。
3005
			#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲0開始的數字,也可以使用欄位的名稱。
3006
			#$result["columnNotNull"][$i],各欄位是否可以不爲null,"true"爲可以不爲null;"false"爲可以爲"null",$i爲0開始的數字,也可以使用欄位的名稱。
3007
			#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲0開始的數字,也可以使用欄位的名稱。
3008
			#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲0開始的數字,也可以使用欄位的名稱。
3009
			#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲0開始的數字,也可以使用欄位的名稱。
3010
			#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲0開始的數字,也可以使用欄位的名稱。
3011
			#$result["columnCollate"][$i],各欄位使用的Collate,$i爲0開始的數字,也可以使用欄位的名稱。
3012
			#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
3013
			#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
3014
			#$result["primaryKey"],該資料表的主鍵
3015
			#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
3016
			#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲0開始的數字,也可以使用欄位的名稱。
3017
			#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列
3018
			#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲0開始的數字
3019
			#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲0開始的數字
3020
			#$result["foreignKey"]["OnUpdateAction"][$l],當參照的欄位資料更新時,會怎麼同步,$l爲0開始的數字
3021
			#$result["foreignKey"]["OnDeleteAction"][$m],當參照的欄位資料移除時,會怎麼同步,$m爲0開始的數字
43 liveuser 3022
			#必填參數:
1 liveuser 3023
			$conf["db"]["getTableColumnDetailInfo"]["dbAddress"]=$conf["dbAddress"];
3024
			$conf["db"]["getTableColumnDetailInfo"]["dbAccount"]=$conf["dbAccount"];
3025
			$conf["db"]["getTableColumnDetailInfo"]["selectedDataBase"]=$conf["selectedDataBaseName"];
3026
			$conf["db"]["getTableColumnDetailInfo"]["selectedDataTable"]=$conf["selectedDataTableName"];
43 liveuser 3027
			#可省略參數:
1 liveuser 3028
 
3029
			#如果 $conf["dbPassword"] 有設定
3030
			if(isset($conf["dbPassword"])){
3031
 
3032
				#套用連限時的密碼
3033
				$conf["db"]["getTableColumnDetailInfo"]["dbPassword"]=$conf["dbPassword"];
3034
 
3035
				}#if end
3036
 
3037
			#如果有設定 $conf["dbPort"]	
3038
			if(isset($conf["dbPort"])){
3039
 
3040
				#設定 $conf["dbPort"]
3041
				$conf["db"]["getTableColumnDetailInfo"]["dbPort"]=$conf["dbPort"];
3042
 
3043
				}#if end	
3044
 
3045
			$tableColumnDetial=db::getTableColumnDetailInfo($conf["db"]["getTableColumnDetailInfo"]);
3046
			unset($conf["db"]["getTableColumnDetailInfo"]);#卸除變數,避免錯誤產生.
3047
 
3048
			#如果取得資料表結構失敗
3049
			if($tableColumnDetial["status"]=="false"){
3050
 
3051
				#設置執行不正常
3052
				$result["status"]="false";
3053
 
3054
				#設置執行錯誤訊息
3055
				$result["error"]=$tableColumnDetial;
3056
 
3057
				#回傳結果
3058
				return $result;
3059
 
3060
				}#if end
3061
 
3062
			#判斷 $conf["newDataTableColmunKeyType"] 來進行處理
3063
			#"index"爲索引鍵,"foreign key"為外鍵,""為將鍵屬性取消。
3064
			switch($conf["newDataTableColmunKeyType"]){
3065
 
3066
				#如果 $conf["newDataTableColmunKeyType"] 是 ""
3067
				case "":
3068
 
3069
					#檢查目標欄位是主鍵或是索引鍵或是外鍵
3070
 
3071
					#debug	
3072
					#var_dump($tableColumnDetial);
3073
 
3074
					#如果 $tableColumnDetial["foreignKey"]["exist"] 等於 "true",代表有外鍵
3075
					if($tableColumnDetial["foreignKey"]["exist"]=="true"){
3076
 
3077
						#如果 $tableColumnDetial["foreignKey"]["columnName"][$conf["dbInformation"]["newColumnName"]] 存在,則代表該欄位為索引鍵
3078
						if(isset($tableColumnDetial["foreignKey"]["columnName"][$conf["newColumnName"]])){
3079
 
3080
							#移除外鍵
43 liveuser 3081
							#函式說明:
1 liveuser 3082
							#移除資料表單1欄位的外鍵
43 liveuser 3083
							#回傳結果:
1 liveuser 3084
							#$result["status"],"true",代表執行成功;"false"代表執行失敗
3085
							#$result["error"],錯誤訊息陣列
3086
							#$result["sql"],執行的sql字串.
43 liveuser 3087
							#必填參數:
1 liveuser 3088
							$conf["db"]["eraseForeignKey"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
3089
							$conf["db"]["eraseForeignKey"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
3090
							$conf["db"]["eraseForeignKey"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
3091
							$conf["db"]["eraseForeignKey"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
3092
							$conf["db"]["eraseForeignKey"]["erasedForeignKeyColumnConstraintName"]=$tableColumnDetial["foreignKey"]["constraintName"][$conf["newColumnName"]];#要移除外鍵欄位的CONSTRAINT名稱
43 liveuser 3093
							#可省略參數: 
1 liveuser 3094
 
3095
							#如果 $conf["dbPassword"] 存在
3096
							if(isset($conf["dbPassword"])){
3097
 
3098
								#則設定連線的密碼
3099
								$conf["db"]["eraseForeignKey"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
3100
 
3101
								}#if end
3102
 
3103
							#如果有設定 $conf["dbPort"]	
3104
							if(isset($conf["dbPort"])){
3105
 
3106
								#設定 $conf["dbPort"]
3107
								$conf["db"]["eraseForeignKey"]["dbPort"]=$conf["dbPort"];
3108
 
3109
								}#if end	
3110
 
3111
							$eraseForeignKeyResult=db::eraseForeignKey($conf["db"]["eraseForeignKey"]);
3112
							unset($conf["db"]["eraseForeignKey"]);
3113
 
3114
							#取得執行的sql字串
3115
							$result["sql"][]=$eraseForeignKeyResult["sql"];
3116
 
3117
							#如果 $eraseForeignKeyResult["status"]等於"fasle"
3118
							if($eraseForeignKeyResult["status"]=="false"){
3119
 
3120
								#設置出錯的識別
3121
								$result["status"]="fasle";
3122
 
3123
								#設置錯誤訊息
3124
								$result["error"]=$eraseForeignKeyResult;
3125
 
3126
								#回傳結果
3127
								return $result;
3128
 
3129
								}#if end
3130
 
3131
							}#if end
3132
 
3133
						}#if end
3134
 
3135
					#如果 $tableColumnDetial["key"]["exist"] 等於 "true",代表有索引鍵
3136
					if($tableColumnDetial["key"]["exist"]=="true"){
3137
 
3138
						#如果 $tableColumnDetial["key"][$conf["newColumnName"]] 存在,則代表該欄位為索引鍵
3139
						if(isset($tableColumnDetial["key"][$conf["newColumnName"]])){
3140
 
3141
							#移除索引鍵
43 liveuser 3142
							#函式說明:
1 liveuser 3143
							#移除資料表單1欄位的索引鍵
43 liveuser 3144
							#回傳結果:
1 liveuser 3145
							#$result["status"],"true",代表執行成功;"false"代表執行失敗
3146
							#$result["error"],錯誤訊息陣列
3147
							#$result["sql"],執行的sql字串.
43 liveuser 3148
							#必填參數:
1 liveuser 3149
							$conf["db"]["eraseIndexKey"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
3150
							$conf["db"]["eraseIndexKey"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
3151
							$conf["db"]["eraseIndexKey"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
3152
							$conf["db"]["eraseIndexKey"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料表
3153
							$conf["db"]["eraseIndexKey"]["erasedIndexKeyColumnConstraintName"]=$tableColumnDetial["keyConstraintName"][$conf["newColumnName"]];#要移除外鍵欄位的CONSTRAINT名稱
43 liveuser 3154
							#可省略參數:
1 liveuser 3155
 
3156
							#如果 $conf["dbPassword"] 存在
3157
							if(isset($conf["dbPassword"])){
3158
 
3159
								#則設定連線的密碼
3160
								$conf["db"]["eraseIndexKey"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
3161
 
3162
								}#if end
3163
 
3164
							#如果有設定 $conf["dbPort"]	
3165
							if(isset($conf["dbPort"])){
3166
 
3167
								#設定 $conf["dbPort"]
3168
								$conf["db"]["eraseIndexKey"]["dbPort"]=$conf["dbPort"];
3169
 
3170
								}#if end	
3171
 
3172
							$eraseIndexKeyResult=db::eraseIndexKey($conf["db"]["eraseIndexKey"]);
3173
							#var_dump($conf["db"]["eraseIndexKey"]);
3174
							unset($conf["db"]);
3175
 
3176
							#debug
3177
							#var_dump($eraseIndexKeyResult);
3178
 
3179
							#取得執行的sql語言
3180
							$result["sql"][]=$eraseIndexKeyResult["sql"];
3181
 
3182
							#如果 $eraseIndexKeyResult["status"]等於"fasle"
3183
							if($eraseIndexKeyResult["status"]=="false"){
3184
 
3185
								#設置出錯的識別
3186
								$result["status"]="false";
3187
 
3188
								#設置錯誤訊息
3189
								$result["error"]=$eraseIndexKeyResult;
3190
 
3191
								#回傳結果
3192
								return $result;
3193
 
3194
								}#if end
3195
 
3196
							}#if end
3197
 
3198
						}#if end
3199
 
3200
					#中斷switch
3201
					break;
3202
 
3203
				#如果 $conf["newDataTableColmunKeyType"] 是 "index"
3204
				case "index":
3205
 
3206
					#如果 $tableColumnDetial["foreignKey"]["exist"] 等於 "true",代表有外鍵
3207
					if($tableColumnDetial["foreignKey"]["exist"]=="true"){
3208
 
3209
						#echo "have foreign key";
3210
 
3211
						#如果 $tableColumnDetial["foreignKey"]["columnName"][$conf["newColumnName"]] 存在,則代表該欄位為索引鍵
3212
						if(isset($tableColumnDetial["foreignKey"]["columnName"][$conf["newColumnName"]])){
3213
 
3214
							#移除外鍵
43 liveuser 3215
							#函式說明:
1 liveuser 3216
							#移除資料表單1欄位的外鍵
43 liveuser 3217
							#回傳結果:
1 liveuser 3218
							#$result["status"],"true",代表執行成功;"false"代表執行失敗
3219
							#$result["error"],錯誤訊息陣列
43 liveuser 3220
							#必填參數:
1 liveuser 3221
							$conf["db"]["eraseForeignKey"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
3222
							$conf["db"]["eraseForeignKey"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
3223
							$conf["db"]["eraseForeignKey"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
3224
							$conf["db"]["eraseForeignKey"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
3225
							$conf["db"]["eraseForeignKey"]["erasedForeignKeyColumnConstraintName"]=$tableColumnDetial["foreignKey"]["constraintName"][$conf["newColumnName"]];#要移除外鍵欄位的CONSTRAINT名稱
43 liveuser 3226
							#可省略參數: 
1 liveuser 3227
 
3228
							#如果 $conf["dbPassword"] 存在
3229
							if(isset($conf["dbPassword"])){
3230
 
3231
								#則設定連線的密碼
3232
								$conf["db"]["eraseForeignKey"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
3233
 
3234
								}#if end
3235
 
3236
							#如果有設定 $conf["dbPort"]	
3237
							if(isset($conf["dbPort"])){
3238
 
3239
								#設定 $conf["dbPort"]
3240
								$conf["db"]["eraseForeignKey"]["dbPort"]=$conf["dbPort"];
3241
 
3242
								}#if end			
3243
 
3244
							$eraseForeignKeyResult=db::eraseForeignKey($conf["db"]["eraseForeignKey"]);
3245
							unset($conf["db"]["eraseForeignKey"]);
3246
 
3247
							#執行的sql字串
3248
							$result["sql"][]=$eraseForeignKeyResult["sql"];
3249
 
3250
							#如果 $eraseForeignKeyResult["status"]等於"fasle"
3251
							if($eraseForeignKeyResult["status"]=="false"){
3252
 
3253
								#設置出錯的識別
3254
								$result["status"]="false";
3255
 
3256
								#設置錯誤訊息
3257
								$result["error"]=$eraseForeignKeyResult;
3258
 
3259
								#回傳結果
3260
								return $result;
3261
 
3262
								}#if end
3263
 
3264
							}#if end
3265
 
3266
						}#if end
3267
 
3268
					#如果 $tableColumnDetial["key"]["exist"] 等於 "true",代表有索引鍵
3269
					if($tableColumnDetial["key"]["exist"]=="true"){
3270
 
3271
						#檢查目標欄位是否為索引鍵
3272
						if(!isset($tableColumnDetial["index"][$conf["newColumnName"]])){
3273
 
3274
							#代表目標欄位不為索引鍵
3275
 
3276
							#建立索引鍵
43 liveuser 3277
							#函式說明:
1 liveuser 3278
							#新增資料表的欄位
43 liveuser 3279
							#回傳結果:
1 liveuser 3280
							#$result["status"],"true",代表執行成功;"false"代表執行失敗.
3281
							#$result["function"],當前執行的函數名稱.
3282
							#$result["error"],錯誤訊息陣列.
3283
							#$result["warning"],警告訊息.
3284
							#$result["sql"],執行的sql字串.
43 liveuser 3285
							#必填參數:
1 liveuser 3286
							$conf["db"]["setColumnIndex"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
3287
							$conf["db"]["setColumnIndex"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
3288
							$conf["db"]["setColumnIndex"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
3289
							$conf["db"]["setColumnIndex"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
3290
							$conf["db"]["setColumnIndex"]["indexedColumnName"]=$conf["newColumnName"];#要設爲index的欄位名稱
43 liveuser 3291
							#可省略參數:
1 liveuser 3292
 
3293
							#如果 $conf["dbPassword"] 存在
3294
							if(isset($conf["dbPassword"])){
3295
 
3296
								#則設定連線的密碼
3297
								$conf["db"]["setColumnIndex"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
3298
 
3299
								}#if end
3300
 
3301
							#如果有設定 $conf["dbPort"]	
3302
							if(isset($conf["dbPort"])){
3303
 
3304
								#設定 $conf["dbPort"]
3305
								$conf["db"]["setColumnIndex"]["dbPort"]=$conf["dbPort"];
3306
 
3307
								}#if end	
3308
 
3309
							$setColumnIndexResult=db::setColumnIndex($conf["db"]["setColumnIndex"]);
3310
							unset($conf["db"]["setColumnIndex"]);
3311
 
3312
							#如果設置 column index 失敗
3313
							if($setColumnIndexResult["status"]==="false"){
3314
 
3315
								#設置出錯的識別
3316
								$result["status"]="false";
3317
 
3318
								#設置錯誤訊息
3319
								$result["error"]=$setColumnIndexResult;
3320
 
3321
								#回傳結果
3322
								return $result;
3323
 
3324
								}#if end
3325
 
3326
							#如果有執行 sql
3327
							if(isset($setColumnIndexResult["sql"])){
3328
 
3329
								#取得執行的sql字串
3330
								$result["sql"][]=$setColumnIndexResult["sql"];
3331
 
3332
								}#if end
3333
 
3334
							#如果 $setColumnIndexResult["status"] 為 "fasle"
3335
							if($setColumnIndexResult["status"]=="fasle"){
3336
 
3337
								#設置出錯的識別
3338
								$result["status"]="false";
3339
 
3340
								#設置錯誤訊息
3341
								$result["error"]=$setColumnIndexResult;
3342
 
3343
								#回傳結果
3344
								return $result;
3345
 
3346
								}#if end
3347
 
3348
							}#if end
3349
 
3350
						}#if end
3351
 
3352
					#如果 $tableColumnDetial["key"]["exist"] 等於 "fasle",代表沒有索引鍵
3353
					if($tableColumnDetial["key"]["exist"]=="false"){
3354
 
3355
						#建立索引鍵
43 liveuser 3356
						#函式說明:
1 liveuser 3357
						#新增資料表的欄位
43 liveuser 3358
						#回傳結果:
1 liveuser 3359
						#$result["status"],"true",代表執行成功;"false"代表執行失敗
3360
						#$result["error"],錯誤訊息陣列
43 liveuser 3361
						#必填參數:
1 liveuser 3362
						$conf["db"]["setColumnIndex"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
3363
						$conf["db"]["setColumnIndex"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
3364
						$conf["db"]["setColumnIndex"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
3365
						$conf["db"]["setColumnIndex"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
3366
						$conf["db"]["setColumnIndex"]["indexedColumnName"]=$conf["newColumnName"];#要設爲index的欄位名稱
43 liveuser 3367
						#可省略參數:
1 liveuser 3368
 
3369
						#如果 $conf["dbPassword"] 存在
3370
						if(isset($conf["dbPassword"])){
3371
 
3372
							#則設定連線的密碼
3373
							$conf["db"]["setColumnIndex"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
3374
 
3375
							}#if end
3376
 
3377
						#如果有設定 $conf["dbPort"]	
3378
						if(isset($conf["dbPort"])){
3379
 
3380
							#設定 $conf["dbPort"]
3381
							$conf["db"]["setColumnIndex"]["dbPort"]=$conf["dbPort"];
3382
 
3383
							}#if end	
3384
 
3385
						$setColumnIndexResult=db::setColumnIndex($conf["db"]["setColumnIndex"]);
3386
						unset($conf["db"]["setColumnIndex"]);
3387
 
3388
						#取得執行的sql字串.
3389
						$result["sql"][]=$setColumnIndexResult["sql"];
3390
 
3391
						#如果 $setColumnIndexResult["status"] 為 "fasle"
3392
						if($setColumnIndexResult["status"]=="fasle"){
3393
 
3394
							#設置出錯的識別
3395
							$result["status"]="false";
3396
 
3397
							#設置錯誤訊息
3398
							$result["error"]=$setColumnIndexResult;
3399
 
3400
							#回傳結果
3401
							return $result;
3402
 
3403
							}#if end
3404
 
3405
						}#if end
3406
 
3407
					#中斷switch
3408
					break;
3409
 
3410
				#如果是 foreign key
3411
				case "foreign key":
3412
 
3413
					#echo "enter foreign key";
3414
 
3415
					#檢查該欄位是否為foreign key
3416
					#如果 $tableColumnDetial["foreignKey"]["exist"] 等於 "true",代表有外鍵
3417
					if($tableColumnDetial["foreignKey"]["exist"]=="true"){
3418
 
3419
						#echo "have foreig key";
3420
 
3421
						#如果 $tableColumnDetial["foreignKey"]["columnName"][$conf["dbInformation"]["newColumnName"]] 存在,則代表該欄位為索引鍵
3422
						if(isset($tableColumnDetial["foreignKey"]["columnName"][$conf["newColumnName"]])){
3423
 
3424
							#移除外鍵
43 liveuser 3425
							#函式說明:
1 liveuser 3426
							#移除資料表單1欄位的外鍵
43 liveuser 3427
							#回傳結果:
1 liveuser 3428
							#$result["status"],"true",代表執行成功;"false"代表執行失敗
3429
							#$result["error"],錯誤訊息陣列
43 liveuser 3430
							#必填參數:
1 liveuser 3431
							$conf["db"]["eraseForeignKey"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
3432
							$conf["db"]["eraseForeignKey"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
3433
							$conf["db"]["eraseForeignKey"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
3434
							$conf["db"]["eraseForeignKey"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
3435
							$conf["db"]["eraseForeignKey"]["erasedForeignKeyColumnConstraintName"]=$tableColumnDetial["foreignKey"]["constraintName"][$conf["newColumnName"]];#要移除外鍵欄位的CONSTRAINT名稱
43 liveuser 3436
							#可省略參數: 
1 liveuser 3437
 
3438
							#如果 $conf["dbPassword"] 存在
3439
							if(isset($conf["dbPassword"])){
3440
 
3441
								#則設定連線的密碼
3442
								$conf["db"]["eraseForeignKey"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
3443
 
3444
								}#if end
3445
 
3446
							#如果有設定 $conf["dbPort"]	
3447
							if(isset($conf["dbPort"])){
3448
 
3449
								#設定 $conf["dbPort"]
3450
								$conf["db"]["eraseForeignKey"]["dbPort"]=$conf["dbPort"];
3451
 
3452
								}#if end
3453
 
3454
							$eraseForeignKeyResult=db::eraseForeignKey($conf["db"]["eraseForeignKey"]);
3455
							unset($conf["db"]["eraseForeignKey"]);
3456
 
3457
							#取得執行的sql字串
3458
							$result["sql"][]=$eraseForeignKeyResult["sql"];
3459
 
3460
							#如果 $eraseForeignKeyResult["status"]等於"fasle"
3461
							if($eraseForeignKeyResult["status"]=="false"){
3462
 
3463
								#設置出錯的識別
3464
								$result["status"]="false";
3465
 
3466
								#設置錯誤訊息
3467
								$result["error"]=$eraseForeignKeyResult;
3468
 
3469
								#回傳結果
3470
								return $result;
3471
 
3472
								}#if end
3473
 
3474
							}#if end
3475
 
3476
						}#if end
3477
 
3478
					#檢查該欄位是否為index
3479
					#如果 $tableColumnDetial["key"]["exist"] 等於 "false",代表沒有索引鍵
3480
					if($tableColumnDetial["key"]["exist"]=="false"){
3481
 
3482
						#echo "have no index";
3483
 
3484
						#建立索引鍵
43 liveuser 3485
						#函式說明:
1 liveuser 3486
						#新增資料表的欄位
43 liveuser 3487
						#回傳結果:
1 liveuser 3488
						#$result["status"],"true",代表執行成功;"false"代表執行失敗
3489
						#$result["error"],錯誤訊息陣列
43 liveuser 3490
						#必填參數:
1 liveuser 3491
						$conf["db"]["setColumnIndex"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
3492
						$conf["db"]["setColumnIndex"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
3493
						$conf["db"]["setColumnIndex"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
3494
						$conf["db"]["setColumnIndex"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
3495
						$conf["db"]["setColumnIndex"]["indexedColumnName"]=$conf["newColumnName"];#要設爲index的欄位名稱
43 liveuser 3496
						#可省略參數:
1 liveuser 3497
 
3498
						#如果 $conf["dbPassword"] 存在
3499
						if(isset($conf["dbPassword"])){
3500
 
3501
							#則設定連線的密碼
3502
							$conf["db"]["setColumnIndex"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
3503
 
3504
							}#if end
3505
 
3506
						#如果有設定 $conf["dbPort"]	
3507
						if(isset($conf["dbPort"])){
3508
 
3509
							#設定 $conf["dbPort"]
3510
							$conf["db"]["setColumnIndex"]["dbPort"]=$conf["dbPort"];
3511
 
3512
							}#if end	
3513
 
3514
						$setColumnIndexResult=db::setColumnIndex($conf["db"]["setColumnIndex"]);
3515
						unset($conf["db"]["setColumnIndex"]);
3516
 
3517
						#取得執行的sql字串
3518
						$result["sql"][]=$setColumnIndexResult["sql"];
3519
 
3520
						#如果 $setColumnIndexResult["status"] 為 "false"
3521
						if($setColumnIndexResult["status"]=="false"){
3522
 
3523
							#設置出錯的識別
3524
							$result["status"]="false";
3525
 
3526
							#設置錯誤訊息
3527
							$result["error"]=$setColumnIndexResult;
3528
 
3529
							#回傳結果
3530
							return $result;
3531
 
3532
							}#if end
3533
 
3534
						}#if end
3535
 
3536
					#反之有索引鍵	
3537
					#如果目標欄位不是索引鍵
3538
					else if(!isset($tableColumnDetial["key"][$conf["newColumnName"]])){
3539
 
3540
						#建立索引鍵
43 liveuser 3541
						#函式說明:
1 liveuser 3542
						#新增資料表的欄位
43 liveuser 3543
						#回傳結果:
1 liveuser 3544
						#$result["status"],"true",代表執行成功;"false"代表執行失敗
3545
						#$result["error"],錯誤訊息陣列
43 liveuser 3546
						#必填參數:
1 liveuser 3547
						$conf["db"]["setColumnIndex"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
3548
						$conf["db"]["setColumnIndex"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
3549
						$conf["db"]["setColumnIndex"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
3550
						$conf["db"]["setColumnIndex"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
3551
						$conf["db"]["setColumnIndex"]["indexedColumnName"]=$conf["newColumnName"];#要設爲index的欄位名稱
43 liveuser 3552
						#可省略參數:
1 liveuser 3553
 
3554
						#如果 $conf["dbPassword"] 存在
3555
						if(isset($conf["dbPassword"])){
3556
 
3557
							#則設定連線的密碼
3558
							$conf["db"]["setColumnIndex"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
3559
 
3560
							}#if end
3561
 
3562
						#如果有設定 $conf["dbPort"]	
3563
						if(isset($conf["dbPort"])){
3564
 
3565
							#設定 $conf["dbPort"]
3566
							$conf["db"]["setColumnIndex"]["dbPort"]=$conf["dbPort"];
3567
 
3568
							}#if end			
3569
 
3570
						$setColumnIndexResult=db::setColumnIndex($conf["db"]["setColumnIndex"]);
3571
						unset($conf["db"]["setColumnIndex"]);
3572
 
3573
						#取得執行的sql字串
3574
						$result["sql"][]=$setColumnIndexResult["sql"];
3575
 
3576
						#如果 $setColumnIndexResult["status"] 為 "false"
3577
						if($setColumnIndexResult["status"]=="false"){
3578
 
3579
							#設置出錯的識別
3580
							$result["status"]="false";
3581
 
3582
							#設置錯誤訊息
3583
							$result["error"]=$setColumnIndexResult;
3584
 
3585
							#回傳結果
3586
							return $result;
3587
 
3588
							}#if end					
3589
 
3590
						}#else end
3591
 
3592
					#檢查該欄位的foreign key設定參數是否存在
43 liveuser 3593
					#函式說明:
1 liveuser 3594
					#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 3595
					#回傳結果:
1 liveuser 3596
					#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3597
					#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3598
					#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 3599
					#必填參數:
1 liveuser 3600
					$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
3601
					$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("foreignKeyReferenceTable","foreignKeyReferenceColumn");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 3602
					#可省略參數:
1 liveuser 3603
					#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
3604
					#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
3605
					$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
3606
					unset($conf["variableCheck"]["isexistMuti"]);
3607
 
3608
					#如果檢查失敗
3609
					if($checkResult["status"]=="false"){
3610
 
3611
						#設置執行失敗的訊息
3612
						$result["status"]="false";
3613
 
3614
						#設置錯誤訊息
3615
						$result["error"]=$checkResult;
3616
 
3617
						#回傳結果
3618
						return $result;
3619
 
3620
						}#if end
3621
 
3622
					#如果檢查不通過
3623
					if($checkResult["passed"]=="false"){
3624
 
3625
						#設置執行失敗的訊息
3626
						$result["status"]="false";
3627
 
3628
						#設置錯誤訊息
3629
						$result["error"]=$checkResult;
3630
 
3631
						#回傳結果
3632
						return $result;
3633
 
3634
						}#if end
3635
 
3636
					#如果 $conf["foreignKeyUpdateAction"] 不存在
3637
					if(!isset($conf["foreignKeyUpdateAction"])){
3638
 
3639
						#則預設為"CASCADE"將有所關聯的紀錄行也會進行刪除或修改。
3640
						$conf["foreignKeyUpdateAction"]="CASCADE";#若要設定foreign key的話,可以指定參考的資料表欄位更新時該欄位該怎麼處理,預設為"CASCADE",會將有所關聯的紀錄行也會進行刪除或修改。"SET NULL"代表會將有所關聯的紀錄行設定成 NULL。"NO ACTION"代表有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
3641
 
3642
						}#if end
3643
 
3644
					#如果 $conf["foreignKeyDeleteAction"] 沒有設定
3645
					if(!isset($conf["foreignKeyDeleteAction"])){
3646
 
3647
						#預設為"SET NULL",會將有所關聯的紀錄行設定成 NULL。
3648
						$conf["foreignKeyDeleteAction"]="SET NULL";#若要設定foreign key的話,可以指定參考的資料表欄位移除時該欄位該怎麼處理,預設為"SET NULL",會將有所關聯的紀錄行設定成 NULL。"NO ACTION"代表有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
3649
 
3650
						}#if end
3651
 
3652
					#檢查目標欄位的 key constraint 名稱
3653
					#取得其key為何種
43 liveuser 3654
					#函式說明:
1 liveuser 3655
					#取得資料表所有欄位的詳細資訊
3656
					#回傳的內容:
3657
					#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
3658
					#$result["error"],錯誤訊息陣列
3659
					#$result["sql"],執行的sql語法
3660
					#$result["oriInput"],原始的資料表欄位資訊
3661
					#$result["everyLine"],逐行的欄位資訊
3662
					#$result["tableName"],當前查詢的資料表名稱
3663
					#$result["engine"],資料表使用的儲存引擎
3664
					#$result["charset"],資料表預設的編碼
3665
					#$result["columnName"][$i],各欄位的名稱陣列,$i爲0開始的數字,也可以使用欄位的名稱。
3666
					#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲0開始的數字,也可以使用欄位的名稱。
3667
					#$result["columnNotNull"][$i],各欄位是否可以不爲null,"true"爲可以不爲null;"false"爲可以爲"null",$i爲0開始的數字,也可以使用欄位的名稱。
3668
					#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲0開始的數字,也可以使用欄位的名稱。
3669
					#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲0開始的數字,也可以使用欄位的名稱。
3670
					#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲0開始的數字,也可以使用欄位的名稱。
3671
					#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲0開始的數字,也可以使用欄位的名稱。
3672
					#$result["columnCollate"][$i],各欄位使用的Collate,$i爲0開始的數字,也可以使用欄位的名稱。
3673
					#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
3674
					#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
3675
					#$result["primaryKey"],該資料表的主鍵
3676
					#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
3677
					#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲0開始的數字,也可以使用欄位的名稱。
3678
					#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列
3679
					#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲0開始的數字
3680
					#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲0開始的數字
3681
					#$result["foreignKey"]["OnUpdateAction"][$l],當參照的欄位資料更新時,會怎麼同步,$l爲0開始的數字
3682
					#$result["foreignKey"]["OnDeleteAction"][$m],當參照的欄位資料移除時,會怎麼同步,$m爲0開始的數字
43 liveuser 3683
					#必填參數:
1 liveuser 3684
					$conf["db"]["getTableColumnDetailInfo"]["dbAddress"]=$conf["dbAddress"];
3685
					$conf["db"]["getTableColumnDetailInfo"]["dbAccount"]=$conf["dbAccount"];
3686
					$conf["db"]["getTableColumnDetailInfo"]["selectedDataBase"]=$conf["selectedDataBaseName"];
3687
					$conf["db"]["getTableColumnDetailInfo"]["selectedDataTable"]=$conf["selectedDataTableName"];
43 liveuser 3688
					#可省略參數:
1 liveuser 3689
 
3690
					#如果 $conf["dbPassword"] 有設定
3691
					if(isset($conf["dbPassword"])){
3692
 
3693
						#套用連限時的密碼
3694
						$conf["db"]["getTableColumnDetailInfo"]["dbPassword"]=$conf["dbPassword"];
3695
 
3696
						}#if end
3697
 
3698
					#如果有設定 $conf["dbPort"]	
3699
					if(isset($conf["dbPort"])){
3700
 
3701
						#設定 $conf["dbPort"]
3702
						$conf["db"]["getTableColumnDetailInfo"]["dbPort"]=$conf["dbPort"];
3703
 
3704
						}#if end			
3705
 
3706
					$tableColumnDetial=db::getTableColumnDetailInfo($conf["db"]["getTableColumnDetailInfo"]);
3707
					unset($conf["db"]["getTableColumnDetailInfo"]);#卸除變數,避免錯誤產生.
3708
 
3709
					#如果取得資料表結構失敗
3710
					if($tableColumnDetial["status"]=="false"){
3711
 
3712
						#設置執行不正常
3713
						$result["status"]="false";
3714
 
3715
						#設置執行錯誤訊息
3716
						$result["error"]=$tableColumnDetial;
3717
 
3718
						#回傳結果
3719
						return $result;
3720
 
3721
						}#if end	
3722
 
3723
					#依據設定將該欄位設定為foreign key
3724
 
3725
					#設定其參照的資料表與欄位的sql語法
3726
					$sql="alter table `".$conf["selectedDataBaseName"]."`.`".$conf["selectedDataTableName"]."` add FOREIGN KEY(`".$tableColumnDetial["key"][$conf["newColumnName"]]."`) REFERENCES `".$conf["foreignKeyDb"]."`.`".$conf["foreignKeyReferenceTable"]."`(`".$conf["foreignKeyReferenceColumn"]."`) ON UPDATE ".$conf["foreignKeyUpdateAction"]." ON DELETE ".$conf["foreignKeyDeleteAction"];
3727
 
3728
					#執行 sql 語法
43 liveuser 3729
					#函式說明:
1 liveuser 3730
					#執行mysql指令
43 liveuser 3731
					#回傳結果::
1 liveuser 3732
					#$result["status"],"true"為執行成功;"false"為執行失敗。
3733
					#$result["error"],錯誤訊息的陣列
3734
					#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
3735
					#$result["queryString"],mysql查詢的語言
3736
					#查詢號的解果,需要解析。
43 liveuser 3737
					#必填參數:
1 liveuser 3738
					$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
3739
					$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
3740
					$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
43 liveuser 3741
					#可省略參數: 
1 liveuser 3742
 
3743
					#如果有設定連線密碼
3744
					if(isset($conf["dbPassword"])){
3745
 
3746
						$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
3747
 
3748
						}#if end
3749
 
3750
					#$conf["db"]["execMysqlQuery"]["dbName"]=$conf["selectedDataBaseName"];#為是否要指定資料庫,預設不指定.
3751
 
3752
					#如果有設定 $conf["dbPort"]	
3753
					if(isset($conf["dbPort"])){
3754
 
3755
						#設定 $conf["dbPort"]
3756
						$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
3757
 
3758
						}#if end	
3759
 
3760
					$sqlExecResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
3761
					unset($conf["db"]["execMysqlQuery"]);
3762
 
3763
					#var_dump($sqlExecResult);
3764
 
3765
					#取得執行的sql語法
3766
					$result["sql"][]=$sqlExecResult["queryString"];
3767
 
3768
					#如果執行 sql 語法錯誤
3769
					if($sqlExecResult["status"]=="false"){
3770
 
3771
						#echo "fasle";
3772
 
3773
						#設定執行失敗的識別
3774
						$result["status"]="false";
3775
 
3776
						#設定錯誤訊息
3777
						$result["error"]=$sqlExecResult;
3778
 
3779
						#回傳結果
3780
						return $result;
3781
 
3782
						}#if end					
3783
 
3784
					#跳出 foreign key
3785
					break;
3786
 
3787
				#如果不是以上參數
3788
				default:
3789
 
3790
					#設定執行錯誤的識別
3791
					$result["status"]="false";
3792
 
3793
					#設定錯誤訊息
3794
					$result["error"]="可用的鍵型為index、foregin key、primary key";
3795
 
3796
					#回傳結果
3797
					return $result;
3798
 
3799
				}#switch end
3800
 
3801
			}#if end
3802
 
3803
		#執行到這邊代表執行成功
3804
		#設定執行成功的識別
3805
		$result["status"]="true";
3806
 
3807
		#回傳結果
3808
		return $result;
3809
 
3810
		}#function editColumn end
3811
 
3812
	/*
43 liveuser 3813
	#函式說明:
1 liveuser 3814
	#新增資料表的欄位
43 liveuser 3815
	#回傳結果:
1 liveuser 3816
	#$result["status"],"true",代表執行成功;"false"代表執行失敗.
3817
	#$result["function"],當前執行的函數名稱.
3818
	#$result["error"],錯誤訊息陣列.
3819
	#$result["warning"],警告訊息.
3820
	#$result["sql"],執行的sql字串.
43 liveuser 3821
	#必填參數:
1 liveuser 3822
	$conf["dbAddress"],字串,爲mysql-Server的位置.
3823
	$conf["dbAddress"]=$dbAddress;
3824
	$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號.
3825
	$conf["dbAccount"]=$dbAccount;
3826
	$conf["selectedDataBaseName"],字串,爲目標資料表所屬的資料庫.
3827
	$conf["selectedDataBaseName"]="";
3828
	$conf["selectedDataTableName"],字串,爲目標資料表所屬的資料庫.
3829
	$conf["selectedDataTableName"]="";
3830
	$conf["indexedColumnName"],字串,要設爲index的欄位名稱.
3831
	$conf["indexedColumnName"]="";
43 liveuser 3832
	#可省略參數:
1 liveuser 3833
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
3834
	#$conf["dbPassword"]=$dbPassword;
3835
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
3836
	#$conf["dbPort"]="3306";
185 liveuser 3837
	#參考資料:
3838
	#無.
43 liveuser 3839
	#備註:
3840
	#無.
1 liveuser 3841
	*/
3842
	public static function setColumnIndex($conf){
3843
 
3844
		#初始化要回傳的內容
3845
		$result=array();
3846
 
3847
		#取得當前執行的函數名稱
3848
		$result["function"]=__FUNCTION__;
3849
 
3850
		#如果 $conf 不為陣列
3851
		if(gettype($conf)!="array"){
3852
 
3853
			#設置執行失敗
3854
			$result["status"]="false";
3855
 
3856
			#設置執行錯誤訊息
3857
			$result["error"][]="\$conf變數須為陣列形態";
3858
 
3859
			#如果傳入的參數為 null
3860
			if($conf==null){
3861
 
3862
				#設置執行錯誤訊息
3863
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
3864
 
3865
				}#if end
3866
 
3867
			#回傳結果
3868
			return $result;
3869
 
3870
			}#if end
3871
 
43 liveuser 3872
		#函式說明:
1 liveuser 3873
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 3874
		#回傳結果:
1 liveuser 3875
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
3876
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
3877
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 3878
		#必填參數:
1 liveuser 3879
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
3880
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName","indexedColumnName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 3881
		#可省略參數:
1 liveuser 3882
		#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
3883
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
3884
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
3885
		unset($conf["variableCheck"]["isexistMuti"]);
3886
 
3887
		#如果檢查不通過
3888
		if($checkResult["passed"]=="false"){
3889
 
3890
			#設置執行失敗的訊息
3891
			$result["status"]="false";
3892
 
3893
			#設置錯誤訊息
3894
			$result["error"]=$checkResult;
3895
 
3896
			#回傳結果
3897
			return $result;
3898
 
3899
			}#if end
3900
 
3901
		#查詢該欄位是否已經是index了
43 liveuser 3902
		#函式說明:
1 liveuser 3903
		#取得資料表所有欄位的詳細資訊
3904
		#回傳的內容:
3905
		#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
3906
		#$result["error"],錯誤訊息陣列
3907
		#$result["function"],當前執行的函數名稱.
3908
		#$result["sql"],執行的sql語法
3909
		#$result["oriInput"],原始的資料表欄位資訊
3910
		#$result["everyLine"],逐行的欄位資訊
3911
		#$result["tableName"],當前查詢的資料表名稱
3912
		#$result["engine"],資料表使用的儲存引擎
3913
		#$result["charset"],資料表預設的編碼
3914
		#$result["columnName"][$i],各欄位的名稱陣列,$i爲1開始的數字,也可以使用欄位的名稱。
3915
		#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲1開始的數字,也可以使用欄位的名稱。
3916
		#$result["columnVarType"][$i],各欄位變數儲存的型態,$i爲1開始的數字,也可以使用欄位的名稱.
3917
		#$result["columnVarLengthLimit"][$i],個欄位變數的長度限制,若不存在其限制,則為"",$i爲1開始的數字,也可以使用欄位的名稱.
3918
		#$result["columnNotNull"][$i],各欄位是否不可爲null,"true"爲不可以爲null;"false"爲可爲"null",$i爲1開始的數字,也可以使用欄位的名稱。
3919
		#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲1開始的數字,也可以使用欄位的名稱。
3920
		#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲1開始的數字,也可以使用欄位的名稱。
3921
		#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲1開始的數字,也可以使用欄位的名稱。
3922
		#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲1開始的數字,也可以使用欄位的名稱。
3923
		#$result["columnCollate"][$i],各欄位使用的Collate,$i爲1開始的數字,也可以使用欄位的名稱。
3924
		#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
3925
		#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
3926
		#$result["keyConstraintName"][$j],該資料表用於識別索引鍵的CONSTRAINT名稱陣列,$j爲1開始的數字,也可以使用欄位的名稱。
3927
		#$result["primaryKey"],該資料表的主鍵
3928
		#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
3929
		#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
3930
		#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
3931
		#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲1開始的數字,,也可用欄位的名稱來找value.
3932
		#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲1開始的數字,也可用欄位的名稱來找value.
3933
		#$result["foreignKey"]["onUpdateAction"][$i],當參照的欄位資料更新時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
3934
		#$result["foreignKey"]["onDeleteAction"][$i],當參照的欄位資料移除時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
43 liveuser 3935
		#必填參數:
1 liveuser 3936
		$conf["db::getTableColumnDetailInfo"]["dbAddress"]=$conf["dbAddress"];#資料庫的網路位置
3937
		$conf["db::getTableColumnDetailInfo"]["dbAccount"]=$conf["dbAccount"];#連線到資料庫要用的帳號
3938
		$conf["db::getTableColumnDetailInfo"]["selectedDataBase"]=$conf["selectedDataBaseName"];#連線到資料庫要選擇的資料庫
3939
		$conf["db::getTableColumnDetailInfo"]["selectedDataTable"]=$conf["selectedDataTableName"];#連線到資料庫要檢視的資料表
43 liveuser 3940
		#可省略參數:
1 liveuser 3941
 
3942
		#如果 $conf["dbPassword"] 有設定
3943
		if(isset($conf["dbPassword"])){
3944
 
3945
			#設定其密碼
3946
			$conf["db::getTableColumnDetailInfo"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
3947
 
3948
			}#if end
3949
 
3950
		#如果有設定 $conf["dbPort"]	
3951
		if(isset($conf["dbPort"])){
3952
 
3953
			#設定 $conf["dbPort"]
3954
			$conf["db::getTableColumnDetailInfo"]["dbPort"]=$conf["dbPort"];
3955
 
3956
			}#if end
3957
 
3958
		#備註:
3959
		#如果forign key參照的是別的資料庫,將無法取得參照的資料庫名稱?
3960
		$getTableColumnDetailInfo=db::getTableColumnDetailInfo($conf["db::getTableColumnDetailInfo"]);
3961
		unset($conf["db::getTableColumnDetailInfo"]);	
3962
 
3963
		#如果取得資料表資訊失敗
3964
		if($getTableColumnDetailInfo["status"]=="false"){
3965
 
3966
			#設置錯誤訊息
3967
			$result["status"]="false";
3968
 
3969
			#設置錯誤提示
3970
			$result["error"]=$getTableColumnDetailInfo;
3971
 
3972
			#回傳結果
3973
			return $result;
3974
 
3975
			}#if end	
3976
 
3977
		#如果該欄位已經是index了
3978
		if(isset($getTableColumnDetailInfo["key"][$conf["indexedColumnName"]])){
3979
 
3980
			#設置執行正常
3981
			$result["status"]="true";
3982
 
3983
			#設置警告提示
3984
			$result["warning"][]="已經是index key了";
3985
 
3986
			#回傳結果
3987
			return $result;
3988
 
3989
			}#if end
3990
 
3991
		#組合sql語言
3992
		$sql="alter table ".$conf["selectedDataBaseName"].".".$conf["selectedDataTableName"]." add index(`".$conf["indexedColumnName"]."`)";
3993
 
3994
		#執行sql語法
43 liveuser 3995
		#函式說明:
1 liveuser 3996
		#執行mysql指令
43 liveuser 3997
		#回傳結果::
1 liveuser 3998
		#$result["status"],"true"為執行成功;"false"為執行失敗。
3999
		#$result["error"],錯誤訊息的陣列
4000
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
4001
		#$result["queryString"],mysql查詢的語言
4002
		#查詢號的解果,需要解析。
43 liveuser 4003
		#必填參數:
1 liveuser 4004
		$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
4005
		$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
4006
		$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
43 liveuser 4007
		#可省略參數:
1 liveuser 4008
 
4009
		#如果 $conf["dbPassword"] 有設定
4010
		if(isset($conf["dbPassword"])){
4011
 
4012
			#設定其密碼
4013
			$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
4014
 
4015
			}#if end
4016
 
4017
		#如果有設定 $conf["dbPort"]	
4018
		if(isset($conf["dbPort"])){
4019
 
4020
			#設定 $conf["dbPort"]
4021
			$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
4022
 
4023
			}#if end
4024
 
4025
		$queryResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
4026
		unset($conf["db"]["execMysqlQuery"]);
4027
 
4028
		#取得執行的sql語法
4029
		$result["sql"]=$queryResult["queryString"];
4030
 
4031
		#如果有錯誤
4032
		if($queryResult["status"]=="false"){
4033
 
4034
			#設置錯誤訊息
4035
			$result["status"]="false";
4036
 
4037
			#設置錯誤提示
4038
			$result["error"]=$queryResult;
4039
 
4040
			#回傳結果
4041
			return $result;
4042
 
4043
			}#if end
4044
 
4045
		#執行到這邊代表執行成功
4046
 
4047
		#設置成功訊息
4048
		$result["status"]="true";
4049
 
4050
		#回傳結果
4051
		return $result;
4052
 
4053
		}#function setColumnIndex end
4054
 
4055
	/*
43 liveuser 4056
	#函式說明:
1 liveuser 4057
	#取得資料表所有欄位的詳細資訊
4058
	#回傳的內容:
4059
	#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
4060
	#$result["error"],錯誤訊息陣列
4061
	#$result["function"],當前執行的函數名稱.
4062
	#$result["sql"],執行的sql語法
4063
	#$result["oriInput"],原始的資料表欄位資訊
4064
	#$result["everyLine"],逐行的欄位資訊
4065
	#$result["tableName"],當前查詢的資料表名稱
4066
	#$result["engine"],資料表使用的儲存引擎
4067
	#$result["charset"],資料表預設的編碼
4068
	#$result["columnName"][$i],各欄位的名稱陣列,$i爲1開始的數字,也可以使用欄位的名稱。
4069
	#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲1開始的數字,也可以使用欄位的名稱。
4070
	#$result["columnVarType"][$i],各欄位變數儲存的型態,$i爲1開始的數字,也可以使用欄位的名稱.
4071
	#$result["columnVarLengthLimit"][$i],個欄位變數的長度限制,若不存在其限制,則為"",$i爲1開始的數字,也可以使用欄位的名稱.
4072
	#$result["columnNotNull"][$i],各欄位是否不可爲null,"true"爲不可以爲null;"false"爲可爲"null",$i爲1開始的數字,也可以使用欄位的名稱。
4073
	#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲1開始的數字,也可以使用欄位的名稱。
4074
	#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲1開始的數字,也可以使用欄位的名稱。
4075
	#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲1開始的數字,也可以使用欄位的名稱。
4076
	#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲1開始的數字,也可以使用欄位的名稱。
4077
	#$result["columnCollate"][$i],各欄位使用的Collate,$i爲1開始的數字,也可以使用欄位的名稱。
4078
	#$result["columnComment"][$i],各欄位的註解,$i爲1開始的數字,也可以使用欄位的名稱。
4079
	#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
4080
	#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
4081
	#$result["keyConstraintName"][$j],該資料表用於識別索引鍵的CONSTRAINT名稱陣列,$j爲1開始的數字,也可以使用欄位的名稱。
4082
	#$result["primaryKey"],該資料表的主鍵
4083
	#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
4084
	#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
4085
	#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
4086
	#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲1開始的數字,,也可用欄位的名稱來找value.
4087
	#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲1開始的數字,也可用欄位的名稱來找value.
4088
	#$result["foreignKey"]["onUpdateAction"][$i],當參照的欄位資料更新時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
4089
	#$result["foreignKey"]["onDeleteAction"][$i],當參照的欄位資料移除時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
43 liveuser 4090
	#必填參數:
1 liveuser 4091
	#$conf["dbAddress"],字串,資料庫的網路位置
4092
	$conf["dbAddress"]="";
4093
	#$conf["dbAccount"],字串,連線到資料庫要用的帳號
4094
	$conf["dbAccount"]="";連線到資料庫要用的帳號
4095
	#$conf["selectedDataBase"]字串,連線到資料庫要選擇的資料庫
4096
	$conf["selectedDataBase"]=$dbName;
4097
	#$conf["selectedDataTable"],字串,連線到資料庫要檢視的資料表
4098
	$conf["selectedDataTable"]="";
43 liveuser 4099
	#可省略參數:
1 liveuser 4100
	#$conf["dbPassword"],字串,連線到資料庫要用的密碼
4101
	#$conf["dbPassword"]=$dbPassword;
4102
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
4103
	#$conf["dbPort"]="3306";
185 liveuser 4104
	#參考資料:
4105
	#無.
1 liveuser 4106
	#備註:
4107
	#如果forign key參照的是別的資料庫,將無法取得參照的資料庫名稱?
4108
	*/
4109
	public static function getTableColumnDetailInfo(&$conf){
4110
 
4111
		#初始化要回傳的內容
4112
		$result=array();
4113
 
4114
		#取得當前執行的函數名稱
4115
		$result["function"]=__FUNCTION__;
4116
 
4117
		#如果 $conf 不為陣列
4118
		if(gettype($conf)!="array"){
4119
 
4120
			#設置執行失敗
4121
			$result["status"]="false";
4122
 
4123
			#設置執行錯誤訊息
4124
			$result["error"][]="\$conf變數須為陣列形態";
4125
 
4126
			#如果傳入的參數為 null
4127
			if($conf==null){
4128
 
4129
				#設置執行錯誤訊息
4130
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
4131
 
4132
				}#if end
4133
 
4134
			#回傳結果
4135
			return $result;
4136
 
4137
			}#if end
4138
 
4139
		#檢查參數設定是否正確
43 liveuser 4140
		#函式說明:
1 liveuser 4141
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
4142
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4143
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
4144
		#$result["function"],當前執行的函式名稱.
4145
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
4146
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
4147
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
4148
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
4149
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
4150
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
4151
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
4152
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
43 liveuser 4153
		#必填參數:
1 liveuser 4154
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
4155
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
4156
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
4157
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","selectedDataBase","selectedDataTable");
4158
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
4159
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string");
4160
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
4161
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
43 liveuser 4162
		#可省略參數:
1 liveuser 4163
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
4164
		#$conf["canBeEmptyString"]="false";
4165
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
4166
		#$conf["skipableVariableCanNotBeEmpty"]=array();
4167
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
4168
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort");
4169
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
4170
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
4171
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
4172
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null);
4173
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
4174
		#$conf["arrayCountEqualCheck"][]=array();
43 liveuser 4175
		#參考資料:
1 liveuser 4176
		#array_keys=>http://php.net/manual/en/function.array-keys.php
4177
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
4178
		unset($conf["variableCheck::checkArguments"]);
4179
 
4180
		#如果檢查失敗
4181
		if($checkArguments["passed"]=="false"){
4182
 
4183
			#設置執行失敗識別
4184
			$result["status"]="false";
4185
 
4186
			#設置錯誤訊息陣列
4187
			$result["error"]=$checkArguments;
4188
 
4189
			#回傳結果
4190
			return $result;
4191
 
4192
			}#if end
4193
 
4194
		#如果檢查不通過
4195
		if($checkArguments["passed"]=="false"){
4196
 
4197
			#設置執行失敗識別
4198
			$result["status"]="false";
4199
 
4200
			#設置錯誤訊息陣列
4201
			$result["error"]=$checkArguments;
4202
 
4203
			#回傳結果
4204
			return $result;
4205
 
4206
			}#if end
4207
 
4208
		#設置要執行的sql語法
4209
		$sql="SHOW CREATE TABLE ".$conf["selectedDataBase"].".".$conf["selectedDataTable"].";";
4210
 
4211
		#執行sql語法
43 liveuser 4212
		#函式說明:
1 liveuser 4213
		#執行mysql指令
43 liveuser 4214
		#回傳結果::
1 liveuser 4215
		#$result["status"],"true"為執行成功;"false"為執行失敗。
4216
		#$result["error"],錯誤訊息的陣列
4217
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
4218
		#$result["queryString"],mysql查詢的語言
4219
		#查詢號的解果,需要解析。
43 liveuser 4220
		#必填參數:
1 liveuser 4221
		$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
4222
		$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
4223
		$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
43 liveuser 4224
		#可省略參數:
1 liveuser 4225
 
4226
		#如果 $conf["dbPassword"] 有設定
4227
		if(isset($conf["dbPassword"])){
4228
 
4229
			#設定其密碼
4230
			$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
4231
 
4232
			}#if end
4233
 
4234
		#如果有設定 $conf["dbPort"]	
4235
		if(isset($conf["dbPort"])){
4236
 
4237
			#設定 $conf["dbPort"]
4238
			$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
4239
 
4240
			}#if end			
4241
 
4242
		$queryResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
4243
		unset($conf["db"]["execMysqlQuery"]);
4244
 
4245
		#如果有錯誤
4246
		if($queryResult["status"]=="false"){
4247
 
4248
			#設置錯誤訊息
4249
			$result["status"]="false";
4250
 
4251
			#設置錯誤提示
4252
			$result["error"]=$queryResult;
4253
 
4254
			#回傳結果
4255
			return $result;
4256
 
4257
			}#if end
4258
 
4259
		#解析mysql resource
4260
 
4261
		#初始化暫存的變數
4262
		$temp="";
4263
 
4264
		#將讀取到的資料一次只讀取一列
4265
		while($row = mysqli_fetch_array($queryResult["queryResource"])){
4266
 
4267
			#$i筆項列資料,則運行$i次。
4268
			foreach($row as $key=>$value){		
4269
 
4270
				#如果key爲"Create Table"
4271
				if($key=="Create Table"){
4272
 
4273
					#將解析的資料內容結果放進$temp變數裏面
4274
					$temp=$value;	
4275
 
4276
					}#if end
4277
 
4278
				}#foreach end
4279
 
4280
			}#while end
4281
 
4282
		#逐行解析$temp
43 liveuser 4283
		#函式說明:
1 liveuser 4284
		#將多行內容的字串,依行切割
4285
		#回傳的參數:
4286
		#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
4287
		#$result["error"],錯誤訊息陣列.
4288
		#$result["function"],當前執行的函數名稱.#$result["oriStr"],要分割的原始字串內容
4289
		#$result["oriStr"],要分割的原始字串內容
4290
		#$result["dataArray"],爲以行分割好的字串陣列內容,$result["dataArray"][$i]爲第($i+1)行的內容。
4291
		#$result["dataCounts"],爲總共分成幾行
43 liveuser 4292
		#必填參數:
1 liveuser 4293
		$conf["stringProcess"]["spiltMutiLineString"]["stringIn"]=$temp;#要處理的多行文字字串。
4294
		#參考資料來源:
4295
		#http://dragonspring.pixnet.net/blog/post/33146613-%5blinux%5d%5btips%5d%e5%8e%bb%e9%99%a4dos%e6%aa%94%e6%a1%88%e8%a1%8c%e5%b0%be%e7%9a%84%5em => windows 與 linux 換行字元
4296
		$everyLine=stringProcess::spiltMutiLineString($conf["stringProcess"]["spiltMutiLineString"]);
4297
		unset($conf["stringProcess"]["spiltMutiLineString"]);
4298
 
4299
		#如果 逐行解析$temp 失敗
4300
		if($everyLine["status"]==="false"){
4301
 
4302
			#設置錯誤訊息
4303
			$result["status"]="false";
4304
 
4305
			#設置錯誤提示
4306
			$result["error"]=$everyLine;
4307
 
4308
			#回傳結果
4309
			return $result;
4310
 
4311
			}#if end
4312
 
4313
		#針對每列內容
4314
		foreach($everyLine["dataArray"] as $no => $line){
4315
 
43 liveuser 4316
			#函式說明:
1 liveuser 4317
			#取得符合特定字首與字尾的字串
43 liveuser 4318
			#回傳結果::
1 liveuser 4319
			#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
4320
			#$result["function"],當前執行的函數名稱.
4321
			#$result["error"],錯誤訊息陣列.
4322
			#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
4323
			#$result["returnString"],爲符合字首條件的字串內容。
4324
			#$result["argu"],使用的參數.
4325
			#必填參數:
4326
			#$conf["checkString"],字串,要檢查的字串.
4327
			$conf["search::getMeetConditionsString"]["checkString"]=$line;
4328
			#可省略參數:
4329
			#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
4330
			$conf["search::getMeetConditionsString"]["frontWord"]="/*";
4331
			#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
4332
			#$conf["tailWord"]="";
4333
			#參考資料:
4334
			#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
4335
			$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
4336
			unset($conf["search::getMeetConditionsString"]);			
4337
 
4338
			#如果執行失敗
4339
			if($getMeetConditionsString["status"]==="false"){
4340
 
4341
				#設置錯誤訊息
4342
				$result["status"]="false";
4343
 
4344
				#設置錯誤提示
4345
				$result["error"]=$getMeetConditionsString;
4346
 
4347
				#回傳結果
4348
				return $result;
4349
 
4350
				}#if end
4351
 
4352
			#如果執行失敗
4353
			if($getMeetConditionsString["founded"]==="true"){
4354
 
4355
				#while loop
4356
				while(true){
4357
 
4358
					#移除 partion 描述 - start 
4359
 
4360
					#如果存在該列
4361
					if(isset($everyLine["dataArray"][$no])){
4362
 
4363
						#卸除之
4364
						unset($everyLine["dataArray"][$no]);
4365
 
4366
						#行數加1
4367
						$no++;
4368
 
4369
						}#if end
4370
 
4371
					#移除 partion 描述 - end
4372
 
4373
					#反之
4374
					else{
4375
 
4376
						//end while
4377
						break;
4378
 
4379
						}#else end						
4380
 
4381
					}#while loop end
4382
 
4383
				#end foreach
4384
				break;
4385
 
4386
				}#if end
4387
 
4388
			}#foreach end
4389
 
4390
		#重新更新總行數
4391
		$everyLine["dataCounts"]=count($everyLine["dataArray"]);
4392
 
4393
		#取得原始輸入的多行字串
4394
		$result["oriInput"]=$everyLine["oriStr"];
4395
 
4396
		#取得原始的每一行
4397
		$result["everyLine"]=$everyLine["dataArray"];
4398
 
4399
		#取得資料表名稱
43 liveuser 4400
		#函式說明:
1 liveuser 4401
		#將固定格式的字串分開,並回傳分開的結果。
4402
		#回傳的參數:
4403
		#$result["oriStr"],要分割的原始字串內容
4404
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4405
		#$result["dataCounts"],爲總共分成幾段
43 liveuser 4406
		#必填參數:
1 liveuser 4407
		$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][0];#要處理的字串。
4408
		$conf["stringProcess"]["spiltString"]["spiltSymbol"]="`";#爲以哪個符號作爲分割
4409
		$tableName=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
4410
		unset($conf["stringProcess"]["spiltString"]);
4411
 
4412
		#如果 取得資料表名稱 失敗
4413
		if($tableName["status"]=="false"){
4414
 
4415
			#設置錯誤訊息
4416
			$result["status"]="false";
4417
 
4418
			#設置錯誤提示
4419
			$result["error"]=$tableName;
4420
 
4421
			#回傳結果
4422
			return $result;
4423
 
4424
			}#if end
4425
 
4426
		#取得資料表名稱
4427
		$result["tableName"]=$tableName["dataArray"][1];
4428
 
4429
		#取得資料表用的 ENGINE 與 DEFAULT CHARSET",亦即最後一行的內容.
43 liveuser 4430
		#函式說明:
1 liveuser 4431
		#將固定格式的字串分開,並回傳分開的結果。
4432
		#回傳的參數:
4433
		#$result["oriStr"],要分割的原始字串內容
4434
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4435
		#$result["dataCounts"],爲總共分成幾段
43 liveuser 4436
		#必填參數:
1 liveuser 4437
		$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][$everyLine["dataCounts"]-1];#要處理的字串。
4438
		$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
4439
		$engineAndCharset=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
4440
		unset($conf["stringProcess"]["spiltString"]);
4441
 
4442
		#如果 取得資料表用的 ENGINE與DEFAULT CHARSET" 失敗
4443
		if($engineAndCharset["status"]=="false"){
4444
 
4445
			#設置錯誤訊息
4446
			$result["status"]="false";
4447
 
4448
			#設置錯誤提示
4449
			$result["error"]=$engineAndCharset;
4450
 
4451
			#回傳結果
4452
			return $result;
4453
 
4454
			}#if end
4455
 
4456
		#get engine string
4457
		$engine=$engineAndCharset["dataArray"][1];
4458
 
43 liveuser 4459
		#函式說明:
1 liveuser 4460
		#將固定格式的字串分開,並回傳分開的結果。
4461
		#回傳的參數:
4462
		#$result["oriStr"],要分割的原始字串內容
4463
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4464
		#$result["dataCounts"],爲總共分成幾段
43 liveuser 4465
		#必填參數:
1 liveuser 4466
		$conf["stringProcess"]["spiltString"]["stringIn"]=$engine;#要處理的字串。
4467
		$conf["stringProcess"]["spiltString"]["spiltSymbol"]="=";#爲以哪個符號作爲分割
4468
		$engine=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
4469
		unset($conf["stringProcess"]["spiltString"]);
4470
 
4471
		#如果 取得資料表用的 ENGINE與DEFAULT CHARSET" 失敗
4472
		if($engine["status"]=="false"){
4473
 
4474
			#設置錯誤訊息
4475
			$result["status"]="false";
4476
 
4477
			#設置錯誤提示
4478
			$result["error"]=$engine;
4479
 
4480
			#回傳結果
4481
			return $result;
4482
 
4483
			}#if end
4484
 
4485
		#如果不存在 engine
4486
		if(!isset($engine["dataArray"][1])){
4487
 
4488
			#設置錯誤訊息
4489
			$result["status"]="false";
4490
 
4491
			#設置錯誤提示
4492
			$result["error"]=$engine;
4493
 
4494
			return $result;
4495
 
4496
			}#if end
4497
 
4498
		#get engine
4499
		$result["engine"]=$engine["dataArray"][1];
4500
 
4501
		#取得字元編碼
43 liveuser 4502
		#函式說明:
1 liveuser 4503
		#將固定格式的字串分開,並回傳分開的結果。
4504
		#回傳的參數:
4505
		#$result["oriStr"],要分割的原始字串內容
4506
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4507
		#$result["dataCounts"],爲總共分成幾段
43 liveuser 4508
		#必填參數:
1 liveuser 4509
		$conf["stringProcess"]["spiltString"]["stringIn"]=$engineAndCharset["oriStr"];#要處理的字串。
4510
		$conf["stringProcess"]["spiltString"]["spiltSymbol"]="CHARSET=";#爲以哪個符號作爲分割
4511
		$charset=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
4512
		unset($conf["stringProcess"]["spiltString"]);
4513
 
4514
		#如果 取得字元編碼 失敗
4515
		if($charset["status"]=="false"){
4516
 
4517
			#設置錯誤訊息
4518
			$result["status"]="false";
4519
 
4520
			#設置錯誤提示
4521
			$result["error"]=$charset;
4522
 
4523
			#回傳結果
4524
			return $result;
4525
 
4526
			}#if end
4527
 
4528
		#取得字元編碼
43 liveuser 4529
		#函式說明:
1 liveuser 4530
		#將固定格式的字串分開,並回傳分開的結果。
4531
		#回傳的參數:
4532
		#$result["oriStr"],要分割的原始字串內容
4533
		#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4534
		#$result["dataCounts"],爲總共分成幾段
43 liveuser 4535
		#必填參數:
1 liveuser 4536
		$conf["stringProcess"]["spiltString"]["stringIn"]=$charset["dataArray"][1];#要處理的字串。
4537
		$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
4538
		$charset=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
4539
		unset($conf["stringProcess"]["spiltString"]);
4540
 
4541
		#如果 取得字元編碼 失敗
4542
		if($charset["status"]=="false"){
4543
 
4544
			#設置錯誤訊息
4545
			$result["status"]="false";
4546
 
4547
			#設置錯誤提示
4548
			$result["error"]=$charset;
4549
 
4550
			#回傳結果
4551
			return $result;
4552
 
4553
			}#if end
4554
 
4555
		#取得字元編碼
4556
		$result["charset"]=$charset["dataArray"][0];
4557
 
4558
		#初始化,儲存鍵值定義的陣列變數
4559
		$keyDefine=array();
4560
 
4561
		#逐行取得各欄位詳細資料
4562
		for($i=1;$i<$everyLine["dataCounts"]-1;$i++){
4563
 
4564
			#檢查開頭是否爲 "  `"
43 liveuser 4565
 			#函式說明:
1 liveuser 4566
			#取得符合特定字首與字尾的字串
43 liveuser 4567
			#回傳結果::
1 liveuser 4568
			#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
4569
			#$result["function"],當前執行的函數名稱.
4570
			#$result["error"],錯誤訊息陣列.
4571
			#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
4572
			#$result["returnString"],爲符合字首條件的字串內容。
4573
			#必填參數:
4574
			#$conf["checkString"],字串,要檢查的字串.
4575
			$conf["search::getMeetConditionsString"]["checkString"]=$everyLine["dataArray"][$i];
4576
			#可省略參數:
4577
			#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
4578
			$conf["search::getMeetConditionsString"]["frontWord"]="  `";
4579
			#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
4580
			#$conf["tailWord"]="";
4581
			#參考資料:
4582
			#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
4583
			$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
4584
			unset($conf["search::getMeetConditionsString"]);
4585
 
4586
			#如果分割失敗
4587
			if($getMeetConditionsString["status"]==="false"){
4588
 
4589
				#設置錯誤訊息
4590
				$result["status"]="false";
4591
 
4592
				#設置錯誤提示
4593
				$result["error"]=$getMeetConditionsString;
4594
 
4595
				#回傳結果
4596
				return $result;
4597
 
4598
				}#if end
4599
 
4600
			#如果有符合的前戳
4601
			if($getMeetConditionsString["founded"]==="true"){
4602
 
43 liveuser 4603
				#函式說明:
1 liveuser 4604
				#將固定格式的字串分開,並回傳分開的結果。
4605
				#回傳的參數:
4606
				#$result["oriStr"],要分割的原始字串內容
4607
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4608
				#$result["dataCounts"],爲總共分成幾段
43 liveuser 4609
				#必填參數:
1 liveuser 4610
				$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][$i];#要處理的字串。
4611
				$conf["stringProcess"]["spiltString"]["spiltSymbol"]="`";#爲以哪個符號作爲分割
4612
				$columnString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
4613
				unset($conf["stringProcess"]["spiltString"]);
4614
 
4615
				#如果 分割字串失敗 失敗
4616
				if($columnString["status"]==="false"){
4617
 
4618
					#設置錯誤訊息
4619
					$result["status"]="false";
4620
 
4621
					#設置錯誤提示
4622
					$result["error"]=$columnString;
4623
 
4624
					#回傳結果
4625
					return $result;
4626
 
4627
					}#if end
4628
 
4629
				#取得欄位名稱
4630
				$result["columnName"][$i]=$columnString["dataArray"][1];
4631
				$result["columnName"][$result["columnName"][$i]]=$result["columnName"][$i];
4632
 
43 liveuser 4633
				#函式說明:
1 liveuser 4634
				#將固定格式的字串分開,並回傳分開的結果。
4635
				#回傳的參數:
4636
				#$result["oriStr"],要分割的原始字串內容
4637
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4638
				#$result["dataCounts"],爲總共分成幾段
43 liveuser 4639
				#必填參數:
1 liveuser 4640
				$conf["stringProcess"]["spiltString"]["stringIn"]=$columnString["dataArray"][2];#要處理的字串。
4641
				$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
4642
				$columnString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
4643
				unset($conf["stringProcess"]["spiltString"]);
4644
 
4645
				#debug
4646
				#var_dump($columnString);
4647
 
4648
				#如果 分割字串失敗 失敗
4649
				if($columnString["status"]==="false"){
4650
 
4651
					#設置錯誤訊息
4652
					$result["status"]="false";
4653
 
4654
					#設置錯誤提示
4655
					$result["error"]=$columnString;
4656
 
4657
					#回傳結果
4658
					return $result;
4659
 
4660
					}#if end
4661
 
4662
				#取得欄位屬性與長度
4663
				$result["columnVarTypeAndLengthLimit"][$i]=$columnString["dataArray"][0];
4664
				$result["columnVarTypeAndLengthLimit"][$result["columnName"][$i]]=$columnString["dataArray"][0];
4665
 
4666
				}#if end
4667
 
43 liveuser 4668
			#函式說明:
1 liveuser 4669
			#將固定格式的字串分開,並回傳分開的結果。
4670
			#回傳的參數:
4671
			#$result["oriStr"],要分割的原始字串內容
4672
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4673
			#$result["dataCounts"],爲總共分成幾段
43 liveuser 4674
			#必填參數:
1 liveuser 4675
			$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][$i];#要處理的字串。
4676
			$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
4677
			$columnString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
4678
			unset($conf["stringProcess"]["spiltString"]);	
4679
 
4680
			#如果 分割字串失敗 失敗
4681
			if($columnString["status"]=="false"){
4682
 
4683
				#設置錯誤訊息
4684
				$result["status"]="false";
4685
 
4686
				#設置錯誤提示
4687
				$result["error"]=$columnString;
4688
 
4689
				#回傳結果
4690
				return $result;
4691
 
4692
				}#if end
4693
 
4694
			#如果分割字串失敗
4695
			if($columnString["status"]==="false"){
4696
 
4697
				#設置執行失敗
4698
				$reuslt["status"]="false";
4699
 
4700
				#設置錯誤訊息
4701
				$result["error"]=$columnString;
4702
 
4703
				#回傳結果
4704
				return $result;
4705
 
4706
				}#if end
4707
 
4708
			#debug
4709
			#var_dump($columnString);
4710
 
4711
			#判斷該 $columnString["dataArray"][2]是一般名稱,還是鍵值定義。
43 liveuser 4712
			#函式說明:
1 liveuser 4713
			#檢查字串裡面有無指定的關鍵字
43 liveuser 4714
			#回傳結果::
1 liveuser 4715
			#$result["status"],"true"代表執行成功,"false"代表執行失敗。
4716
			#$result["error"],錯誤訊息
4717
			#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 4718
			#必填參數:
1 liveuser 4719
			$conf["search"]["findKeyWord"]["keyWord"]="`";#想要搜尋的關鍵字
4720
			$conf["search"]["findKeyWord"]["string"]=$columnString["dataArray"][2];#要被搜尋的字串內容
43 liveuser 4721
			#可省略參數:
1 liveuser 4722
			#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
4723
			$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
4724
			unset($conf["search"]["findKeyWord"]);
4725
 
4726
			#如果尋找失敗
4727
			if($searchResult["status"]==="false"){
4728
 
4729
				#設置執行失敗
4730
				$reuslt["status"]="false";
4731
 
4732
				#設置錯誤訊息
4733
				$result["error"]=$columnString;
4734
 
4735
				#回傳結果
4736
				return $result;
4737
 
4738
				}#if end
4739
 
4740
			#如果有找到,且沒有長度與形態資訊
4741
			if($searchResult["founded"]==="true" && !isset($result["columnVarTypeAndLengthLimit"][$i]) ){
4742
 
4743
				#代表是屬於鍵值的定義
4744
				$keyDefine[]=$everyLine["dataArray"][$i];
4745
 
4746
				#var_dump($keyDefine);
4747
 
4748
				#跳過該行內容
4749
				continue;
4750
 
4751
				}#if end
4752
 
4753
			#判斷該 $columnString["dataArray"][0]是否為 "CONSTRAINT" 或 "KEY"
4754
			if($columnString["dataArray"][0]==="CONSTRAINT" || $columnString["dataArray"][0]==="KEY"){
4755
 
4756
				#代表是屬於定義 外鍵 的 CONSTRAINT 定義
4757
				$keyDefine[]=$everyLine["dataArray"][$i];
4758
 
4759
				#跳過該行內容
4760
				continue;
4761
 
4762
				}#if end
4763
 
43 liveuser 4764
			#函式說明:
1 liveuser 4765
			#處理字串避免網頁出錯
43 liveuser 4766
			#回傳結果::
1 liveuser 4767
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
4768
			#$result["function"],當前執行的函數.
4769
			#$result["content"],爲處理好的字串.
4770
			#$result["error"],錯誤訊息陣列.
43 liveuser 4771
			#必填參數:
1 liveuser 4772
			$conf["stringProcess"]["correctCharacter"]["stringIn"]=$columnString["dataArray"][0];#爲要處理的字串
43 liveuser 4773
			#可省略參數:
1 liveuser 4774
			$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array("`");#爲被選擇要處理的字串/字元,須爲陣列值。
4775
			#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
4776
			#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
4777
			$correctCharacterResult=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
4778
			unset($conf["stringProcess"]);
4779
 
4780
			#如果處理字串失敗
4781
			if($correctCharacterResult["status"]==="false"){
4782
 
4783
				#設置執行失敗
4784
				$reuslt["status"]="false";
4785
 
4786
				#設置錯誤訊息
4787
				$result["error"]=$correctCharacterResult;
4788
 
4789
				#回傳結果
4790
				return $result;
4791
 
4792
				}#if end
4793
 
4794
			#如果不是 "CONSTRAINT" 且 存在 $result["columnVarTypeAndLengthLimit"][$i]
4795
			if($correctCharacterResult["content"]!=="CONSTRAINT" && isset($result["columnVarTypeAndLengthLimit"][$i])){
4796
 
4797
				#取得欄位名稱,遇到有空格的欄位名稱會出錯
4798
				#$result["columnName"][$i]=$correctCharacterResult["content"];
4799
				#$result["columnName"][$correctCharacterResult["content"]]=$correctCharacterResult["content"];
4800
 
4801
				#取得欄位變數形態與長度限制,遇到有空格的欄位名稱會出錯
4802
				#$result["columnVarTypeAndLengthLimit"][$i]=$columnString["dataArray"][1];
4803
				#$result["columnVarTypeAndLengthLimit"][$result["columnName"][$i]]=$columnString["dataArray"][1];
4804
 
4805
				#檢查是否有欄位的長度限制關鍵字 "(" ")"
43 liveuser 4806
				#函式說明:
1 liveuser 4807
				#檢查一個字串裡面是否有多個關鍵字
43 liveuser 4808
				#回傳結果::
1 liveuser 4809
				#$result["status"],"true"代表執行成功,"false"代表執行失敗。
4810
				#$result["error"],錯誤訊息
4811
				#$result["founded"],是否找到所有的關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 4812
				#必填參數:
1 liveuser 4813
				$conf["search"]["findManyKeyWords"]["keyWords"]=array("(",")");#想要搜尋的關鍵字
4814
				$conf["search"]["findManyKeyWords"]["string"]=$result["columnVarTypeAndLengthLimit"][$i];#要被搜尋的字串內容
43 liveuser 4815
				#可省略參數:
1 liveuser 4816
				#$conf["search"]["findManyKeyWords"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
4817
				$lengthLimitKeyWordSearchResult=search::findManyKeyWords($conf["search"]["findManyKeyWords"]);
4818
				unset($conf["search"]["findManyKeyWords"]);
4819
 
4820
				#如果  檢查是否有欄位的長度限制關鍵字 "(" ")" 失敗
4821
				if($lengthLimitKeyWordSearchResult["status"]==="false"){
4822
 
4823
					#設置執行失敗
4824
					$reuslt["status"]="false";
4825
 
4826
					#設置錯誤訊息
4827
					$result["error"]=$lengthLimitKeyWordSearchResult;
4828
 
4829
					#回傳結果
4830
					return $result;
4831
 
4832
					}#if end
4833
 
4834
				#如果 $lengthLimitKeyWordSearchResult["founded"] 等於 "true"
4835
				if($lengthLimitKeyWordSearchResult["foundedAll"]==="true"){
4836
 
4837
					#代表有長度限制的字串
4838
 
4839
					#以"("為關鍵字進行分割
43 liveuser 4840
					#函式說明:
1 liveuser 4841
					#將固定格式的字串分開,並回傳分開的結果。
4842
					#回傳的參數:
4843
					#$result["oriStr"],要分割的原始字串內容
4844
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4845
					#$result["dataCounts"],爲總共分成幾段
43 liveuser 4846
					#必填參數:
1 liveuser 4847
					$conf["stringProcess"]["spiltString"]["stringIn"]=$result["columnVarTypeAndLengthLimit"][$i];#要處理的字串。
4848
					$conf["stringProcess"]["spiltString"]["spiltSymbol"]="(";#爲以哪個符號作爲分割
4849
					$columnTypeAndLengthLimitSpiledStr=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
4850
					unset($conf["stringProcess"]["spiltString"]);
4851
 
4852
					#如果分割字串失敗
4853
					if($columnTypeAndLengthLimitSpiledStr["status"]==="false"){
4854
 
4855
						#設置執行失敗
4856
						$reuslt["status"]="false";
4857
 
4858
						#設置錯誤訊息
4859
						$result["error"]=$columnTypeAndLengthLimitSpiledStr;
4860
 
4861
						#回傳結果
4862
						return $result;
4863
 
4864
						}#if end
4865
 
4866
					#取得欄位變數型別
4867
					$result["columnVarType"][$i]=$columnTypeAndLengthLimitSpiledStr["dataArray"][0];
4868
					$result["columnVarType"][$result["columnName"][$i]]=$columnTypeAndLengthLimitSpiledStr["dataArray"][0];
4869
 
4870
					#以")"為關鍵字進行分割
43 liveuser 4871
					#函式說明:
1 liveuser 4872
					#將固定格式的字串分開,並回傳分開的結果。
4873
					#回傳的參數:
4874
					#$result["oriStr"],要分割的原始字串內容
4875
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
4876
					#$result["dataCounts"],爲總共分成幾段
43 liveuser 4877
					#必填參數:
1 liveuser 4878
					$conf["stringProcess"]["spiltString"]["stringIn"]=$columnTypeAndLengthLimitSpiledStr["dataArray"][1];#要處理的字串。
4879
					$conf["stringProcess"]["spiltString"]["spiltSymbol"]=")";#爲以哪個符號作爲分割
4880
					$columnTypeAndLengthLimitSpiledStr=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
4881
					unset($conf["stringProcess"]["spiltString"]);
4882
 
4883
					#如果分割字串失敗
4884
					if($columnTypeAndLengthLimitSpiledStr["status"]==="false"){
4885
 
4886
						#設置執行失敗
4887
						$reuslt["status"]="false";
4888
 
4889
						#設置錯誤訊息
4890
						$result["error"]=$columnTypeAndLengthLimitSpiledStr;
4891
 
4892
						#回傳結果
4893
						return $result;
4894
 
4895
						}#if end
4896
 
4897
					#取得欄位的長度限制
4898
					$result["columnVarLengthLimit"][$i]=$columnTypeAndLengthLimitSpiledStr["dataArray"][0];
4899
					$result["columnVarLengthLimit"][$result["columnName"][$i]]=$columnTypeAndLengthLimitSpiledStr["dataArray"][0];
4900
 
4901
					}#if end
4902
 
4903
				#反之代表沒有長度限制的字串
4904
				else{
4905
 
4906
					#取得欄位變數型別
4907
					$result["columnVarType"][$i]=$result["columnVarTypeAndLengthLimit"][$i];
4908
					$result["columnVarType"][$result["columnName"][$i]]=$result["columnVarTypeAndLengthLimit"][$i];
4909
 
4910
					#取得欄位變數長度限制
4911
					$result["columnVarLengthLimit"][$i]="";
4912
					$result["columnVarLengthLimit"][$result["columnName"][$i]]="";
4913
 
4914
					}#else
4915
 
4916
				#欄位是否不可為null
43 liveuser 4917
				#函式說明:
1 liveuser 4918
				#檢查字串裡面有無指定的關鍵字
43 liveuser 4919
				#回傳結果::
1 liveuser 4920
				#$result["status"],"true"代表執行成功,"false"代表執行失敗。
4921
				#$result["error"],錯誤訊息
4922
				#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 4923
				#必填參數:
1 liveuser 4924
				$conf["search"]["findKeyWord"]["keyWord"]="NOT NULL";#想要搜尋的關鍵字
4925
				$conf["search"]["findKeyWord"]["string"]=$everyLine["dataArray"][$i];#要被搜尋的字串內容
43 liveuser 4926
				#可省略參數:
1 liveuser 4927
				#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
4928
				$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
4929
				unset($conf["search"]["findKeyWord"]);
4930
 
4931
				#如果取得 欄位是否不可為null 失敗
4932
				if($searchResult["status"]==="false"){
4933
 
4934
					#設置執行失敗
4935
					$reuslt["status"]="false";
4936
 
4937
					#設置錯誤訊息
4938
					$result["error"]=$searchResult;
4939
 
4940
					#回傳結果
4941
					return $result;
4942
 
4943
					}#if end
4944
 
4945
				#如果有找到 NOT NULL
4946
				if($searchResult["founded"]==="true"){
4947
 
4948
					$result["columnNotNull"][$i]="true";
4949
					$result["columnNotNull"][$result["columnName"][$i]]="true";
4950
 
4951
					}#if end
4952
 
4953
				#反之沒有找到 NOT NULL
4954
				else{
4955
 
4956
					$result["columnNotNull"][$i]="false";
4957
					$result["columnNotNull"][$result["columnName"][$i]]="false";
4958
 
4959
					}#else end
4960
 
4961
				#欄位是否會自動加1
43 liveuser 4962
				#函式說明:
1 liveuser 4963
				#檢查字串裡面有無指定的關鍵字
43 liveuser 4964
				#回傳結果::
1 liveuser 4965
				#$result["status"],"true"代表執行成功,"false"代表執行失敗。
4966
				#$result["error"],錯誤訊息
4967
				#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 4968
				#必填參數:
1 liveuser 4969
				$conf["search"]["findKeyWord"]["keyWord"]="AUTO_INCREMENT";#想要搜尋的關鍵字
4970
				$conf["search"]["findKeyWord"]["string"]=$everyLine["dataArray"][$i];#要被搜尋的字串內容
43 liveuser 4971
				#可省略參數:
1 liveuser 4972
				#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
4973
				$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
4974
				unset($conf["search"]["findKeyWord"]);
4975
 
4976
				#如果取得 欄位是否會自動加1 失敗
4977
				if($searchResult["status"]==="false"){
4978
 
4979
					#設置執行失敗
4980
					$reuslt["status"]="false";
4981
 
4982
					#設置錯誤訊息
4983
					$result["error"]=$searchResult;
4984
 
4985
					#回傳結果
4986
					return $result;
4987
 
4988
					}#if end
4989
 
4990
				#如果有找到 AUTO_INCREMENT
4991
				if($searchResult["founded"]==="true"){
4992
 
4993
					$result["columnAutoIncrement"][$i]="true";
4994
					$result["columnAutoIncrement"][$result["columnName"][$i]]="true";
4995
 
4996
					}#if end
4997
 
4998
				#反之沒有 AUTO_INCREMENT
4999
				else{
5000
 
5001
					$result["columnAutoIncrement"][$i]="false";
5002
					$result["columnAutoIncrement"][$result["columnName"][$i]]="false";
5003
 
5004
					}#else end
5005
 
5006
				#欄位是否有預設內容
5007
 
43 liveuser 5008
				#函式說明:
1 liveuser 5009
				#檢查字串裡面有無指定的關鍵字
43 liveuser 5010
				#回傳結果::
1 liveuser 5011
				#$result["status"],"true"代表執行成功,"false"代表執行失敗。
5012
				#$result["error"],錯誤訊息
5013
				#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 5014
				#必填參數:
1 liveuser 5015
				$conf["search"]["findKeyWord"]["keyWord"]="DEFAULT";#想要搜尋的關鍵字
5016
				$conf["search"]["findKeyWord"]["string"]=$everyLine["dataArray"][$i];#要被搜尋的字串內容
43 liveuser 5017
				#可省略參數:
1 liveuser 5018
				#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
5019
				$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
5020
				unset($conf["search"]["findKeyWord"]);
5021
 
5022
				#如果取得 欄位是否有預設內容 失敗
5023
				if($searchResult["status"]==="false"){
5024
 
5025
					#設置執行失敗
5026
					$reuslt["status"]="false";
5027
 
5028
					#設置錯誤訊息
5029
					$result["error"]=$searchResult;
5030
 
5031
					#回傳結果
5032
					return $result;
5033
 
5034
					}#if end
5035
 
5036
				#如果有找到 DEFAULT
5037
				if($searchResult["founded"]==="true"){
5038
 
43 liveuser 5039
					#函式說明:
1 liveuser 5040
					#將固定格式的字串分開,並回傳分開的結果。
5041
					#回傳的參數:
5042
					#$result["oriStr"],要分割的原始字串內容
5043
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5044
					#$result["dataCounts"],爲總共分成幾段
43 liveuser 5045
					#必填參數:
1 liveuser 5046
					$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][$i];#要處理的字串。
5047
					$conf["stringProcess"]["spiltString"]["spiltSymbol"]="DEFAULT ";#爲以哪個符號作爲分割
5048
					$defaultString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5049
					unset($conf["stringProcess"]["spiltString"]);
5050
 
5051
					#如果分割字串失敗
5052
					if($defaultString["status"]=="false"){
5053
 
5054
						#設置執行失敗
5055
						$result["status"]="false";
5056
 
5057
						#設置執行錯誤訊息
5058
						$result["error"]=$defaultString;
5059
 
5060
						#回傳結果
5061
						return $result;
5062
 
5063
						}#if end
5064
 
43 liveuser 5065
					#函式說明:
1 liveuser 5066
					#將固定格式的字串分開,並回傳分開的結果。
5067
					#回傳的參數:
5068
					#$result["oriStr"],要分割的原始字串內容
5069
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5070
					#$result["dataCounts"],爲總共分成幾段
43 liveuser 5071
					#必填參數:
1 liveuser 5072
					$conf["stringProcess"]["spiltString"]["stringIn"]=$defaultString["dataArray"][1];#要處理的字串。
5073
					$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
5074
					$defaultString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5075
					unset($conf["stringProcess"]["spiltString"]);
5076
 
5077
					#如果分割字串失敗
5078
					if($defaultString["status"]=="false"){
5079
 
5080
						#設置執行失敗
5081
						$result["status"]="false";
5082
 
5083
						#設置執行錯誤訊息
5084
						$result["error"]=$defaultString;
5085
 
5086
						#回傳結果
5087
						return $result;
5088
 
5089
						}#if end
5090
 
5091
					#將「,」,「'」去掉 
43 liveuser 5092
					#函式說明:
1 liveuser 5093
					#處理字串避免網頁出錯
43 liveuser 5094
					#回傳結果::
1 liveuser 5095
					#$result,爲處理好的字串。
43 liveuser 5096
					#必填參數:
1 liveuser 5097
					$conf["stringProcess"]["correctCharacter"]["stringIn"]=$defaultString["dataArray"][0];#爲要處理的字串
43 liveuser 5098
					#可省略參數:
1 liveuser 5099
					$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",","'");#爲被選擇要處理的字串/字元,須爲陣列值。
5100
					#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
5101
					#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
5102
					$thisColumnDefaultValue=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
5103
					unset($conf["stringProcess"]["correctCharacter"]);
5104
 
5105
					#如果處理字串失敗
5106
					if($thisColumnDefaultValue["status"]=="false"){
5107
 
5108
						#設置執行不正常
5109
						$result["status"]="false";
5110
 
5111
						#設置錯誤訊息
5112
						$result["error"]=$thisColumnDefaultValue;
5113
 
5114
						#回傳結果
5115
						return $result;
5116
 
5117
						}#if end
5118
 
5119
					#取得該欄位的預設內容
5120
					$result["columnDefault"][$i]=$thisColumnDefaultValue["content"];
5121
					$result["columnDefault"][$result["columnName"][$i]]=$thisColumnDefaultValue["content"];
5122
 
5123
					}#if end
5124
 
5125
				#反之沒有找到 DEFAULT	
5126
				else{
5127
 
5128
					$result["columnDefault"][$i]="沒有指定";
5129
					$result["columnDefault"][$result["columnName"][$i]]=$result["columnDefault"][$i];
5130
 
5131
					}#else end
5132
 
5133
				#如果有欄位內有 ON UPDATE 的字樣
5134
 
43 liveuser 5135
				#函式說明:
1 liveuser 5136
				#檢查字串裡面有無指定的關鍵字
43 liveuser 5137
				#回傳結果::
1 liveuser 5138
				#$result["status"],"true"代表執行成功,"false"代表執行失敗。
5139
				#$result["error"],錯誤訊息
5140
				#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 5141
				#必填參數:
1 liveuser 5142
				$conf["search"]["findKeyWord"]["keyWord"]="ON UPDATE";#想要搜尋的關鍵字
5143
				$conf["search"]["findKeyWord"]["string"]=$everyLine["dataArray"][$i];#要被搜尋的字串內容
43 liveuser 5144
				#可省略參數:
1 liveuser 5145
				#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
5146
				$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
5147
				unset($conf["search"]["findKeyWord"]);
5148
 
5149
				#如果尋找 欄位內是否有 ON UPDATE 的字樣失敗
5150
				if($searchResult["status"]==="false"){
5151
 
5152
					#設置執行失敗
5153
					$result["status"]="false";
5154
 
5155
					#設置執行錯誤訊息
5156
					$result["error"]=$searchResult;
5157
 
5158
					#回傳結果
5159
					return $result;
5160
 
5161
					}#if end
5162
 
5163
				#如果有找到 ON UPDATE
5164
				if($searchResult["founded"]==="true"){ 
5165
 
43 liveuser 5166
					#函式說明:
1 liveuser 5167
					#將固定格式的字串分開,並回傳分開的結果。
5168
					#回傳的參數:
5169
					#$result["oriStr"],要分割的原始字串內容
5170
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5171
					#$result["dataCounts"],爲總共分成幾段
43 liveuser 5172
					#必填參數:
1 liveuser 5173
					$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][$i];#要處理的字串。
5174
					$conf["stringProcess"]["spiltString"]["spiltSymbol"]="ON UPDATE ";#爲以哪個符號作爲分割
5175
					$onUpdateString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5176
					unset($conf["stringProcess"]["spiltString"]);
5177
 
43 liveuser 5178
					#函式說明:
1 liveuser 5179
					#將固定格式的字串分開,並回傳分開的結果。
5180
					#回傳的參數:
5181
					#$result["oriStr"],要分割的原始字串內容
5182
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5183
					#$result["dataCounts"],爲總共分成幾段
43 liveuser 5184
					#必填參數:
1 liveuser 5185
					$conf["stringProcess"]["spiltString"]["stringIn"]=$onUpdateString["dataArray"][1];#要處理的字串。
5186
					$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
5187
					$onUpdateString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5188
					unset($conf["stringProcess"]["spiltString"]);
5189
 
5190
					#如果分割字串失敗
5191
					if($onUpdateString["status"]=="false"){
5192
 
5193
						#設置執行不正常
5194
						$result["status"]="false";
5195
 
5196
						#設置錯誤訊息
5197
						$result["error"]=$onUpdateString;
5198
 
5199
						#回傳結果
5200
						return $result;
5201
 
5202
						}#if end
5203
 
5204
					#將「,」去掉 
43 liveuser 5205
					#函式說明:
1 liveuser 5206
					#處理字串避免網頁出錯
43 liveuser 5207
					#回傳結果::
1 liveuser 5208
					#$result,爲處理好的字串。
43 liveuser 5209
					#必填參數:
1 liveuser 5210
					$conf["stringProcess"]["correctCharacter"]["stringIn"]=$onUpdateString["dataArray"][0];#爲要處理的字串
43 liveuser 5211
					#可省略參數:
1 liveuser 5212
					$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",");#爲被選擇要處理的字串/字元,須爲陣列值。
5213
					#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
5214
					#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
5215
					$columnOnUpdateActionStr=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
5216
					unset($conf["stringProcess"]["correctCharacter"]);
5217
 
5218
					#如果 處理字串失敗
5219
					if($columnOnUpdateActionStr["status"]=="false"){
5220
 
5221
						#設置執行不正常
5222
						$result["status"]="false";
5223
 
5224
						#設置錯誤訊息
5225
						$result["error"]=$columnOnUpdateActionStr;
5226
 
5227
						#回傳結果
5228
						return $result;
5229
 
5230
						}#if end
5231
 
5232
					#取得 ON UPDATE 的對應動作
5233
					$result["columnOnUpdateAction"][$result["columnName"][$i]]=$columnOnUpdateActionStr["content"];
5234
					$result["columnOnUpdateAction"][$i]=$columnOnUpdateActionStr["content"];
5235
 
5236
					}#if end
5237
 
5238
				#反之,沒有 ON UPDATE 的對應動作
5239
				else{
5240
 
5241
					$result["columnOnUpdateAction"][$i]="沒有指定";
5242
					$result["columnOnUpdateAction"][$result["columnName"][$i]]=$result["columnOnUpdateAction"][$i];
5243
 
5244
					}#else end
5245
 
5246
				}#if end
5247
 
5248
			#如果有欄位內有 CHARACTER SET 的字樣
5249
 
43 liveuser 5250
			#函式說明:
1 liveuser 5251
			#檢查字串裡面有無指定的關鍵字
43 liveuser 5252
			#回傳結果::
1 liveuser 5253
			#$result["status"],"true"代表執行成功,"false"代表執行失敗。
5254
			#$result["error"],錯誤訊息
5255
			#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 5256
			#必填參數:
1 liveuser 5257
			$conf["search"]["findKeyWord"]["keyWord"]="CHARACTER SET";#想要搜尋的關鍵字
5258
			$conf["search"]["findKeyWord"]["string"]=$everyLine["dataArray"][$i];#要被搜尋的字串內容
43 liveuser 5259
			#可省略參數:
1 liveuser 5260
			#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
5261
			$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
5262
			unset($conf["search"]["findKeyWord"]);
5263
 
5264
			#如果尋找關鍵字失敗
5265
			if($searchResult["status"]==="false"){
5266
 
5267
				#設置執行不正常
5268
				$result["status"]="false";
5269
 
5270
				#設置錯誤訊息
5271
				$result["error"]=$searchResult;
5272
 
5273
				#回傳結果
5274
				return $result;
5275
 
5276
				}#if end
5277
 
5278
			#如果有找到 CHARACTER SET
5279
			if($searchResult["founded"]==="true"){ 
5280
 
43 liveuser 5281
				#函式說明:
1 liveuser 5282
				#將固定格式的字串分開,並回傳分開的結果。
5283
				#回傳的參數:
5284
				#$result["oriStr"],要分割的原始字串內容
5285
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5286
				#$result["dataCounts"],爲總共分成幾段
43 liveuser 5287
				#必填參數:
1 liveuser 5288
				$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][$i];#要處理的字串。
5289
				$conf["stringProcess"]["spiltString"]["spiltSymbol"]="CHARACTER SET ";#爲以哪個符號作爲分割
5290
				$characterSetString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5291
				unset($conf["stringProcess"]["spiltString"]);
5292
 
5293
				#如果分割字串失敗
5294
				if($characterSetString["status"]==="false"){
5295
 
5296
					#設置執行不正常
5297
					$result["status"]="false";
5298
 
5299
					#設置錯誤訊息
5300
					$result["error"]=$characterSetString;
5301
 
5302
					#回傳結果
5303
					return $result;
5304
 
5305
					}#if end
5306
 
43 liveuser 5307
				#函式說明:
1 liveuser 5308
				#將固定格式的字串分開,並回傳分開的結果。
5309
				#回傳的參數:
5310
				#$result["oriStr"],要分割的原始字串內容
5311
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5312
				#$result["dataCounts"],爲總共分成幾段
43 liveuser 5313
				#必填參數:
1 liveuser 5314
				$conf["stringProcess"]["spiltString"]["stringIn"]=$characterSetString["dataArray"][1];#要處理的字串。
5315
				$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
5316
				$characterSetString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5317
				unset($conf["stringProcess"]["spiltString"]);
5318
 
5319
				#如果分割字串失敗
5320
				if($characterSetString["status"]==="false"){
5321
 
5322
					#設置執行不正常
5323
					$result["status"]="false";
5324
 
5325
					#設置錯誤訊息
5326
					$result["error"]=$characterSetString;
5327
 
5328
					#回傳結果
5329
					return $result;
5330
 
5331
					}#if end
5332
 
5333
				#將「,」去掉 
43 liveuser 5334
				#函式說明:
1 liveuser 5335
				#處理字串避免網頁出錯
43 liveuser 5336
				#回傳結果::
1 liveuser 5337
				#$result,爲處理好的字串。
43 liveuser 5338
				#必填參數:
1 liveuser 5339
				$conf["stringProcess"]["correctCharacter"]["stringIn"]=$characterSetString["dataArray"][0];#爲要處理的字串
43 liveuser 5340
				#可省略參數:
1 liveuser 5341
				$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",");#爲被選擇要處理的字串/字元,須爲陣列值。
5342
				#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
5343
				#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
5344
				$processedCharacterSetStr=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
5345
				unset($conf["stringProcess"]["correctCharacter"]);
5346
 
5347
				#如果處理字串失敗
5348
				if($processedCharacterSetStr["status"]==="false"){
5349
 
5350
					#設置執行不正常
5351
					$result["status"]="false";
5352
 
5353
					#設置錯誤訊息
5354
					$result["error"]=$processedCharacterSetStr;
5355
 
5356
					#回傳結果
5357
					return $result;
5358
 
5359
					}#if end
5360
 
5361
				#取得CHARACTER SET的設定字串
5362
				$result["columnCharacterSet"][$i]=$processedCharacterSetStr["content"];
5363
				$result["columnCharacterSet"][$result["columnName"][$i]]=$processedCharacterSetStr["content"];
5364
 
5365
				}#if end
5366
 
5367
			#反之,沒有 CHARACTER SET 字樣
5368
			else{
5369
 
5370
				#如果存在該欄位
5371
				if(isset($result["columnName"][$i])){
5372
 
5373
					#採用預設的 $result["charset"]
5374
					$result["columnCharacterSet"][$i]=$result["charset"];
5375
					$result["columnCharacterSet"][$result["columnName"][$i]]=$result["columnCharacterSet"][$i];
5376
 
5377
					}#if end
5378
 
5379
				}#else end
5380
 
5381
			#檢查是否有 COLLATE 字樣...
5382
 
43 liveuser 5383
			#函式說明:
1 liveuser 5384
			#檢查字串裡面有無指定的關鍵字
43 liveuser 5385
			#回傳結果::
1 liveuser 5386
			#$result["status"],"true"代表執行成功,"false"代表執行失敗。
5387
			#$result["error"],錯誤訊息
5388
			#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 5389
			#必填參數:
1 liveuser 5390
			$conf["search"]["findKeyWord"]["keyWord"]="COLLATE";#想要搜尋的關鍵字
5391
			$conf["search"]["findKeyWord"]["string"]=$everyLine["dataArray"][$i];#要被搜尋的字串內容
43 liveuser 5392
			#可省略參數:
1 liveuser 5393
			#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
5394
			$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
5395
			unset($conf["search"]["findKeyWord"]);
5396
 
5397
			#如果尋找關鍵字失敗
5398
			if($searchResult["status"]==="false"){
5399
 
5400
				#設置執行不正常
5401
				$result["status"]="false";
5402
 
5403
				#設置錯誤訊息
5404
				$result["error"]=$searchResult;
5405
 
5406
				#回傳結果
5407
				return $result;
5408
 
5409
				}#if end
5410
 
5411
			#如果有找到 CHARACTER SET
5412
			if($searchResult["founded"]==="true"){ 
5413
 
43 liveuser 5414
				#函式說明:
1 liveuser 5415
				#將固定格式的字串分開,並回傳分開的結果。
5416
				#回傳的參數:
5417
				#$result["oriStr"],要分割的原始字串內容
5418
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5419
				#$result["dataCounts"],爲總共分成幾段
43 liveuser 5420
				#必填參數:
1 liveuser 5421
				$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][$i];#要處理的字串。
5422
				$conf["stringProcess"]["spiltString"]["spiltSymbol"]="COLLATE ";#爲以哪個符號作爲分割
5423
				$collateString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5424
				unset($conf["stringProcess"]["spiltString"]);
5425
 
5426
				#如果分割字串失敗
5427
				if($collateString["status"]=="false"){
5428
 
5429
					#設置執行不正常
5430
					$result["status"]="false";
5431
 
5432
					#設置錯誤訊息
5433
					$result["error"]=$searchResult;
5434
 
5435
					#回傳結果
5436
					return $result;
5437
 
5438
					}#if end
5439
 
43 liveuser 5440
				#函式說明:
1 liveuser 5441
				#將固定格式的字串分開,並回傳分開的結果。
5442
				#回傳的參數:
5443
				#$result["oriStr"],要分割的原始字串內容
5444
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5445
				#$result["dataCounts"],爲總共分成幾段
43 liveuser 5446
				#必填參數:
1 liveuser 5447
				$conf["stringProcess"]["spiltString"]["stringIn"]=$collateString["dataArray"][1];#要處理的字串。
5448
				$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
5449
				$collateString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5450
				unset($conf["stringProcess"]["spiltString"]);
5451
 
5452
				#如果分割字串失敗
5453
				if($collateString["status"]==="false"){
5454
 
5455
					#設置執行不正常
5456
					$result["status"]="false";
5457
 
5458
					#設置錯誤訊息
5459
					$result["error"]=$searchResult;
5460
 
5461
					#回傳結果
5462
					return $result;
5463
 
5464
					}#if end
5465
 
5466
				#將「,」去掉 
43 liveuser 5467
				#函式說明:
1 liveuser 5468
				#處理字串避免網頁出錯
43 liveuser 5469
				#回傳結果::
1 liveuser 5470
				#$result,爲處理好的字串。
43 liveuser 5471
				#必填參數:
1 liveuser 5472
				$conf["stringProcess"]["correctCharacter"]["stringIn"]=$collateString["dataArray"][0];#爲要處理的字串
43 liveuser 5473
				#可省略參數:
1 liveuser 5474
				$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",");#爲被選擇要處理的字串/字元,須爲陣列值。
5475
				#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
5476
				#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
5477
				$thisColumnCollate=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
5478
				unset($conf["stringProcess"]["correctCharacter"]);
5479
 
5480
				#如果處理字串失敗
5481
				if($thisColumnCollate["status"]==="false"){
5482
 
5483
					#設置執行不正常
5484
					$result["status"]="false";
5485
 
5486
					#設置錯誤訊息
5487
					$result["error"]=$thisColumnCollate;
5488
 
5489
					#回傳結果
5490
					return $result;
5491
 
5492
					}#if end
5493
 
5494
				#儲存 COLLATE 資訊字串
5495
				$result["columnCollate"][$i]=$thisColumnCollate["content"];
5496
				$result["columnCollate"][$result["columnName"][$i]]=$thisColumnCollate["content"];
5497
 
5498
				}#if end
5499
 
5500
			#反之,沒有 COLLATE  字樣
5501
			else{
5502
				#如果存在該欄位
5503
				if(isset($result["columnName"][$i])){
5504
 
5505
					$result["columnCollate"][$i]="沒有指定";
5506
					$result["columnCollate"][$result["columnName"][$i]]=$result["columnCollate"][$i];
5507
 
5508
					}#if end
5509
 
5510
				}#else end
5511
 
5512
			#檢查是否有COMMENT字樣
43 liveuser 5513
			#函式說明:
1 liveuser 5514
			#檢查字串裡面有無指定的關鍵字
43 liveuser 5515
			#回傳結果::
1 liveuser 5516
			#$result["status"],"true"代表執行成功,"false"代表執行失敗。
5517
			#$result["error"],錯誤訊息
5518
			#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 5519
			#必填參數:
1 liveuser 5520
			$conf["search"]["findKeyWord"]["keyWord"]="COMMENT";#想要搜尋的關鍵字
5521
			$conf["search"]["findKeyWord"]["string"]=$everyLine["dataArray"][$i];#要被搜尋的字串內容
43 liveuser 5522
			#可省略參數:
1 liveuser 5523
			#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
5524
			$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
5525
			unset($conf["search"]);
5526
 
5527
			#如果尋找關鍵字失敗
5528
			if($searchResult["status"]==="false"){
5529
 
5530
				#設置執行不正常
5531
				$result["status"]="false";
5532
 
5533
				#設置錯誤訊息
5534
				$result["error"]=$searchResult;
5535
 
5536
				#回傳結果
5537
				return $result;
5538
 
5539
				}#if end
5540
 
5541
			#如果有 COMMENT 字樣
5542
			if($searchResult["founded"]==="true"){
5543
 
43 liveuser 5544
				#函式說明:
1 liveuser 5545
				#將固定格式的字串分開,並回傳分開的結果。
5546
				#回傳的參數:
5547
				#$result["oriStr"],要分割的原始字串內容
5548
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5549
				#$result["dataCounts"],爲總共分成幾段
43 liveuser 5550
				#必填參數:
1 liveuser 5551
				$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][$i];#要處理的字串。
5552
				$conf["stringProcess"]["spiltString"]["spiltSymbol"]="COMMENT ";#爲以哪個符號作爲分割
5553
				$commentString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5554
				unset($conf["stringProcess"]["spiltString"]);
5555
 
5556
				#如果分割字串失敗
5557
				if($commentString["status"]=="false"){
5558
 
5559
					#設置執行不正常
5560
					$result["status"]="false";
5561
 
5562
					#設置錯誤訊息
5563
					$result["error"]=$commentString;
5564
 
5565
					#回傳結果
5566
					return $result;
5567
 
5568
					}#if end
5569
 
43 liveuser 5570
				#函式說明:
1 liveuser 5571
				#將固定格式的字串分開,並回傳分開的結果。
5572
				#回傳的參數:
5573
				#$result["oriStr"],要分割的原始字串內容
5574
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5575
				#$result["dataCounts"],爲總共分成幾段
43 liveuser 5576
				#必填參數:
1 liveuser 5577
				$conf["stringProcess"]["spiltString"]["stringIn"]=$commentString["dataArray"][1];#要處理的字串。
5578
				$conf["stringProcess"]["spiltString"]["spiltSymbol"]="'";#爲以哪個符號作爲分割
5579
				$commentString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5580
				unset($conf["stringProcess"]["spiltString"]);
5581
 
5582
				#如果分割字串失敗
5583
				if($commentString["status"]==="false"){
5584
 
5585
					#設置執行不正常
5586
					$result["status"]="false";
5587
 
5588
					#設置錯誤訊息
5589
					$result["error"]=$commentString;
5590
 
5591
					#回傳結果
5592
					return $result;
5593
 
5594
					}#if end
5595
 
5596
				#取得該欄位的註解內容
5597
				$result["columnComment"][$i]=$commentString["dataArray"][0];
5598
				$result["columnComment"][$result["columnName"][$i]]=$commentString["dataArray"][0];
5599
 
5600
				}#if end
5601
 
5602
			#反之,沒有 COMMENT 字樣
5603
			else{
5604
				#如果存在該欄位
5605
				if(isset($result["columnName"][$i])){
5606
 
5607
					#設置該欄位沒有註解
5608
					$result["columnComment"][$i]="沒有註解";
5609
					$result["columnComment"][$result["columnName"][$i]]="沒有註解";
5610
 
5611
					}#if end
5612
 
5613
				}#else end
5614
 
5615
			}#for end
5616
 
5617
		#初始化索引鍵的陣列
5618
		$result["key"]=array();
5619
 
5620
		#依據有幾個鍵值的定義來執行
5621
		foreach($keyDefine as $unClassifyString){
5622
 
5623
			#依據第一個單字來進行判斷
5624
			#可能的有:
5625
			#PRIMARY KEY,主鍵
5626
			#KEY,索引鍵
5627
			#CONSTRAINT,外鍵
5628
 
5629
			#如果找到 PRIMARY KEY
43 liveuser 5630
			#函式說明:
1 liveuser 5631
			#檢查字串裡面有無指定的關鍵字
43 liveuser 5632
			#回傳結果::
1 liveuser 5633
			#$result["status"],"true"代表執行成功,"false"代表執行失敗。
5634
			#$result["error"],錯誤訊息
5635
			#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 5636
			#必填參數:
1 liveuser 5637
			$conf["search"]["findKeyWord"]["keyWord"]="PRIMARY KEY";#想要搜尋的關鍵字
5638
			$conf["search"]["findKeyWord"]["string"]=$unClassifyString;#要被搜尋的字串內容
43 liveuser 5639
			#可省略參數:
1 liveuser 5640
			#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
5641
			$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
5642
			unset($conf["search"]["findKeyWord"]);
5643
 
5644
			#如果尋找關鍵字失敗
5645
			if($searchResult["status"]=="false"){
5646
 
5647
				#設置執行不正常
5648
				$result["status"]="false";
5649
 
5650
				#設置錯誤訊息
5651
				$result["error"]=$searchResult;
5652
 
5653
				#回傳結果
5654
				return $result;
5655
 
5656
				}#if end
5657
 
5658
			#如果有找到 PRIMARY KEY
5659
			if($searchResult["founded"]=="true"){ 
5660
 
43 liveuser 5661
				#函式說明:
1 liveuser 5662
				#將固定格式的字串分開,並回傳分開的結果。
5663
				#回傳的參數:
5664
				#$result["oriStr"],要分割的原始字串內容
5665
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5666
				#$result["dataCounts"],爲總共分成幾段
43 liveuser 5667
				#必填參數:
1 liveuser 5668
				$conf["stringProcess"]["spiltString"]["stringIn"]=$unClassifyString;#要處理的字串。
5669
				$conf["stringProcess"]["spiltString"]["spiltSymbol"]="PRIMARY KEY ";#爲以哪個符號作爲分割
5670
				$primaryKeyString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5671
				unset($conf["stringProcess"]["spiltString"]);
5672
 
5673
				#如果分割字串失敗
5674
				if($primaryKeyString["status"]=="false"){
5675
 
5676
					#設置執行不正常
5677
					$result["status"]="false";
5678
 
5679
					#設置錯誤訊息
5680
					$result["error"]=$primaryKeyString;
5681
 
5682
					#回傳結果
5683
					return $result;
5684
 
5685
					}#if end
5686
 
5687
				#取得主鍵的欄位名稱
5688
				$primaryKey=$primaryKeyString["dataArray"][1];
5689
 
5690
				#將「,」、「`」、「(」、「)」去掉 
43 liveuser 5691
				#函式說明:
1 liveuser 5692
				#處理字串避免網頁出錯
43 liveuser 5693
				#回傳結果::
1 liveuser 5694
				#$result,爲處理好的字串。
43 liveuser 5695
				#必填參數:
1 liveuser 5696
				$conf["stringProcess"]["correctCharacter"]["stringIn"]=$primaryKey;#爲要處理的字串
43 liveuser 5697
				#可省略參數:
1 liveuser 5698
				$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",","`","(",")");#爲被選擇要處理的字串/字元,須爲陣列值。
5699
				#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
5700
				#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
5701
				$getPrimaryKey=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
5702
				unset($conf["stringProcess"]["correctCharacter"]);
5703
 
5704
				#如果 處理字串失敗
5705
				if($getPrimaryKey["status"]=="false"){
5706
 
5707
					#設置執行不正常
5708
					$result["status"]="false";
5709
 
5710
					#設置錯誤訊息
5711
					$result["error"]=$getPrimaryKey;
5712
 
5713
					#回傳結果
5714
					return $result;
5715
 
5716
					}#if end
5717
 
5718
				#取得主鍵欄位名稱
5719
				$result["primaryKey"]=$getPrimaryKey["content"];
5720
 
5721
				#後續省略
5722
				continue;
5723
 
5724
				}#if end
5725
 
5726
			#尋找是否有 KEY 關鍵字
43 liveuser 5727
			#函式說明:
1 liveuser 5728
			#檢查字串裡面有無指定的關鍵字
43 liveuser 5729
			#回傳結果::
1 liveuser 5730
			#$result["status"],"true"代表執行成功,"false"代表執行失敗。
5731
			#$result["error"],錯誤訊息
5732
			#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 5733
			#必填參數:
1 liveuser 5734
			$conf["search"]["findKeyWord"]["keyWord"]="  KEY ";#想要搜尋的關鍵字
5735
			$conf["search"]["findKeyWord"]["string"]=$unClassifyString;#要被搜尋的字串內容
43 liveuser 5736
			#可省略參數:
1 liveuser 5737
			#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
5738
			$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
5739
			unset($conf["search"]["findKeyWord"]);
5740
 
5741
			#如果尋找關鍵字失敗
5742
			if($searchResult["status"]=="false"){
5743
 
5744
				#設置執行不正常
5745
				$result["status"]="false";
5746
 
5747
				#設置錯誤訊息
5748
				$result["error"]=$searchResult;
5749
 
5750
				#回傳結果
5751
				return $result;
5752
 
5753
				}#if end
5754
 
5755
			#如果有找到 "  KEY "
5756
			if($searchResult["founded"]=="true"){
5757
 
5758
				# 用 "  KEY " 來分割
43 liveuser 5759
				#函式說明:
1 liveuser 5760
				#將固定格式的字串分開,並回傳分開的結果。
5761
				#回傳的參數:
5762
				#$result["oriStr"],要分割的原始字串內容
5763
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5764
				#$result["dataCounts"],爲總共分成幾段
43 liveuser 5765
				#必填參數:
1 liveuser 5766
				$conf["stringProcess"]["spiltString"]["stringIn"]=$unClassifyString;#要處理的字串。
5767
				$conf["stringProcess"]["spiltString"]["spiltSymbol"]="  KEY ";#爲以哪個符號作爲分割
5768
				$keyString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5769
				unset($conf["stringProcess"]["spiltString"]);
5770
 
5771
				#如果分割字串失敗
5772
				if($keyString["status"]=="false"){
5773
 
5774
					#設置執行不正常
5775
					$result["status"]="false";
5776
 
5777
					#設置錯誤訊息
5778
					$result["error"]=$keyString;
5779
 
5780
					#回傳結果
5781
					return $result;
5782
 
5783
					}#if end
5784
 
43 liveuser 5785
				#函式說明:
1 liveuser 5786
				#將固定格式的字串分開,並回傳分開的結果。
5787
				#回傳的參數:
5788
				#$result["oriStr"],要分割的原始字串內容
5789
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5790
				#$result["dataCounts"],爲總共分成幾段
43 liveuser 5791
				#必填參數:
1 liveuser 5792
				$conf["stringProcess"]["spiltString"]["stringIn"]=$keyString["dataArray"][0];#要處理的字串。
5793
				$conf["stringProcess"]["spiltString"]["spiltSymbol"]="`";#爲以哪個符號作爲分割
5794
				$keyString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5795
				unset($conf["stringProcess"]["spiltString"]);
5796
 
5797
				#debug
5798
				#var_dump($keyString);
5799
 
5800
				#如果分割字串失敗
5801
				if($keyString["status"]=="false"){
5802
 
5803
					#設置執行不正常
5804
					$result["status"]="false";
5805
 
5806
					#設置錯誤訊息
5807
					$result["error"]=$keyString;
5808
 
5809
					#回傳結果
5810
					return $result;
5811
 
5812
					}#if end
5813
 
5814
				#取得索引的欄位名稱
5815
				$thisKeyColumnName=$keyString["dataArray"][2];
5816
 
5817
				#取得要回傳的key欄位名稱
5818
				$result["key"][]=$thisKeyColumnName;
5819
 
5820
				#用index key欄位的名稱來儲存index key的欄位
5821
				$result["key"][$thisKeyColumnName]=$thisKeyColumnName;
5822
 
5823
				#取得用於識別 key 的 Constraint
5824
				$keyConstraintName=$keyString["dataArray"][0];
5825
 
5826
				#將「`」去掉 
43 liveuser 5827
				#函式說明:
1 liveuser 5828
				#處理字串避免網頁出錯
43 liveuser 5829
				#回傳結果::
1 liveuser 5830
				#$result,爲處理好的字串。
43 liveuser 5831
				#必填參數:
1 liveuser 5832
				$conf["stringProcess"]["correctCharacter"]["stringIn"]=$keyConstraintName;#爲要處理的字串
43 liveuser 5833
				#可省略參數:
1 liveuser 5834
				$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array("`");#爲被選擇要處理的字串/字元,須爲陣列值。
5835
				#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
5836
				#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
5837
				$thisKeyConstraintName=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
5838
				unset($conf["stringProcess"]["correctCharacter"]);
5839
 
5840
				#如果處理字串失敗
5841
				if($thisKeyConstraintName["status"]=="false"){
5842
 
5843
					#設置執行不正常
5844
					$result["status"]="false";
5845
 
5846
					#設置錯誤訊息
5847
					$result["error"]=$thisKeyConstraintName;
5848
 
5849
					#回傳結果
5850
					return $result;
5851
 
5852
					}#if end
5853
 
5854
				#儲存 key 的名稱
5855
				$result["keyConstraintName"][]=$thisKeyConstraintName["content"];
5856
 
5857
				#將 $result["keyConstraintName"] 用 欄位的名稱去儲存
5858
				$result["keyConstraintName"][$thisKeyColumnName]=$thisKeyConstraintName["content"];
5859
 
5860
				#後續省略
5861
				continue;
5862
 
5863
				}#if end
5864
 
5865
			#尋找是否有 CONSTRAINT 關鍵字
43 liveuser 5866
			#函式說明:
1 liveuser 5867
			#檢查字串裡面有無指定的關鍵字
43 liveuser 5868
			#回傳結果::
1 liveuser 5869
			#$result["status"],"true"代表執行成功,"false"代表執行失敗。
5870
			#$result["error"],錯誤訊息
5871
			#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 5872
			#必填參數:
1 liveuser 5873
			$conf["search"]["findKeyWord"]["keyWord"]="CONSTRAINT";#想要搜尋的關鍵字
5874
			$conf["search"]["findKeyWord"]["string"]=$unClassifyString;#要被搜尋的字串內容
43 liveuser 5875
			#可省略參數:
1 liveuser 5876
			#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
5877
			$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
5878
			unset($conf["search"]["findKeyWord"]);
5879
 
5880
			#如果尋找關鍵字失敗
5881
			if($searchResult["status"]=="false"){
5882
 
5883
				#設置執行不正常
5884
				$result["status"]="false";
5885
 
5886
				#設置錯誤訊息
5887
				$result["error"]=$searchResult;
5888
 
5889
				#回傳結果
5890
				return $result;
5891
 
5892
				}#if end
5893
 
5894
			#如果有找到 "CONSTRAINT"
5895
			if($searchResult["founded"]=="true"){
5896
 
5897
				#取得 CONSTRAINT 的名稱
5898
 
5899
				#用 " " 來分割字串
43 liveuser 5900
				#函式說明:
1 liveuser 5901
				#將固定格式的字串分開,並回傳分開的結果。
5902
				#回傳的參數:
5903
				#$result["oriStr"],要分割的原始字串內容
5904
				#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5905
				#$result["dataCounts"],爲總共分成幾段
43 liveuser 5906
				#必填參數:
1 liveuser 5907
				$conf["stringProcess"]["spiltString"]["stringIn"]=$unClassifyString;#要處理的字串。
5908
				$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
5909
				$foreignKeyConstraintString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
5910
				unset($conf["stringProcess"]["spiltString"]);
5911
 
5912
				#如果分割字串失敗
5913
				if($foreignKeyConstraintString["status"]=="false"){
5914
 
5915
					#設置執行不正常
5916
					$result["status"]="false";
5917
 
5918
					#設置錯誤訊息
5919
					$result["error"]=$foreignKeyConstraintString;
5920
 
5921
					#回傳結果
5922
					return $result;
5923
 
5924
					}#if end	
5925
 
5926
				#將 $foreignKeyString[0] 的非必要字元踢除
5927
				#將「,」、「`」、「(」、「)」去掉 
43 liveuser 5928
				#函式說明:
1 liveuser 5929
				#處理字串避免網頁出錯
43 liveuser 5930
				#回傳結果::
1 liveuser 5931
				#$result,爲處理好的字串。
43 liveuser 5932
				#必填參數:
1 liveuser 5933
				$conf["stringProcess"]["correctCharacter"]["stringIn"]=$foreignKeyConstraintString["dataArray"][1];#爲要處理的字串
43 liveuser 5934
				#可省略參數:
1 liveuser 5935
				$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array("`");#爲被選擇要處理的字串/字元,須爲陣列值。
5936
				#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
5937
				#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
5938
				$foreignConstraintName=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
5939
				unset($conf["stringProcess"]["correctCharacter"]);		
5940
 
5941
				#如果處理 CONSTRAINT 字串失敗
5942
				if($foreignConstraintName["status"]=="false"){
5943
 
5944
					#設置執行不正常
5945
					$result["status"]="false";
5946
 
5947
					#設置錯誤訊息
5948
					$result["error"]=$foreignConstraintName;
5949
 
5950
					#回傳結果
5951
					return $result;
5952
 
5953
					}#if end	
5954
 
5955
				#儲存 foreignKey 的 CONSTRAINT 名稱
5956
				$result["foreignKey"]["constraintName"][]=$foreignConstraintName["content"];	
5957
 
5958
				#尋找 "FOREIGN KEY"
43 liveuser 5959
				#函式說明:
1 liveuser 5960
				#檢查字串裡面有無指定的關鍵字
43 liveuser 5961
				#回傳結果::
1 liveuser 5962
				#$result["status"],"true"代表執行成功,"false"代表執行失敗。
5963
				#$result["error"],錯誤訊息
5964
				#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 5965
				#必填參數:
1 liveuser 5966
				$conf["search"]["findKeyWord"]["keyWord"]="FOREIGN KEY";#想要搜尋的關鍵字
5967
				$conf["search"]["findKeyWord"]["string"]=$unClassifyString;#要被搜尋的字串內容
43 liveuser 5968
				#可省略參數:
1 liveuser 5969
				#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
5970
				$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
5971
				unset($conf["search"]["findKeyWord"]);
5972
 
5973
				#如果尋找關鍵字失敗
5974
				if($searchResult["status"]=="false"){
5975
 
5976
					#設置執行不正常
5977
					$result["status"]="false";
5978
 
5979
					#設置錯誤訊息
5980
					$result["error"]=$searchResult;
5981
 
5982
					#回傳結果
5983
					return $result;
5984
 
5985
					}#if end
5986
 
5987
				#如果有找到 "FOREIGN KEY"
5988
				if($searchResult["founded"]=="true"){
5989
 
5990
					#用 "FOREIGN KEY " 來分割字串
43 liveuser 5991
					#函式說明:
1 liveuser 5992
					#將固定格式的字串分開,並回傳分開的結果。
5993
					#回傳的參數:
5994
					#$result["oriStr"],要分割的原始字串內容
5995
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
5996
					#$result["dataCounts"],爲總共分成幾段
43 liveuser 5997
					#必填參數:
1 liveuser 5998
					$conf["stringProcess"]["spiltString"]["stringIn"]=$unClassifyString;#要處理的字串。
5999
					$conf["stringProcess"]["spiltString"]["spiltSymbol"]="FOREIGN KEY ";#爲以哪個符號作爲分割
6000
					$foreignKeyString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
6001
					unset($conf["stringProcess"]["spiltString"]);
6002
 
6003
					#如果分割字串失敗
6004
					if($foreignKeyString["status"]=="false"){
6005
 
6006
						#設置執行不正常
6007
						$result["status"]="false";
6008
 
6009
						#設置錯誤訊息
6010
						$result["error"]=$foreignKeyString;
6011
 
6012
						#回傳結果
6013
						return $result;
6014
 
6015
						}#if end	
6016
 
6017
					#用 " " 來分割字串
43 liveuser 6018
					#函式說明:
1 liveuser 6019
					#將固定格式的字串分開,並回傳分開的結果。
6020
					#回傳的參數:
6021
					#$result["oriStr"],要分割的原始字串內容
6022
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
6023
					#$result["dataCounts"],爲總共分成幾段
43 liveuser 6024
					#必填參數:
1 liveuser 6025
					$conf["stringProcess"]["spiltString"]["stringIn"]=$foreignKeyString["dataArray"][1];#要處理的字串。
6026
					$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
6027
					$foreignKeyString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
6028
					unset($conf["stringProcess"]["spiltString"]);
6029
 
6030
					#如果分割字串失敗
6031
					if($foreignKeyString["status"]=="false"){
6032
 
6033
						#設置執行不正常
6034
						$result["status"]="false";
6035
 
6036
						#設置錯誤訊息
6037
						$result["error"]=$foreignKeyString;
6038
 
6039
						#回傳結果
6040
						return $result;
6041
 
6042
						}#if end	
6043
 
6044
					#將 $foreignKeyString[0] 的非必要字元踢除
6045
					#將「,」、「`」、「(」、「)」去掉 
43 liveuser 6046
					#函式說明:
1 liveuser 6047
					#處理字串避免網頁出錯
43 liveuser 6048
					#回傳結果::
1 liveuser 6049
					#$result,爲處理好的字串。
43 liveuser 6050
					#必填參數:
1 liveuser 6051
					$conf["stringProcess"]["correctCharacter"]["stringIn"]=$foreignKeyString["dataArray"][0];#爲要處理的字串
43 liveuser 6052
					#可省略參數:
1 liveuser 6053
					$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",","`","(",")");#爲被選擇要處理的字串/字元,須爲陣列值。
6054
					#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
6055
					#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
6056
					$thisForeignKeyColumnName=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
6057
					unset($conf["stringProcess"]["correctCharacter"]);
6058
 
6059
					#如果 處理字串失敗
6060
					if($thisForeignKeyColumnName["status"]=="false"){
6061
 
6062
						#設置執行不正常
6063
						$result["status"]="false";
6064
 
6065
						#設置錯誤訊息
6066
						$result["error"]=$thisForeignKeyColumnName;
6067
 
6068
						#回傳結果
6069
						return $result;
6070
 
6071
						}#if end
6072
 
6073
					#儲存外鍵欄位的名稱
6074
					$result["foreignKey"]["columnName"][]=$thisForeignKeyColumnName["content"];
6075
 
6076
					#用該外鍵欄位的名稱,作為key來存放外鍵欄位的名稱
6077
					$result["foreignKey"]["columnName"][$thisForeignKeyColumnName["content"]]=$thisForeignKeyColumnName["content"];
6078
 
6079
					#用 "REFERENCES " 來分割字串
43 liveuser 6080
					#函式說明:
1 liveuser 6081
					#將固定格式的字串分開,並回傳分開的結果。
6082
					#回傳的參數:
6083
					#$result["oriStr"],要分割的原始字串內容
6084
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
6085
					#$result["dataCounts"],爲總共分成幾段
43 liveuser 6086
					#必填參數:
1 liveuser 6087
					$conf["stringProcess"]["spiltString"]["stringIn"]=$unClassifyString;#要處理的字串。
6088
					$conf["stringProcess"]["spiltString"]["spiltSymbol"]="REFERENCES ";#爲以哪個符號作爲分割
6089
					$foreignKeyReferencesString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
6090
					unset($conf["stringProcess"]["spiltString"]);
6091
 
6092
					#如果分割字串失敗
6093
					if($foreignKeyReferencesString["status"]=="false"){
6094
 
6095
						#設置執行不正常
6096
						$result["status"]="false";
6097
 
6098
						#設置錯誤訊息
6099
						$result["error"]=$foreignKeyReferencesString;
6100
 
6101
						#回傳結果
6102
						return $result;
6103
 
6104
						}#if end
6105
 
6106
					#用 " " 來分割字串
43 liveuser 6107
					#函式說明:
1 liveuser 6108
					#將固定格式的字串分開,並回傳分開的結果。
6109
					#回傳的參數:
6110
					#$result["oriStr"],要分割的原始字串內容
6111
					#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
6112
					#$result["dataCounts"],爲總共分成幾段
43 liveuser 6113
					#必填參數:
1 liveuser 6114
					$conf["stringProcess"]["spiltString"]["stringIn"]=$foreignKeyReferencesString["dataArray"][1];#要處理的字串。
6115
					$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
6116
					$foreignKeyReferencesString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
6117
					unset($conf["stringProcess"]["spiltString"]);
6118
 
6119
					#如果分割字串失敗
6120
					if($foreignKeyReferencesString["status"]=="false"){
6121
 
6122
						#設置執行不正常
6123
						$result["status"]="false";
6124
 
6125
						#設置錯誤訊息
6126
						$result["error"]=$foreignKeyReferencesString;
6127
 
6128
						#回傳結果
6129
						return $result;
6130
 
6131
						}#if end
6132
 
6133
					#將 $foreignKeyString[0] 的非必要字元踢除
6134
					#將「,」、「`」、「(」、「)」去掉 
43 liveuser 6135
					#函式說明:
1 liveuser 6136
					#處理字串避免網頁出錯
43 liveuser 6137
					#回傳結果::
1 liveuser 6138
					#$result,爲處理好的字串。
43 liveuser 6139
					#必填參數:
1 liveuser 6140
					$conf["stringProcess"]["correctCharacter"]["stringIn"]=$foreignKeyReferencesString["dataArray"][1];#爲要處理的字串
43 liveuser 6141
					#可省略參數:
1 liveuser 6142
					$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",","`","(",")");#爲被選擇要處理的字串/字元,須爲陣列值。
6143
						#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
6144
					#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
6145
					$tempReferencesColumn=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
6146
					unset($conf["stringProcess"]["correctCharacter"]);
6147
 
6148
					#如果 處理字串失敗
6149
					if($tempReferencesColumn["status"]=="false"){
6150
 
6151
						#設置執行不正常
6152
						$result["status"]="false";
6153
 
6154
						#設置錯誤訊息
6155
						$result["error"]=$tempReferencesColumn;
6156
 
6157
						#回傳結果
6158
						return $result;
6159
 
6160
						}#if end
6161
 
6162
					#取得參照的欄位名稱
6163
					$result["foreignKey"]["referencesColumn"][]=$tempReferencesColumn["content"];
6164
 
6165
					#用欄位名稱來儲存參照的資料表
6166
					$result["foreignKey"]["referencesColumn"][$thisForeignKeyColumnName["content"]]=$tempReferencesColumn["content"];
6167
 
6168
					#將 $foreignKeyString[0] 的非必要字元踢除
6169
					#將「,」、「`」、「(」、「)」去掉 
43 liveuser 6170
					#函式說明:
1 liveuser 6171
					#處理字串避免網頁出錯
43 liveuser 6172
					#回傳結果::
1 liveuser 6173
					#$result,爲處理好的字串。
43 liveuser 6174
					#必填參數:
1 liveuser 6175
					$conf["stringProcess"]["correctCharacter"]["stringIn"]=$foreignKeyReferencesString["dataArray"][0];#爲要處理的字串
43 liveuser 6176
					#可省略參數:
1 liveuser 6177
					$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array("`");#爲被選擇要處理的字串/字元,須爲陣列值。
6178
					#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
6179
					#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
6180
					$tempReferencesTable=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
6181
					unset($conf["stringProcess"]["correctCharacter"]);
6182
 
6183
					#如果處理字串失敗
6184
					if($tempReferencesTable["status"]=="false"){
6185
 
6186
						#設置執行不正常
6187
						$result["status"]="false";
6188
 
6189
						#設置錯誤訊息
6190
						$result["error"]=$tempReferencesTable;
6191
 
6192
						#回傳結果
6193
						return $result;
6194
 
6195
						}#if end	
6196
 
6197
					#取得參照的資料表
6198
					$result["foreignKey"]["referencesTable"][]=$tempReferencesTable["content"];
6199
 
6200
					#用欄位名稱來儲存參照的欄位
6201
					$result["foreignKey"]["referencesTable"][$thisForeignKeyColumnName["content"]]=$tempReferencesTable["content"];
6202
 
6203
					#如果有 "ON UPDATE" 存在
43 liveuser 6204
					#函式說明:
1 liveuser 6205
					#檢查字串裡面有無指定的關鍵字
43 liveuser 6206
					#回傳結果::
1 liveuser 6207
					#$result["status"],"true"代表執行成功,"false"代表執行失敗。
6208
					#$result["error"],錯誤訊息
6209
					#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 6210
					#必填參數:
1 liveuser 6211
					$conf["search"]["findKeyWord"]["keyWord"]="ON UPDATE";#想要搜尋的關鍵字
6212
					$conf["search"]["findKeyWord"]["string"]=$unClassifyString;#要被搜尋的字串內容
43 liveuser 6213
					#可省略參數:
1 liveuser 6214
					#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
6215
					$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
6216
					unset($conf["search"]["findKeyWord"]);
6217
 
6218
					#如果尋找關鍵字失敗
6219
					if($searchResult["status"]=="false"){
6220
 
6221
						#設置執行不正常
6222
						$result["status"]="false";
6223
 
6224
						#設置錯誤訊息
6225
						$result["error"]=$searchResult;
6226
 
6227
						#回傳結果
6228
						return $result;
6229
 
6230
						}#if end
6231
 
6232
					#如果有找到 "ON UPDATE"
6233
					if($searchResult["founded"]=="true"){
6234
 
6235
						#用 "ON UPDATE " 來分割字串
43 liveuser 6236
						#函式說明:
1 liveuser 6237
						#將固定格式的字串分開,並回傳分開的結果。
6238
						#回傳的參數:
6239
						#$result["oriStr"],要分割的原始字串內容
6240
						#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
6241
						#$result["dataCounts"],爲總共分成幾段
43 liveuser 6242
						#必填參數:
1 liveuser 6243
						$conf["stringProcess"]["spiltString"]["stringIn"]=$unClassifyString;#要處理的字串。
6244
						$conf["stringProcess"]["spiltString"]["spiltSymbol"]="ON UPDATE ";#爲以哪個符號作爲分割
6245
						$foreignKeyOnUpdateString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
6246
						unset($conf["stringProcess"]["spiltString"]);
6247
 
6248
						#如果分割字串失敗
6249
						if($foreignKeyOnUpdateString["status"]=="false"){
6250
 
6251
							#設置執行不正常
6252
							$result["status"]="false";
6253
 
6254
							#設置錯誤訊息
6255
							$result["error"]=$searchResult;
6256
 
6257
							#回傳結果
6258
							return $result;
6259
 
6260
							}#if end
6261
 
6262
						#檢查裏面是否含有 " ON DELETE " 字樣
43 liveuser 6263
						#函式說明:
1 liveuser 6264
						#檢查字串裡面有無指定的關鍵字
43 liveuser 6265
						#回傳結果::
1 liveuser 6266
						#$result["status"],"true"代表執行成功,"false"代表執行失敗。
6267
						#$result["error"],錯誤訊息
6268
						#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 6269
						#必填參數:
1 liveuser 6270
						$conf["search"]["findKeyWord"]["keyWord"]=" ON DELETE ";#想要搜尋的關鍵字
6271
						$conf["search"]["findKeyWord"]["string"]=$foreignKeyOnUpdateString["dataArray"][1];#要被搜尋的字串內容
43 liveuser 6272
						#可省略參數:
1 liveuser 6273
						#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
6274
						$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
6275
						unset($conf["search"]["findKeyWord"]);
6276
 
6277
						#如果尋找關鍵字失敗
6278
						if($searchResult["status"]=="false"){
6279
 
6280
							#設置執行不正常
6281
							$result["status"]="false";
6282
 
6283
							#設置錯誤訊息
6284
							$result["error"]=$searchResult;
6285
 
6286
							#回傳結果
6287
							return $result;
6288
 
6289
							}#if end
6290
 
6291
						#如果裏面含有 "ON DELETE " 字樣
6292
						if($searchResult["founded"]=="true"){
6293
 
6294
							#我們只要取得 "ON DELETE " 前面的內容
6295
							#用"ON UPDATE "來分割
43 liveuser 6296
							#函式說明:
1 liveuser 6297
							#將固定格式的字串分開,並回傳分開的結果。
6298
							#回傳的參數:
6299
							#$result["oriStr"],要分割的原始字串內容
6300
							#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
6301
							#$result["dataCounts"],爲總共分成幾段
43 liveuser 6302
							#必填參數:
1 liveuser 6303
							$conf["stringProcess"]["spiltString"]["stringIn"]=$foreignKeyOnUpdateString["dataArray"][1];#要處理的字串。
6304
							$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ON DELETE ";#爲以哪個符號作爲分割
6305
							$foreignKeyOnDeleteString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
6306
							unset($conf["stringProcess"]["spiltString"]);
6307
							#var_dump($foreignKeyOnDeleteString);
6308
 
6309
							#如果分割字串失敗
6310
							if($foreignKeyOnDeleteString["status"]=="false"){
6311
 
6312
								#設置執行不正常
6313
								$result["status"]="false";
6314
 
6315
								#設置錯誤訊息
6316
								$result["error"]=$foreignKeyOnDeleteString;
6317
 
6318
								#回傳結果
6319
								return $result;
6320
 
6321
								}#if end
6322
 
6323
							$foreignKeyOnUpdateString=$foreignKeyOnUpdateString["dataArray"][0];
6324
 
6325
							#將 $foreignKeyOnUpdateString 的非必要字元踢除
6326
							#將「,」、「`」、「(」、「)」去掉 
43 liveuser 6327
							#函式說明:
1 liveuser 6328
							#處理字串避免網頁出錯
43 liveuser 6329
							#回傳結果::
1 liveuser 6330
							#$result,爲處理好的字串。
43 liveuser 6331
							#必填參數:
1 liveuser 6332
							$conf["stringProcess"]["correctCharacter"]["stringIn"]=$foreignKeyOnUpdateString;#爲要處理的字串
43 liveuser 6333
							#可省略參數:
1 liveuser 6334
							$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",");#爲被選擇要處理的字串/字元,須爲陣列值。
6335
								#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
6336
							#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
6337
							$tempOnUpdateAction=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
6338
							unset($conf["stringProcess"]["correctCharacter"]);
6339
 
6340
							#如果 處理字串 失敗
6341
							if($tempOnUpdateAction["status"]=="false"){
6342
 
6343
								#設置執行不正常
6344
								$result["status"]="false";
6345
 
6346
								#設置錯誤訊息
6347
								$result["error"]=$tempOnUpdateAction;
6348
 
6349
								#回傳結果
6350
								return $result;
6351
 
6352
								}#if end
6353
 
6354
							#紀錄 ON UPDATE 的動作字串
6355
							$result["foreignKey"]["onUpdateAction"][]=$tempOnUpdateAction["content"];
6356
 
6357
							#用 freign key 的名稱來紀錄外鍵更新的動作
6358
							$result["foreignKey"]["onUpdateAction"][$thisForeignKeyColumnName]=$tempOnUpdateAction["content"];
6359
 
6360
							}#if end
6361
 
6362
						#反之 沒有 "ON DELETE " 字樣
6363
						else{	
6364
 
6365
							#var_dump($foreignKeyOnUpdateString["dataArray"][1]);
6366
 
6367
							#將 $foreignKeyOnUpdateString 的非必要字元踢除
6368
							#將「,」、「`」、「(」、「)」去掉 
43 liveuser 6369
							#函式說明:
1 liveuser 6370
							#處理字串避免網頁出錯
43 liveuser 6371
							#回傳結果::
1 liveuser 6372
							#$result,爲處理好的字串。
43 liveuser 6373
							#必填參數:
1 liveuser 6374
							$conf["stringProcess"]["correctCharacter"]["stringIn"]=$foreignKeyOnUpdateString["dataArray"][1];#爲要處理的字串
43 liveuser 6375
							#可省略參數:
1 liveuser 6376
							$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",");#爲被選擇要處理的字串/字元,須爲陣列值。
6377
								#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
6378
							#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
6379
							$tempOnUpdateAction=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
6380
							unset($conf["stringProcess"]["correctCharacter"]);
6381
 
6382
							#如果處理字串失敗
6383
							if($tempOnUpdateAction["status"]=="false"){
6384
 
6385
								#設置執行不正常
6386
								$result["status"]="false";
6387
 
6388
								#設置錯誤訊息
6389
								$result["error"]=$tempOnUpdateAction;
6390
 
6391
								#回傳結果
6392
								return $result;
6393
 
6394
								}#if end
6395
 
6396
							#紀錄外鍵更新的動作
6397
							$result["foreignKey"]["onUpdateAction"][]=$tempOnUpdateAction["content"];
6398
 
6399
							#用 freign key 的名稱來紀錄外鍵更新的動作
6400
							$result["foreignKey"]["onUpdateAction"][$thisForeignKeyColumnName["content"]]=$tempOnUpdateAction["content"];
6401
 
6402
							}#else end
6403
 
6404
						}#if end
6405
 
6406
					#如果有 "ON DELETE" 存在
43 liveuser 6407
					#函式說明:
1 liveuser 6408
					#檢查字串裡面有無指定的關鍵字
43 liveuser 6409
					#回傳結果::
1 liveuser 6410
					#$result["status"],"true"代表執行成功,"false"代表執行失敗。
6411
					#$result["error"],錯誤訊息
6412
					#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 6413
					#必填參數:
1 liveuser 6414
					$conf["search"]["findKeyWord"]["keyWord"]="ON DELETE";#想要搜尋的關鍵字
6415
					$conf["search"]["findKeyWord"]["string"]=$unClassifyString;#要被搜尋的字串內容
43 liveuser 6416
					#可省略參數:
1 liveuser 6417
					#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
6418
					$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
6419
					unset($conf["search"]["findKeyWord"]);
6420
 
6421
					#如果尋找關鍵字失敗
6422
					if($searchResult["status"]=="false"){
6423
 
6424
						#設置執行不正常
6425
						$result["status"]="false";
6426
 
6427
						#設置錯誤訊息
6428
						$result["error"]=$searchResult;
6429
 
6430
						#回傳結果
6431
						return $result;
6432
 
6433
						}#if end
6434
 
6435
					#如果有找到 "ON DELETE"
6436
					if($searchResult["founded"]=="true"){							
6437
 
6438
						#用 "ON DELETE " 來分割字串
43 liveuser 6439
						#函式說明:
1 liveuser 6440
						#將固定格式的字串分開,並回傳分開的結果。
6441
						#回傳的參數:
6442
						#$result["oriStr"],要分割的原始字串內容
6443
						#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
6444
						#$result["dataCounts"],爲總共分成幾段
43 liveuser 6445
						#必填參數:
1 liveuser 6446
						$conf["stringProcess"]["spiltString"]["stringIn"]=$unClassifyString;#要處理的字串。
6447
						$conf["stringProcess"]["spiltString"]["spiltSymbol"]="ON DELETE ";#爲以哪個符號作爲分割
6448
						$foreignKeyOnDeleteString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
6449
						unset($conf["stringProcess"]["spiltString"]);
6450
 
6451
						#如果分割字串失敗
6452
						if($foreignKeyOnDeleteString["status"]=="false"){
6453
 
6454
							#設置執行不正常
6455
							$result["status"]="false";
6456
 
6457
							#設置錯誤訊息
6458
							$result["error"]=$foreignKeyOnDeleteString;
6459
 
6460
							#回傳結果
6461
							return $result;
6462
 
6463
							}#if end
6464
 
6465
						#檢查裏面是否含有 " ON UPDATE " 字樣
43 liveuser 6466
						#函式說明:
1 liveuser 6467
						#檢查字串裡面有無指定的關鍵字
43 liveuser 6468
						#回傳結果::
1 liveuser 6469
						#$result["status"],"true"代表執行成功,"false"代表執行失敗。
6470
						#$result["error"],錯誤訊息
6471
						#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 6472
						#必填參數:
1 liveuser 6473
						$conf["search"]["findKeyWord"]["keyWord"]="ON UPDATE ";#想要搜尋的關鍵字
6474
						$conf["search"]["findKeyWord"]["string"]=$foreignKeyOnDeleteString["dataArray"][1];#要被搜尋的字串內容
43 liveuser 6475
						#可省略參數:
1 liveuser 6476
						#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
6477
						$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
6478
						unset($conf["search"]["findKeyWord"]);
6479
 
6480
						#如果分割字串失敗
6481
						if($searchResult["status"]=="false"){
6482
 
6483
							#設置執行不正常
6484
							$result["status"]="false";
6485
 
6486
							#設置錯誤訊息
6487
							$result["error"]=$searchResult;
6488
 
6489
							#回傳結果
6490
							return $result;
6491
 
6492
							}#if end
6493
 
6494
						#如果裏面含有 "ON UPDATE " 字樣
6495
						if($searchResult["founded"]=="true"){
6496
 
6497
							#我們只要取得 "ON UPDATE " 前面的內容
6498
							#用"ON UPDATE "來分割
43 liveuser 6499
							#函式說明:
1 liveuser 6500
							#將固定格式的字串分開,並回傳分開的結果。
6501
							#回傳的參數:
6502
							#$result["oriStr"],要分割的原始字串內容
6503
							#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
6504
							#$result["dataCounts"],爲總共分成幾段
43 liveuser 6505
							#必填參數:
1 liveuser 6506
							$conf["stringProcess"]["spiltString"]["stringIn"]=$foreignKeyOnDeleteString["dataArray"][1];#要處理的字串。
6507
							$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ON UPDATE ";#爲以哪個符號作爲分割
6508
							$foreignKeyOnDeleteString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
6509
							unset($conf["stringProcess"]["spiltString"]);
6510
 
6511
							#如果分割字串失敗
6512
							if($searchResult["status"]=="false"){
6513
 
6514
								#設置執行不正常
6515
								$result["status"]="false";
6516
 
6517
								#設置錯誤訊息
6518
								$result["error"]=$searchResult;
6519
 
6520
								#回傳結果
6521
								return $result;
6522
 
6523
								}#if end
6524
 
6525
							$foreignKeyOnDeleteString=$foreignKeyOnDeleteString["dataArray"][0];
6526
 
6527
							#將 $foreignKeyString[0] 的非必要字元踢除
6528
							#將「,」、「`」、「(」、「)」去掉 
43 liveuser 6529
							#函式說明:
1 liveuser 6530
							#處理字串避免網頁出錯
43 liveuser 6531
							#回傳結果::
1 liveuser 6532
							#$result,爲處理好的字串。
43 liveuser 6533
							#必填參數:
1 liveuser 6534
							$conf["stringProcess"]["correctCharacter"]["stringIn"]=$foreignKeyOnDeleteString;#爲要處理的字串
43 liveuser 6535
							#可省略參數:
1 liveuser 6536
							$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",");#爲被選擇要處理的字串/字元,須爲陣列值。
6537
								#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
6538
							#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
6539
							$tempOneleteAction=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
6540
							unset($conf["stringProcess"]["correctCharacter"]);
6541
 
6542
							#如果處理字串失敗
6543
							if($tempOneleteAction["status"]=="false"){
6544
 
6545
								#設置執行不正常
6546
								$result["status"]="false";
6547
 
6548
								#設置錯誤訊息
6549
								$result["error"]=$tempOneleteAction;
6550
 
6551
								#回傳結果
6552
								return $result;
6553
 
6554
								}#if end
6555
 
6556
							#儲存外鍵移除後的動作
6557
							$result["foreignKey"]["onDeleteAction"][]=$tempOneleteAction["content"];
6558
 
6559
							#用 freign key 的名稱來紀錄外鍵移除後的動作
6560
							$result["foreignKey"]["onDeleteAction"][$thisForeignKeyColumnName["content"]]=$tempOneleteAction["content"];
6561
 
6562
							}#if end
6563
 
6564
						#反之裏面沒有 "ON UPDATE " 字樣
6565
						else{
6566
 
6567
							#將 $foreignKeyString[0] 的非必要字元踢除
6568
							#將「,」、「`」、「(」、「)」去掉 
43 liveuser 6569
							#函式說明:
1 liveuser 6570
							#處理字串避免網頁出錯
43 liveuser 6571
							#回傳結果::
1 liveuser 6572
							#$result,爲處理好的字串。
43 liveuser 6573
							#必填參數:
1 liveuser 6574
							$conf["stringProcess"]["correctCharacter"]["stringIn"]=$foreignKeyOnDeleteString["dataArray"][1];#爲要處理的字串
43 liveuser 6575
							#可省略參數:
1 liveuser 6576
							$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",");#爲被選擇要處理的字串/字元,須爲陣列值。
6577
							#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
6578
							#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
6579
							$tempOneleteAction=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
6580
							unset($conf["stringProcess"]["correctCharacter"]);
6581
 
6582
							#如果處理字串失敗
6583
							if($tempOneleteAction["status"]=="false"){
6584
 
6585
								#設置執行不正常
6586
								$result["status"]="false";
6587
 
6588
								#設置錯誤訊息
6589
								$result["error"]=$tempOneleteAction;
6590
 
6591
								#回傳結果
6592
								return $result;
6593
 
6594
								}#if end
6595
 
6596
							#取得 外鍵移除後的動作
6597
							$result["foreignKey"]["OnDeleteAction"][]=$tempOneleteAction["content"];
6598
 
6599
							#用 freign key 的名稱來紀錄外鍵移除後的動作
6600
							$result["foreignKey"]["onDeleteAction"][$thisForeignKeyColumnName]=$tempOneleteAction["content"];
6601
 
6602
							}#else end
6603
 
6604
						}#if end
6605
 
6606
					}#if end
6607
 
6608
				}#if end
6609
 
6610
			}#foreach end
6611
 
6612
		#如果儲存索引鍵資訊的變數存在
6613
		if(isset($result["key"])){
6614
 
6615
			#如果索引鍵的數量大於0
6616
			if(count($result["key"])>0){
6617
 
6618
				#設置 $result["key"]["exist"] 為 "true";
6619
				$result["key"]["exist"]="true";
6620
 
6621
				}#if end
6622
 
6623
			#反之沒有索引鍵	
6624
			else{
6625
 
6626
				#設置 $result["key"]["exist"] 為 "false";
6627
				$result["key"]["exist"]="false";
6628
 
6629
				}#else end
6630
 
6631
			}#if end
6632
 
6633
		#如果 $result["foreignKey"]["constraintName"] 存在
6634
		if(isset($result["foreignKey"]["constraintName"])){
6635
 
6636
			#如果 $result["foreignKey"]["constraintName"] 數量大於 0
6637
			if(count($result["foreignKey"]["constraintName"])>0){
6638
 
6639
				#針對每個 $result["foreignKey"]["constraintName"][$k] 
6640
				for($i=0;$i<count($result["foreignKey"]["columnName"])/2;$i++){
6641
 
6642
					#指派 $result["foreignKey"]["constraintName"][$k] 的內容同時指派給 $result["foreignKey"]["constraintName"][$result["foreignKey"]["columnName"][$k]]
6643
					$result["foreignKey"]["constraintName"][$result["foreignKey"]["columnName"][$i]]=$result["foreignKey"]["constraintName"][$i];
6644
 
6645
					}#if end
6646
 
6647
				#將 $result["foreignKey"]["exist"] 設為 "true"
6648
				$result["foreignKey"]["exist"]="true";
6649
 
6650
				}#if end
6651
 
6652
			#反之 $result["foreignKey"]["exist"] 數量等於 0
6653
			else{
6654
 
6655
				#將 $result["foreignKey"]["exist"] 設為 "fasle"
6656
				$result["foreignKey"]["exist"]="false";
6657
 
6658
				}#else end
6659
 
6660
			}#if end	
6661
 
6662
		#反之 $result["foreignKey"]["constraintName"] 不存在
6663
		else{
6664
 
6665
			#將 $result["foreignKey"]["exist"] 設為 "fasle"
6666
			$result["foreignKey"]["exist"]="false";
6667
 
6668
			}#else end
6669
 
6670
		#執行到這邊代表執行成功
6671
 
6672
		#設置成功訊息
6673
		$result["status"]="true";
6674
 
6675
		#回傳結果
6676
		return $result;
6677
 
6678
		}#function getTableColumnDetailInfo end
6679
 
6680
	/*
43 liveuser 6681
	#函式說明:
1 liveuser 6682
	#移除資料表單1欄位的外鍵
43 liveuser 6683
	#回傳結果:
1 liveuser 6684
	#$result["status"],"true",代表執行成功;"false"代表執行失敗
6685
	#$result["function"],當前執行的函數名稱.
6686
	#$result["error"],錯誤訊息陣列
6687
	#$result["sql"],執行的sql字串.
43 liveuser 6688
	#必填參數:
1 liveuser 6689
	#$conf["dbAddress"],字串,爲mysql-Server的位置
6690
	$conf["dbAddress"]=$dbAddress;
6691
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
6692
	$conf["dbAccount"]=$dbAccount;
6693
	#$conf["selectedDataBaseName"],字串,爲目標資料表所屬的資料庫.
6694
	$conf["selectedDataBaseName"]="";
6695
	#$conf["selectedDataTableName"],字串,爲目標資料表所屬的資料庫.
6696
	$conf["selectedDataTableName"]="";
6697
	#$conf["erasedForeignKeyColumnConstraintName"],字串,要移除外鍵欄位的CONSTRAINT名稱.
6698
	$conf["erasedForeignKeyColumnConstraintName"]="";
43 liveuser 6699
	#可省略參數: 
1 liveuser 6700
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
6701
	#$conf["dbPassword"]=$dbPassword;
6702
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
6703
	#$conf["dbPort"]="3306";
185 liveuser 6704
	#參考資料:
6705
	#無.
43 liveuser 6706
	#備註:
6707
	#無.
1 liveuser 6708
	*/ 
6709
	public static function eraseForeignKey($conf){
6710
 
6711
		#初始化要回傳的內容
6712
		$result=array();
6713
 
6714
		#取得當前執行的函數名稱
6715
		$result["function"]=__FUNCTION__;
6716
 
6717
		#如果 $conf 不為陣列
6718
		if(gettype($conf)!="array"){
6719
 
6720
			#設置執行失敗
6721
			$result["status"]="false";
6722
 
6723
			#設置執行錯誤訊息
6724
			$result["error"][]="\$conf變數須為陣列形態";
6725
 
6726
			#如果傳入的參數為 null
6727
			if($conf==null){
6728
 
6729
				#設置執行錯誤訊息
6730
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6731
 
6732
				}#if end
6733
 
6734
			#回傳結果
6735
			return $result;
6736
 
6737
			}#if end
6738
 
43 liveuser 6739
		#函式說明:
1 liveuser 6740
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 6741
		#回傳結果:
1 liveuser 6742
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6743
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6744
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 6745
		#必填參數:
1 liveuser 6746
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
6747
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName","erasedForeignKeyColumnConstraintName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 6748
		#可省略參數:
1 liveuser 6749
		#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
6750
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
6751
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
6752
		unset($conf["variableCheck"]["isexistMuti"]);
6753
 
6754
		#如果檢查不通過
6755
		if($checkResult["passed"]=="false"){
6756
 
6757
			#設置執行失敗的訊息
6758
			$result["status"]="false";
6759
 
6760
			#設置錯誤訊息
6761
			$result["error"]=$checkResult;
6762
 
6763
			#回傳結果
6764
			return $result;
6765
 
6766
			}#if end
6767
 
6768
		#移除foreignKey的語法
6769
		$sql="ALTER TABLE ".$conf["selectedDataBaseName"].".".$conf["selectedDataTableName"]." DROP FOREIGN KEY ".$conf["erasedForeignKeyColumnConstraintName"];
6770
 
43 liveuser 6771
		#函式說明:
1 liveuser 6772
		#執行mysql查詢的指令
43 liveuser 6773
		#回傳結果::
1 liveuser 6774
		#$result["status"],"true"為執行成功;"false"為執行失敗。
6775
		#$result["error"],錯誤訊息的陣列
6776
		#查詢號的解果,需要解析。
43 liveuser 6777
		#必填參數:
1 liveuser 6778
		$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
6779
		$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
6780
		$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
43 liveuser 6781
		#可省略參數: 
1 liveuser 6782
 
6783
		#如果有設定密碼
6784
		if(isset($conf["dbPassword"])){
6785
 
6786
			$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
6787
 
6788
			}#if end
6789
 
6790
		#如果有設定 $conf["dbPort"]	
6791
		if(isset($conf["dbPort"])){
6792
 
6793
			#設定 $conf["dbPort"]
6794
			$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
6795
 
6796
			}#if end	
6797
 
6798
		$queryResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
6799
		unset($conf["db"]["execMysqlQuery"]);
6800
 
6801
		#取得執行的sql語法
6802
		$result["sql"]=$queryResult["queryString"];
6803
 
6804
		#如果執行sql語法錯誤
6805
		if($queryResult["status"]=="false"){
6806
 
6807
			#設置執行失敗的識別
6808
			$result["status"]="false";
6809
 
6810
			#設置執行錯誤資訊
6811
			$result["error"]=$queryResult;
6812
 
6813
			#回傳結果
6814
			return $result;
6815
 
6816
			}#if end
6817
 
6818
		#執行到這邊代表執行無誤
6819
 
6820
		#設置執行成功的識別
6821
		$result["status"]="true";
6822
 
6823
		#回傳結果
6824
		return $result;
6825
 
6826
		}#function eraseForeignKey end
6827
 
6828
	/*
43 liveuser 6829
	#函式說明:
1 liveuser 6830
	#移除資料表單1欄位的索引鍵
43 liveuser 6831
	#回傳結果:
1 liveuser 6832
	#$result["status"],"true",代表執行成功;"false"代表執行失敗
6833
	#$result["error"],錯誤訊息陣列
6834
	#$result["sql"],執行的sql字串.
43 liveuser 6835
	#必填參數:
1 liveuser 6836
	$conf["dbAddress"],字串,爲mysql-Server的位置.
6837
	$conf["dbAddress"]=$dbAddress;
6838
	$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號.
6839
	$conf["dbAccount"]=$dbAccount;
6840
	$conf["selectedDataBaseName"],字串,爲目標資料表所屬的資料庫.
6841
	$conf["selectedDataBaseName"]="";
6842
	$conf["selectedDataTableName"],字串,爲目標資料表所屬的資料庫.
6843
	$conf["selectedDataTableName"]="";
6844
	$conf["erasedIndexKeyColumnConstraintName"],字串,要移除外鍵欄位的CONSTRAINT名稱.
6845
	$conf["erasedIndexKeyColumnConstraintName"]="";
43 liveuser 6846
	#可省略參數: 
1 liveuser 6847
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
6848
	#$conf["dbPassword"]=$dbPassword;
6849
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
6850
	#$conf["dbPort"]="3306";
185 liveuser 6851
	#參考資料:
6852
	#無.
43 liveuser 6853
	#備註:
6854
	#無.
1 liveuser 6855
	*/ 
6856
	public static function eraseIndexKey($conf){
6857
 
6858
		#初始化要回傳的內容
6859
		$result=array();
6860
 
6861
		#取得當前執行的函數名稱
6862
		$result["function"]=__FUNCTION__;
6863
 
6864
		#如果 $conf 不為陣列
6865
		if(gettype($conf)!="array"){
6866
 
6867
			#設置執行失敗
6868
			$result["status"]="false";
6869
 
6870
			#設置執行錯誤訊息
6871
			$result["error"][]="\$conf變數須為陣列形態";
6872
 
6873
			#如果傳入的參數為 null
6874
			if($conf==null){
6875
 
6876
				#設置執行錯誤訊息
6877
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
6878
 
6879
				}#if end
6880
 
6881
			#回傳結果
6882
			return $result;
6883
 
6884
			}#if end
6885
 
43 liveuser 6886
		#函式說明:
1 liveuser 6887
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 6888
		#回傳結果:
1 liveuser 6889
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
6890
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
6891
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 6892
		#必填參數:
1 liveuser 6893
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
6894
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName","erasedIndexKeyColumnConstraintName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 6895
		#可省略參數:
1 liveuser 6896
		#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
6897
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
6898
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
6899
		unset($conf["variableCheck"]["isexistMuti"]);
6900
 
6901
		#檢查有誤
6902
		if($checkResult["status"]=="false"){
6903
 
6904
			#設置執行失敗的訊息
6905
			$result["status"]="false";
6906
 
6907
			#設置錯誤訊息
6908
			$result["error"]=$checkResult;
6909
 
6910
			#回傳結果
6911
			return $result;
6912
 
6913
			}#if end
6914
 
6915
		#如果檢查不通過
6916
		if($checkResult["passed"]=="false"){
6917
 
6918
			#設置執行失敗的訊息
6919
			$result["status"]="false";
6920
 
6921
			#設置錯誤訊息
6922
			$result["error"]=$checkResult;
6923
 
6924
			#回傳結果
6925
			return $result;
6926
 
6927
			}#if end
6928
 
6929
		#移除Key的語法
6930
		$sql="ALTER TABLE ".$conf["selectedDataBaseName"].".".$conf["selectedDataTableName"]." DROP INDEX `".$conf["erasedIndexKeyColumnConstraintName"]."`";
6931
 
43 liveuser 6932
		#函式說明:
1 liveuser 6933
		#執行mysql查詢的指令
43 liveuser 6934
		#回傳結果::
1 liveuser 6935
		#$result["status"],"true"為執行成功;"false"為執行失敗。
6936
		#$result["error"],錯誤訊息的陣列
6937
		#查詢號的解果,需要解析。
43 liveuser 6938
		#必填參數:
1 liveuser 6939
		$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
6940
		$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
6941
		$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
43 liveuser 6942
		#可省略參數: 
1 liveuser 6943
 
6944
		#如果有設定密碼
6945
		if(isset($conf["dbPassword"])){
6946
 
6947
			$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
6948
 
6949
			}#if end
6950
 
6951
		#如果有設定 $conf["dbPort"]	
6952
		if(isset($conf["dbPort"])){
6953
 
6954
			#設定 $conf["dbPort"]
6955
			$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
6956
 
6957
			}#if end	
6958
 
6959
		$queryResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
6960
		unset($conf["db"]["execMysqlQuery"]);
6961
 
6962
		#取得執行的sql語法
6963
		$result["sql"]=$queryResult["queryString"];
6964
 
6965
		#如果執行sql語法錯誤
6966
		if($queryResult["status"]=="false"){
6967
 
6968
			#設置執行失敗的識別
6969
			$result["status"]="false";
6970
 
6971
			#設置執行錯誤資訊
6972
			$result["error"]=$queryResult;
6973
 
6974
			#回傳結果
6975
			return $result;
6976
 
6977
			}#if end
6978
 
6979
		#執行到這邊代表執行無誤
6980
 
6981
		#設置執行失敗的識別
6982
		$result["status"]="true";
6983
 
6984
		#回傳結果
6985
		return $result;
6986
 
6987
		}#function eraseIndexKey end
6988
 
6989
	/*
43 liveuser 6990
	#函式說明:
1 liveuser 6991
	#移除資料表的欄位
43 liveuser 6992
	#回傳結果:
1 liveuser 6993
	#$result["status"],若成功則爲"true",失敗則爲,"false"
6994
	#$result["error"],錯誤訊息.
6995
	#$result["function"],當前執行的函數名稱.
43 liveuser 6996
	#必填參數:
1 liveuser 6997
	#$conf["dbAddress"],字串,爲mysql-Server的位置.
6998
	$conf["dbAddress"]=$dbAddress;
6999
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號.
7000
	$conf["dbAccount"]=$dbAccount;
7001
	#$conf["selectedDataBaseName"],字串,爲目標資料表所屬的資料庫.
7002
	$conf["selectedDataBaseName"]="";
7003
	#$conf["selectedDataTableName"],字串,爲目標資料表所屬的資料庫.
7004
	$conf["selectedDataTableName"]="";
7005
	#$conf["removedColumnName"],字串,要移除的欄位名稱.
7006
	$conf["removedColumnName"]="";
43 liveuser 7007
	#可省略參數: 
1 liveuser 7008
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
7009
	#$conf["dbPassword"]=$dbPassword;
7010
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
7011
	#$conf["dbPort"]="3306";
185 liveuser 7012
	#參考資料:
7013
	#無.
43 liveuser 7014
	#備註:
7015
	#無.
1 liveuser 7016
	*/
7017
	public static function dropColumn($conf){
7018
 
7019
		#初始化要回傳的內容
7020
		$result=array();
7021
 
7022
		#取得當前執行的函數名稱
7023
		$result["function"]=__FUNCTION__;
7024
 
7025
		#如果 $conf 不為陣列
7026
		if(gettype($conf)!="array"){
7027
 
7028
			#設置執行失敗
7029
			$result["status"]="false";
7030
 
7031
			#設置執行錯誤訊息
7032
			$result["error"][]="\$conf變數須為陣列形態";
7033
 
7034
			#如果傳入的參數為 null
7035
			if($conf==null){
7036
 
7037
				#設置執行錯誤訊息
7038
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7039
 
7040
				}#if end
7041
 
7042
			#回傳結果
7043
			return $result;
7044
 
7045
			}#if end
7046
 
43 liveuser 7047
		#函式說明:
1 liveuser 7048
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 7049
		#回傳結果:
1 liveuser 7050
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7051
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7052
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 7053
		#必填參數:
1 liveuser 7054
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
7055
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName","removedColumnName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 7056
		#可省略參數:
1 liveuser 7057
		$conf["variableType"]=array("string","string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
7058
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
7059
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
7060
		unset($conf["variableCheck"]["isexistMuti"]);
7061
 
7062
		#如果檢查失敗
7063
		if($checkResult["status"]=="false"){
7064
 
7065
			#設置執行失敗的訊息
7066
			$result["status"]="false";
7067
 
7068
			#設置錯誤訊息
7069
			$result["error"]=$checkResult;
7070
 
7071
			#回傳結果
7072
			return $result;
7073
 
7074
			}#if end
7075
 
7076
		#如果檢查不通過
7077
		if($checkResult["passed"]=="false"){
7078
 
7079
			#設置執行失敗的訊息
7080
			$result["status"]="false";
7081
 
7082
			#設置錯誤訊息
7083
			$result["error"]=$checkResult;
7084
 
7085
			#回傳結果
7086
			return $result;
7087
 
7088
			}#if end
7089
 
43 liveuser 7090
		#函式說明:
1 liveuser 7091
		#取得資料表所有欄位的詳細資訊
7092
		#回傳的內容:
7093
		#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
7094
		#$result["error"],錯誤訊息陣列
7095
		#$result["sql"],執行的sql語法
7096
		#$result["oriInput"],原始的資料表欄位資訊
7097
		#$result["everyLine"],逐行的欄位資訊
7098
		#$result["tableName"],當前查詢的資料表名稱
7099
		#$result["engine"],資料表使用的儲存引擎
7100
		#$result["charset"],資料表預設的編碼
7101
		#$result["columnName"][$i],各欄位的名稱陣列,$i爲0開始的數字,也可以使用欄位的名稱。
7102
		#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲0開始的數字,也可以使用欄位的名稱。
7103
		#$result["columnNotNull"][$i],各欄位是否可以不爲null,"true"爲可以不爲null;"false"爲可以爲"null",$i爲0開始的數字,也可以使用欄位的名稱。
7104
		#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲0開始的數字,也可以使用欄位的名稱。
7105
		#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲0開始的數字,也可以使用欄位的名稱。
7106
		#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲0開始的數字,也可以使用欄位的名稱。
7107
		#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲0開始的數字,也可以使用欄位的名稱。
7108
		#$result["columnCollate"][$i],各欄位使用的Collate,$i爲0開始的數字,也可以使用欄位的名稱。
7109
		#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
7110
		#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
7111
		#$result["keyConstraintName"][$j],該資料表用於識別索引鍵的CONSTRAINT名稱陣列,$j爲0開始的數字,也可以使用欄位的名稱。
7112
		#$result["primaryKey"],該資料表的主鍵
7113
		#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
7114
		#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲0開始的數字,也可以使用欄位的名稱。
7115
		#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列,$k爲0開始的數字,也可以使用欄位的名稱。
7116
		#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲0開始的數字
7117
		#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲0開始的數字
7118
		#$result["columnOnUpdateAction"][$i],當參照的欄位資料更新時,會怎麼同步,$i爲0開始的數字,"沒有指定"為沒有設定
7119
		#$result["columnOnDeleteAction"][$i],當參照的欄位資料移除時,會怎麼同步,$i爲0開始的數字,"沒有指定"為沒有設定
43 liveuser 7120
		#必填參數:
1 liveuser 7121
		$conf["db"]["getTableColumnDetailInfo"]["dbAddress"]=$conf["dbAddress"];#資料庫的網路位置
7122
		$conf["db"]["getTableColumnDetailInfo"]["dbAccount"]=$conf["dbAccount"];#連線到資料庫要用的帳號
7123
		$conf["db"]["getTableColumnDetailInfo"]["selectedDataBase"]=$conf["selectedDataBaseName"];#連線到資料庫要選擇的資料庫
7124
		$conf["db"]["getTableColumnDetailInfo"]["selectedDataTable"]=$conf["selectedDataTableName"];#連線到資料庫要檢視的資料表
43 liveuser 7125
		#可省略參數:
1 liveuser 7126
 
7127
		#如果 $conf["dbPassword"] 有設置
7128
		if(isset($conf["dbPassword"])){
7129
 
7130
			$conf["db"]["getTableColumnDetailInfo"]["dbPassword"]=$conf["dbPassword"];#連線到資料庫要用的密碼
7131
 
7132
			}#if end
7133
 
7134
		#如果有設定 $conf["dbPort"]	
7135
		if(isset($conf["dbPort"])){
7136
 
7137
			#設定 $conf["dbPort"]
7138
			$conf["db"]["getTableColumnDetailInfo"]["dbPort"]=$conf["dbPort"];
7139
 
7140
			}#if end	
7141
 
7142
		$tableDetail=db::getTableColumnDetailInfo($conf["db"]["getTableColumnDetailInfo"]);
7143
		unset($conf["db"]["getTableColumnDetailInfo"]);
7144
 
7145
		#如果取得資料表結構詳細資料失敗
7146
		if($tableDetail["status"]=="false"){
7147
 
7148
			#設置執行失敗的訊息
7149
			$result["status"]="false";
7150
 
7151
			#設置錯誤訊息
7152
			$result["error"]=$tableDetail;
7153
 
7154
			#回傳結果
7155
			return $result;
7156
 
7157
			}#if end
7158
 
7159
		#var_dump($tableDetail["foreignKey"]);
7160
 
7161
		#判斷該欄位是否爲 foreign key
7162
		if(isset($tableDetail["foreignKey"]["columnName"][$conf["removedColumnName"]])){
7163
 
7164
			#代表該欄位等於 foreign key 
7165
 
7166
			#先移除foreign key...
43 liveuser 7167
			#函式說明:
1 liveuser 7168
			#移除資料表單1欄位的外鍵
43 liveuser 7169
			#回傳結果:
1 liveuser 7170
			#$result["status"],"true",代表執行成功;"false"代表執行失敗
7171
			#$result["error"],錯誤訊息陣列
43 liveuser 7172
			#必填參數:
1 liveuser 7173
			$conf["db"]["eraseForeignKey"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
7174
			$conf["db"]["eraseForeignKey"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
7175
			$conf["db"]["eraseForeignKey"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
7176
			$conf["db"]["eraseForeignKey"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
7177
			$conf["db"]["eraseForeignKey"]["erasedForeignKeyColumnConstraintName"]=$tableDetail["foreignKey"]["constraintName"][$conf["removedColumnName"]];#要移除外鍵欄位的CONSTRAINT名稱
43 liveuser 7178
			#可省略參數: 
1 liveuser 7179
 
7180
			#如果 $conf["dbPassword"] 有設置
7181
			if(isset($conf["dbPassword"])){
7182
 
7183
				$conf["db"]["eraseForeignKey"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
7184
 
7185
				}#if end
7186
 
7187
			#如果有設定 $conf["dbPort"]	
7188
			if(isset($conf["dbPort"])){
7189
 
7190
				#設定 $conf["dbPort"]
7191
				$conf["db"]["eraseForeignKey"]["dbPort"]=$conf["dbPort"];
7192
 
7193
				}#if end	
7194
 
7195
			$eraseForeignKeyResult=db::eraseForeignKey($conf["db"]["eraseForeignKey"]);
7196
			unset($conf["db"]["eraseForeignKey"]);
7197
 
7198
			#var_dump($eraseForeignKeyResult);
7199
 
7200
			#如果執行失敗
7201
			if($eraseForeignKeyResult["status"]=="false"){
7202
 
7203
				#var_dump($eraseForeignKeyResult);
7204
 
7205
				#設置錯誤識別
7206
				$result["status"]="fasle";
7207
 
7208
				#設置錯誤提示
7209
				$result["error"]=$eraseForeignKeyResult;
7210
 
7211
				#回傳結果
7212
				return $result;
7213
 
7214
				}#if end
7215
 
7216
			}#if end
7217
 
7218
		#如果要移除欄位是index
7219
		if(isset($tableDetail["key"][$conf["removedColumnName"]])){
7220
 
7221
			#移除索引鍵
43 liveuser 7222
			#函式說明:
1 liveuser 7223
			#移除資料表單1欄位的索引鍵
43 liveuser 7224
			#回傳結果:
1 liveuser 7225
			#$result["status"],"true",代表執行成功;"false"代表執行失敗
7226
			#$result["error"],錯誤訊息陣列
43 liveuser 7227
			#必填參數:
1 liveuser 7228
			$conf["db"]["eraseIndexKey"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
7229
			$conf["db"]["eraseIndexKey"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
7230
			$conf["db"]["eraseIndexKey"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
7231
			$conf["db"]["eraseIndexKey"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
7232
			$conf["db"]["eraseIndexKey"]["erasedIndexKeyColumnConstraintName"]=$tableDetail["keyConstraintName"][$conf["removedColumnName"]];#要移除索引鍵欄位的CONSTRAINT名稱
43 liveuser 7233
			#可省略參數: 
1 liveuser 7234
 
7235
			#如果 $conf["dbPassword"] 有設置
7236
			if(isset($conf["dbPassword"])){
7237
 
7238
				$conf["db"]["eraseIndexKey"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
7239
 
7240
				}#if end
7241
 
7242
			#如果有設定 $conf["dbPort"]	
7243
			if(isset($conf["dbPort"])){
7244
 
7245
				#設定 $conf["dbPort"]
7246
				$conf["db"]["eraseIndexKey"]["dbPort"]=$conf["dbPort"];
7247
 
7248
				}#if end
7249
 
7250
			$eraseIndexKeyResult=db::eraseIndexKey($conf["db"]["eraseIndexKey"]);
7251
			unset($conf["db"]["eraseIndexKey"]);
7252
 
7253
			#如果執行失敗
7254
			if($eraseIndexKeyResult["status"]=="false"){
7255
 
7256
				#var_dump($eraseIndexKeyResult);
7257
 
7258
				#設置錯誤識別
7259
				$result["status"]="fasle";
7260
 
7261
				#設置錯誤提示
7262
				$result["error"]=$eraseIndexKeyResult;
7263
 
7264
				#回傳結果
7265
				return $result;
7266
 
7267
				}#if end
7268
 
7269
			}#if end		
7270
 
7271
		#組合sql語言
7272
		$sql="alter table ".$conf["selectedDataBaseName"].".".$conf["selectedDataTableName"]." drop `".$conf["removedColumnName"]."`;";
7273
 
43 liveuser 7274
		#函式說明:
1 liveuser 7275
		#執行mysql指令
43 liveuser 7276
		#回傳結果::
1 liveuser 7277
		#$result["status"],"true"為執行成功;"false"為執行失敗。
7278
		#$result["error"],錯誤訊息的陣列
7279
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
7280
		#查詢號的解果,需要解析。
43 liveuser 7281
		#必填參數:
1 liveuser 7282
		$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
7283
		$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
7284
		$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
43 liveuser 7285
		#可省略參數: 
1 liveuser 7286
 
7287
		#如果有設定連線密碼
7288
		if(isset($conf["dbPassword"])){
7289
 
7290
			#就套用密碼
7291
			$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
7292
 
7293
			}#if end
7294
 
7295
		#如果有設定 $conf["dbPort"]	
7296
		if(isset($conf["dbPort"])){
7297
 
7298
			#設定 $conf["dbPort"]
7299
			$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
7300
 
7301
			}#if end
7302
 
7303
		$queryResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
7304
		unset($conf["db"]["execMysqlQuery"]);
7305
 
7306
		#如果執行失敗
7307
		if($queryResult["status"]=="false"){
7308
 
7309
			#設置執行失敗
7310
			$result["status"]="false";
7311
 
7312
			#取得錯誤訊息
7313
			$result["error"]=$queryResult;
7314
 
7315
			#回傳結果
7316
			return $result;
7317
 
7318
			}#if end
7319
 
7320
		#設置執行成功
7321
		$result["status"]="true";
7322
 
7323
		#回傳結果
7324
		return $result;
7325
 
7326
		}#function dropColumn end
7327
 
7328
	/*
43 liveuser 7329
	#函式說明:
1 liveuser 7330
	#清空資料表儲存的資料
43 liveuser 7331
	#回傳結果::
1 liveuser 7332
	#$result["status"],執行成功與否,"true"代表執行成功;"fasle"代表執行失敗
7333
	#$result["error"],錯誤訊息
7334
	#$result["function"],當前執行的涵式.
43 liveuser 7335
	#必填參數:
1 liveuser 7336
	$conf["dbAddress"]="字串,爲mysql-Server的位置
185 liveuser 7337
	$conf["dbAddress"]=$dbAddress;
1 liveuser 7338
	$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
7339
	$conf["dbAccount"]=$dbAccount;
7340
	$conf["dbName"]=$dbName;#爲目標資料表所屬的資料庫
7341
	$conf["dtName"]="";#爲要移除的資料表名稱
43 liveuser 7342
	#可省略參數:		
1 liveuser 7343
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
7344
	#$conf["dbPassword"]=$dbPassword;
7345
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
7346
	#$conf["dbPort"]="3306";
43 liveuser 7347
	#參考資料:
1 liveuser 7348
	#https://dev.mysql.com/doc/refman/5.0/en/truncate-table.html
43 liveuser 7349
	#備註:
7350
	#無.
1 liveuser 7351
	*/
7352
	public static function emptyTable($conf){
7353
 
7354
		#初始化要回傳的內容
7355
		$result=array();
7356
 
7357
		#取得當前執行的函數名稱
7358
		$result["function"]=__FUNCTION__;
7359
 
7360
		#如果 $conf 不為陣列
7361
		if(gettype($conf)!="array"){
7362
 
7363
			#設置執行失敗
7364
			$result["status"]="false";
7365
 
7366
			#設置執行錯誤訊息
7367
			$result["error"][]="\$conf變數須為陣列形態";
7368
 
7369
			#如果傳入的參數為 null
7370
			if($conf==null){
7371
 
7372
				#設置執行錯誤訊息
7373
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7374
 
7375
				}#if end
7376
 
7377
			#回傳結果
7378
			return $result;
7379
 
7380
			}#if end
7381
 
43 liveuser 7382
		#函式說明:
1 liveuser 7383
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 7384
		#回傳結果:
1 liveuser 7385
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7386
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7387
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 7388
		#必填參數:
1 liveuser 7389
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
7390
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","dbName","dtName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 7391
		#可省略參數:
1 liveuser 7392
		#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
7393
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
7394
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
7395
		unset($conf["variableCheck"]);
7396
 
7397
		#如果檢查不通過
7398
		if($checkResult["status"]=="false"){
7399
 
7400
			#設置錯誤識別
7401
			$result["status"]="fasle";
7402
 
7403
			#設置錯誤訊息
7404
			$result["error"]=$checkResult;
7405
 
7406
			#回傳結果
7407
			return $result;
7408
 
7409
			}#if end
7410
 
7411
		#如果檢查不通過
7412
		if($checkResult["passed"]=="false"){
7413
 
7414
			#設置錯誤識別
7415
			$result["status"]="fasle";
7416
 
7417
			#設置錯誤訊息
7418
			$result["error"]=$checkResult;
7419
 
7420
			#回傳結果
7421
			return $result;
7422
 
7423
			}#if end
7424
 
7425
		#設定要執行的sql語法
7426
		$sql="TRUNCATE TABLE ".$conf["dbName"].".".$conf["dtName"].";";
7427
 
43 liveuser 7428
		#函式說明:
1 liveuser 7429
		#執行mysql指令
43 liveuser 7430
		#回傳結果::
1 liveuser 7431
		#$result["status"],"true"為執行成功;"false"為執行失敗。
7432
		#$result["error"],錯誤訊息的陣列
7433
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
7434
		#$result["queryString"],mysql查詢的語言
7435
		#查詢號的解果,需要解析。
43 liveuser 7436
		#必填參數:
1 liveuser 7437
		$conf["db.execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
7438
		$conf["db.execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
7439
		$conf["db.execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
43 liveuser 7440
		#可省略參數: 
1 liveuser 7441
 
7442
		#如果 $conf["dbPassword"] 有設置
7443
		if(isset($conf["dbPassword"])){
7444
 
7445
			$conf["db.execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
7446
 
7447
			}#if end
7448
 
7449
		#如果有設定 $conf["dbPort"]	
7450
		if(isset($conf["dbPort"])){
7451
 
7452
			#設定 $conf["dbPort"]
7453
			$conf["db.execMysqlQuery"]["dbPort"]=$conf["dbPort"];
7454
 
7455
			}#if end				
7456
 
7457
		$queryResult=db::execMysqlQuery($conf["db.execMysqlQuery"]);
7458
		unset($conf["db.execMysqlQuery"]);
7459
 
7460
		#如果 $queryResult["status"] 為 "false"
7461
		if($queryResult["status"]=="false"){
7462
 
43 liveuser 7463
			#函式說明:
1 liveuser 7464
			#透過一筆筆將資料表刪除後,重設識別欄位的自動增量欄位起始值為1
43 liveuser 7465
			#回傳結果:
1 liveuser 7466
			#$result["status"],執行是否正常,"true"代表執行正常,"false"代表執行失敗.
7467
			#$result["error"],錯誤訊息.
7468
			#$result["function"],當前執行的函數名稱.
7469
			#$result["sql"],執行的sql語法陣列.
7470
			#必填參數:
7471
			#$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbAddress"],字串,連線到資料庫的位置.
7472
			$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbAddress"]=$conf["dbAddress"];
7473
			#$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbAccount"],字串,連線到資料庫的帳號.
7474
			$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbAccount"]=$conf["dbAccount"];
7475
			#$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbName"],字串,要連線到哪個資料庫.
7476
			$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbName"]=$conf["dbName"];
7477
			#$conf["db.eraseDataInTableThenResetAutoIncrement"]["dtName"],字串,要重設重設識別欄位的自動增量為0的資料表名稱.
7478
			$conf["db.eraseDataInTableThenResetAutoIncrement"]["dtName"]=$conf["dtName"];
7479
			#可省略參數:
7480
 
7481
			#如果 $conf["dbPassword"] 有設置
7482
			if(isset($conf["dbPassword"])){
7483
 
7484
				#$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbPassword"],字串,連線到資料庫的密碼.
7485
				$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbPassword"]=$conf["dbPassword"];
7486
 
7487
				}#if end
7488
 
7489
			#如果有設定 $conf["dbPort"]	
7490
			if(isset($conf["dbPort"])){
7491
 
7492
				#設定 $conf["dbPort"]
7493
				$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbPort"]=$conf["dbPort"];
7494
 
7495
				}#if end	
7496
 
7497
			#參考資料:
7498
			#http://dev.mysql.com/doc/refman/5.0/en/alter-table.html
7499
			#參考語法:
7500
			#ALTER TABLE dbName.dtName AUTO_INCREMENT = 1;
7501
			$eraseDataInTableThenResetAutoIncrementResult=db::eraseDataInTableThenResetAutoIncrement($conf["db.eraseDataInTableThenResetAutoIncrement"]);
7502
			unset($conf["db.eraseDataInTableThenResetAutoIncrement"]);
7503
 
7504
			#如果 透過一筆筆將資料表刪除後,重設識別欄位的自動增量欄位起始值為1 失敗
7505
			if($eraseDataInTableThenResetAutoIncrementResult["status"]=="false"){
7506
 
7507
				#設置錯誤識別
7508
				$result["status"]="false";
7509
 
7510
				#設置錯誤訊息
7511
				$result["error"]=$eraseDataInTableThenResetAutoIncrementResult;
7512
 
7513
				#回傳結果
7514
				return $result;
7515
 
7516
				}#if end
7517
 
7518
			}#if end	
7519
 
7520
		#值行到這邊代表執行成功
7521
		$result["status"]="true";
7522
 
7523
		#回傳結果
7524
		return $result;
7525
 
7526
		}#function emptyTable end
7527
 
7528
	/*
43 liveuser 7529
	#函式說明:
1 liveuser 7530
	#更改資料庫的名稱 
43 liveuser 7531
	#回傳結果::
1 liveuser 7532
	#$result["status"],"true"代表執行成功
7533
	#$result["function"],當前執行的函數名稱.
7534
	#$result["error"],錯誤訊息陣列.
43 liveuser 7535
	#必填參數:
1 liveuser 7536
	#$conf["editedDatabaseName"],爲要更改的資料庫名稱.
7537
	$conf["editedDatabaseName"]=$editedDbName;
7538
	#$conf["newDatabaseName"],新的資料庫名稱
7539
	$conf["newDatabaseName"]="";
7540
	#$conf["dbAccount"],爲用於連入資料庫server時要使用的帳號
7541
	$conf["dbAccount"]=$dbAccount;
7542
	#$conf["dbAddress"],爲資料庫server的位置
7543
	$conf["dbAddress"]=$dbAddress;
7544
	#$conf["fileArgu"],字串,__FILE__的內容.
7545
	$conf["fileArgu"]=__FILE__;
43 liveuser 7546
	#可省略參數:
1 liveuser 7547
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
7548
	#$conf["dbPassword"]=$dbPassword;
7549
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
7550
	#$conf["dbPort"]="3306";
43 liveuser 7551
	#參考資料:
1 liveuser 7552
	#http://stackoverflow.com/questions/1708651/how-can-i-change-case-of-database-name-in-mysql
43 liveuser 7553
	#備註:
7554
	#無.
1 liveuser 7555
	*/
7556
	public static function editDatabaseName($conf){
7557
 
7558
		#初始化要回傳的內容
7559
		$result=array();
7560
 
7561
		#取得當前執行的函數名稱
7562
		$result["function"]=__FUNCTION__;
7563
 
7564
		#如果 $conf 不為陣列
7565
		if(gettype($conf)!="array"){
7566
 
7567
			#設置執行失敗
7568
			$result["status"]="false";
7569
 
7570
			#設置執行錯誤訊息
7571
			$result["error"][]="\$conf變數須為陣列形態";
7572
 
7573
			#如果傳入的參數為 null
7574
			if($conf==null){
7575
 
7576
				#設置執行錯誤訊息
7577
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7578
 
7579
				}#if end
7580
 
7581
			#回傳結果
7582
			return $result;
7583
 
7584
			}#if end
7585
 
43 liveuser 7586
		#函式說明:
1 liveuser 7587
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 7588
		#回傳結果:
1 liveuser 7589
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7590
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7591
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 7592
		#必填參數:
1 liveuser 7593
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
7594
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("fileArgu","editedDatabaseName","newDatabaseName","dbAccount","dbAddress");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 7595
		#可省略參數:
1 liveuser 7596
		#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
7597
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
7598
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
7599
		unset($conf["variableCheck"]["isexistMuti"]);
7600
 
7601
		#如果檢查失敗
7602
		if($checkResult["status"]=="false"){
7603
 
7604
			#設置錯誤識別
7605
			$result["status"]="false";
7606
 
7607
			#設置錯誤訊息
7608
			$result["error"]=$checkResult;
7609
 
7610
			#回傳錯誤訊息
7611
			return $result;
7612
 
7613
			}#if end
7614
 
7615
		#如果檢查不通過
7616
		if($checkResult["passed"]=="false"){
7617
 
7618
			#設置錯誤識別
7619
			$result["status"]="false";
7620
 
7621
			#設置錯誤訊息
7622
			$result["error"]=$checkResult;
7623
 
7624
			#回傳錯誤訊息
7625
			return $result;
7626
 
7627
			}#if end
7628
 
7629
		#檢查要修改名稱的資料庫是否爲系統資料庫
43 liveuser 7630
		#函式說明:
1 liveuser 7631
		#檢查一個數值是否與陣列裏面的元素相同
43 liveuser 7632
		#回傳結果::
1 liveuser 7633
		#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
7634
		#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
7635
		#$result["error"],錯誤訊息
7636
		#$result["function"],當前執行的函數名稱
7637
		#$result["equalVarName"],相等的變數名稱或key.
7638
		#$result["equalVarValue"],相等的變數數值內容.
43 liveuser 7639
		#必填參數:
1 liveuser 7640
		$conf["search"]["getEqualVar"]["conditionElement"]=$conf["editedDatabaseName"];#條件元素,要等於的元素內容。
7641
		$conf["search"]["getEqualVar"]["compareElements"]=array("information_schema","mysql","performance_schema");#要比對的陣列變數內容。
7642
		$searchResult=search::getEqualVar($conf["search"]["getEqualVar"]);
7643
		unset($conf["search"]["getEqualVar"]);
7644
 
7645
		#如果檢查失敗
7646
		if($searchResult["status"]=="false"){
7647
 
7648
			#設置錯誤識別
7649
			$result["status"]="false";
7650
 
7651
			#設置錯誤訊息
7652
			$result["error"]=$searchResult;
7653
 
7654
			#回傳結果
7655
			return $result;
7656
 
7657
			}#if end
7658
 
7659
		#如果要移除的資料庫爲系統資料庫
7660
		if($searchResult["founded"]=="true"){
7661
 
7662
			#設置錯誤識別
7663
			$result["status"]="false";
7664
 
7665
			#設置錯誤訊息
7666
			$result["error"][]="您不能更改系統資料庫";
7667
 
7668
			#回傳結果
7669
			return $result;
7670
 
7671
			}#if end
7672
 
7673
		#如果 $conf["dbPassword"] 不存在
7674
		if(!isset($conf["dbPassword"])){
7675
 
7676
			#設爲空值
7677
			$conf["dbPassword"]="";
7678
 
7679
			}#if end
7680
 
7681
		#反之有設定
7682
		else{
7683
 
7684
			#設定連線用的密碼
7685
			$formatedPassword="--password=".$conf["dbPassword"];
7686
 
7687
			}#else end
7688
 
7689
		#檢查新名字的資料庫是否存在
43 liveuser 7690
		#函式說明:
1 liveuser 7691
		#檢查該資料庫是否存在,結果會回傳一個陣列。
7692
		#回傳結果:
7693
		#$result["status"],執行正常則回傳"true",執行失敗則回傳"false".
7694
		#$result["error"],錯誤訊息
7695
		#$result["exist"],有為"true",無為"false".
7696
		#必填的參數
7697
		$conf["db"]["checkDataBaseExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
7698
		$conf["db"]["checkDataBaseExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
7699
		$conf["db"]["checkDataBaseExists"]["checkDataBaseName"]=$conf["newDatabaseName"];#爲要檢查是否存在的資料庫名稱
43 liveuser 7700
		#可省略參數
1 liveuser 7701
 
7702
		#如果 $conf["dbPassword"] 存在
7703
		if(isset($conf["dbPassword"])){
7704
 
7705
			#設置密碼
7706
			$conf["db"]["checkDataBaseExists"]["dbPassword"]=$conf["dbPassword"];
7707
 
7708
			}#if end
7709
 
7710
		#如果 $conf["dbPort"] 存在
7711
		if(isset($conf["dbPort"])){
7712
 
7713
			#設置密碼
7714
			$conf["db"]["checkDataBaseExists"]["dbPort"]=$conf["dbPort"];
7715
 
7716
			}#if end		
7717
 
7718
		$checkResult=db::checkDataBaseExists($conf["db"]["checkDataBaseExists"]);
7719
		unset($conf["db"]["checkDataBaseExists"]);
7720
 
7721
		#如果 $checkResult["status"] 等於 "false"
7722
		if($checkResult["status"]==="false"){
7723
 
7724
			#設置錯誤識別
7725
			$result["status"]="false";
7726
 
7727
			#設置錯誤訊息
7728
			$result["error"]=$checkResult;
7729
 
7730
			#回傳結果
7731
			return $result;
7732
 
7733
			}#if end
7734
 
7735
		#如果跟現有的資料庫名稱一樣
7736
		if($checkResult["exist"]==="true"){
7737
 
7738
			#設置錯誤訊息
7739
			$result["error"]=$checkResult;
7740
 
7741
			#設置錯誤識別
7742
			$result["status"]="false";
7743
 
7744
			#回傳結果
7745
			return $result;
7746
 
7747
			}#if end
7748
 
7749
		#如果沒有跟現有的資料庫名稱一樣	
7750
		if($checkResult["exist"]==="false"){
7751
 
7752
			#建立新的資料庫
43 liveuser 7753
			#函式說明:
1 liveuser 7754
			#建立資料庫,會回傳一個陣列。
7755
			#回傳結果:
7756
			#$result["status"],若成功則爲"true",失敗則爲"false".
7757
			#$result["error"],錯誤訊息 
43 liveuser 7758
			#必填參數:
1 liveuser 7759
			$conf["db"]["createDatabase"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
7760
			$conf["db"]["createDatabase"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
7761
			$conf["db"]["createDatabase"]["newDatabaseName"]=$conf["newDatabaseName"];#爲要新增的資料庫名稱
43 liveuser 7762
			#可省略參數:
1 liveuser 7763
 
7764
			#如果 $conf["dbPassword"] 存在
7765
			if(isset($conf["dbPassword"])){
7766
 
7767
				#設置密碼
7768
				$conf["db"]["createDatabase"]["dbPassword"]=$conf["dbPassword"];
7769
 
7770
				}#if end
7771
 
7772
			#如果 $conf["dbPort"] 存在
7773
			if(isset($conf["dbPort"])){
7774
 
7775
				#設置密碼
7776
				$conf["db"]["createDatabase"]["dbPort"]=$conf["dbPort"];
7777
 
7778
				}#if end	
7779
 
7780
			$createNewDbResult=db::createDatabase($conf["db"]["createDatabase"]);
7781
			unset($conf["db"]["createDatabase"]);
7782
 
7783
			#如果新資料庫建立失敗
7784
			if($createNewDbResult["status"]=="false"){
7785
 
7786
				#設置錯誤識別
7787
				$result["status"]="false";
7788
 
7789
				#設置錯誤訊息
7790
				$result["error"]=$createNewDbResult;
7791
 
7792
				#回傳結果
7793
				return $result;
7794
 
7795
				}#if end
7796
 
7797
			#將舊的資料庫內容完整複製到新的資料庫
43 liveuser 7798
			#函式說明:
1 liveuser 7799
			#呼叫shell執行系統命令,並取得回傳的內容.
43 liveuser 7800
			#回傳結果:
1 liveuser 7801
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
454 liveuser 7802
			#$result["error"],錯誤訊息陣列.
7803
			#$result["function"],當前執行的函數名稱.
7804
			#$result["argu"],使用的參數.
7805
			#$result["cmd"],執行的指令內容.
7806
			#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
7807
			#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
7808
			#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
7809
			#$result["running"],是否還在執行.
7810
			#$result["pid"],pid.
7811
			#$result["statusCode"],執行結束後的代碼.
7812
			#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
7813
			#必填參數:
7814
			#$conf["command"],字串,要執行的指令.
7815
			$conf["external::callShell"]["command"]="mysqldump";
7816
			#$conf["fileArgu"],字串,變數__FILE__的內容.
1 liveuser 7817
			$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
7818
			#可省略參數:
454 liveuser 7819
			#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
7820
			$conf["external::callShell"]["argu"]=array("-u".$conf["dbAccount"],$formatedPassword,$conf["editedDatabaseName"],"|","mysql","-u".$conf["dbAccount"],$formatedPassword,$conf["newDatabaseName"]);
7821
			#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
7822
			#$conf["arguIsAddr"]=array();
7823
			#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
7824
			#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
7825
			#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
1 liveuser 7826
			#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
7827
			#$conf["enablePrintDescription"]="true";
454 liveuser 7828
			#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
1 liveuser 7829
			#$conf["printDescription"]="";
454 liveuser 7830
			#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
7831
			#$conf["escapeshellarg"]="false";
7832
			#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
7833
			#$conf["thereIsShellVar"]=array();
7834
			#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
7835
			#$conf["username"]="";
7836
			#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
7837
			#$conf["password"]="";
7838
			#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
7839
			#$conf["useScript"]="";
7840
			#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
7841
			#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
7842
			#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
7843
			#$conf["inBackGround"]="";
7844
			#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
7845
			#$conf["getErr"]="false";
7846
			#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
7847
			#$conf["doNotRun"]="false";
1 liveuser 7848
			#參考資料:
454 liveuser 7849
			#exec=>http://php.net/manual/en/function.exec.php
7850
			#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
7851
			#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
7852
			#備註:
7853
			#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
7854
			#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
1 liveuser 7855
			$callShell=external::callShell($conf["external::callShell"]);
7856
			unset($conf["external::callShell"]);
7857
 
7858
			#若執行shell失敗
7859
			if($callShell["status"]=="false"){
7860
 
7861
				#設置錯誤識別
7862
				$result["status"]="false";
7863
 
7864
				#設置錯誤訊息
7865
				$result["error"]=$callShell;
7866
 
7867
				#回傳結果
7868
				return $result;					
7869
 
7870
				}#if end
7871
 
7872
			#將舊的資料庫丟棄
7873
			#函式說明:
7874
			#移除資料庫,會回傳一個陣列。
7875
			#回傳結果:
7876
			#$result["status"],若成功則爲0,失敗則爲1。
7877
			#$result["error"],錯誤訊息
43 liveuser 7878
			#必填參數:
1 liveuser 7879
			$conf["db"]["dropDatabase"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
7880
			$conf["db"]["dropDatabase"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
7881
			$conf["db"]["dropDatabase"]["dropedDatabaseName"]=$conf["editedDatabaseName"];#爲要移除的資料庫名稱
43 liveuser 7882
			#可省略參數:		
1 liveuser 7883
 
7884
			#如果 $conf["dbPassword"] 存在
7885
			if(isset($conf["dbPassword"])){
7886
 
7887
				#設置密碼
7888
				$conf["db"]["dropDatabase"]["dbPassword"]=$conf["dbPassword"];
7889
 
7890
				}#if end
7891
 
7892
			#如果 $conf["dbPort"] 存在
7893
			if(isset($conf["dbPort"])){
7894
 
7895
				#設置密碼
7896
				$conf["db"]["dropDatabase"]["dbPort"]=$conf["dbPort"];
7897
 
7898
				}#if end	
7899
 
7900
			$dropDbResult=db::dropDatabase($conf["db"]["dropDatabase"]);
7901
			unset($conf["db"]["dropDatabase"]);
7902
 
7903
			#如果舊資料庫丟棄失敗
7904
			if($dropDbResult["status"]=="false"){
7905
 
7906
				#設置錯誤識別
7907
				$result["status"]="false";
7908
 
7909
				#設置錯誤訊息
7910
				$result["error"][]="舊名稱資料庫丟棄失敗";
7911
 
7912
				#回傳結果
7913
				return $result;
7914
 
7915
				}#if end				
7916
 
7917
			}#if end
7918
 
7919
		#執行到這邊代表執行正確
7920
		$result["status"]="true";
7921
 
7922
		#回傳結果
7923
		return $result;
7924
 
7925
		}#function editDatabaseName
7926
 
7927
	/*
43 liveuser 7928
	#函式說明:
1 liveuser 7929
	#更改資料表的名稱. 
43 liveuser 7930
	#回傳結果:
1 liveuser 7931
	#$result["status"],"true"代表執行成功;若失敗會回傳錯誤訊息.
7932
	#$resuly["function"],當前執行的函數名稱.
7933
	#$result["error"],錯誤訊息.
7934
	#$result["sql"],執行的sql字串.
43 liveuser 7935
	#必填參數:
1 liveuser 7936
	#$conf["editedDataBaseName"],爲要更改的資料表所屬的資料庫名稱.
7937
	$conf["editedDataBaseName"]="";
7938
	#$conf["editedDataTableName"],爲要更改的資料表原始名稱.
7939
	$conf["editedDataTableName"]="";
7940
	#$conf["newDataTableName"],新的資料庫名稱.
7941
	$conf["newDataTableName"]="";
7942
	#$conf["dbAccount"],爲用於連入資料庫server時要使用的帳號.
7943
	$conf["dbAccount"]=$dbAccount;
7944
	#conf["dbAddress"],爲資料庫server的位置.
7945
	$conf["dbAddress"]=$dbAddress;
43 liveuser 7946
	#可省略參數:
1 liveuser 7947
	#$conf["dbPassword"],爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
7948
	#$conf["dbPassword"]=$dbPassword;
7949
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
7950
	#$conf["dbPort"]="3306";
185 liveuser 7951
	#參考資料:
7952
	#無.
43 liveuser 7953
	#備註:
7954
	#無.
1 liveuser 7955
	*/
7956
	public static function editDataTableName($conf){
7957
 
7958
		#初始化要回傳的內容
7959
		$result=array();
7960
 
7961
		#取得當前執行的函數名稱
7962
		$result["function"]=__FUNCTION__;
7963
 
7964
		#如果 $conf 不為陣列
7965
		if(gettype($conf)!="array"){
7966
 
7967
			#設置執行失敗
7968
			$result["status"]="false";
7969
 
7970
			#設置執行錯誤訊息
7971
			$result["error"][]="\$conf變數須為陣列形態";
7972
 
7973
			#如果傳入的參數為 null
7974
			if($conf==null){
7975
 
7976
				#設置執行錯誤訊息
7977
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
7978
 
7979
				}#if end
7980
 
7981
			#回傳結果
7982
			return $result;
7983
 
7984
			}#if end
7985
 
43 liveuser 7986
		#函式說明:
1 liveuser 7987
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 7988
		#回傳結果:
1 liveuser 7989
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
7990
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
7991
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 7992
		#必填參數:
1 liveuser 7993
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
7994
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("editedDataBaseName","editedDataTableName","newDataTableName","dbAccount","dbAddress");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 7995
		#可省略參數:
1 liveuser 7996
		$conf["variableType"]=array("string","string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
7997
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
7998
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
7999
		unset($conf["variableCheck"]["isexistMuti"]);
8000
 
8001
		#如果 $checkResult["passed"]等於"false".
8002
		if($checkResult["passed"]=="false"){
8003
 
8004
			#代表參數有錯
8005
 
8006
			#設置錯誤識別
8007
			$result["status"]="false";
8008
 
8009
			#設置錯誤訊息
8010
			$result["error"]=$checkResult;
8011
 
8012
			#回傳結果
8013
			return $result;
8014
 
8015
			}#if end
8016
 
8017
		#設定要執行的sql語法
8018
		$sql="rename table ".$conf["editedDataBaseName"].".".$conf["editedDataTableName"]." to ".$conf["editedDataBaseName"].".".$conf["newDataTableName"].";";
8019
 
43 liveuser 8020
		#函式說明:
1 liveuser 8021
		#執行mysql指令
43 liveuser 8022
		#回傳結果::
1 liveuser 8023
		#$result["status"],"true"為執行成功;"false"為執行失敗。
8024
		#$result["error"],錯誤訊息的陣列
8025
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
8026
		#$result["queryString"],mysql查詢的語言
8027
		#查詢號的解果,需要解析。
43 liveuser 8028
		#必填參數:
1 liveuser 8029
		$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
8030
		$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
8031
		$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
43 liveuser 8032
		#可省略參數: 
1 liveuser 8033
 
8034
		#如果 $conf["dbPassword"] 有設定
8035
		if(isset($conf["dbPassword"])){
8036
 
8037
			$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
8038
 
8039
			}#if end
8040
 
8041
		#如果 $conf["dbPort"] 有設定
8042
		if(isset($conf["dbPort"])){
8043
 
8044
			$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port.
8045
 
8046
			}#if end			
8047
 
8048
		$db["execMysqlQuery"]=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
8049
		unset($conf["db"]["execMysqlQuery"]);
8050
 
8051
		#如果 $db["execMysqlQuery"]["status"] 等於 "false".
8052
		if($db["execMysqlQuery"]["status"]=="false"){
8053
 
8054
			#設置執行錯誤的識別
8055
			$result["status"]="false";
8056
 
8057
			#設置錯誤訊息
8058
			$result["error"]=$db["execMysqlQuery"]["error"];
8059
 
8060
			#回傳結果
8061
			return $result;
8062
 
8063
			}#if end
8064
 
8065
		#取得執行的sql語法
8066
		$result["sql"]=$db["execMysqlQuery"]["queryString"];
8067
 
8068
		#執行到這邊代表執行成功
8069
		$result["status"]="true";
8070
 
8071
		#回傳結果
8072
		return $result;
8073
 
8074
		}#function editDataTableName end
8075
 
8076
	/*
8077
	#函式說明:
8078
	#移除資料庫,會回傳一個陣列。
8079
	#回傳結果:
8080
	#$result["status"],若成功則爲"true",失敗則爲,"false"
8081
	#$result["error"],錯誤訊息.
8082
	#$result["function"],當前執行的函數名稱.
43 liveuser 8083
	#必填參數:
1 liveuser 8084
	$conf["dbAddress"]=$dbAddress;#爲mysql-Server的位置
8085
	$conf["dbAccount"]=$dbAccount;#爲用於連入mysql-Server時要使用的帳號
8086
	$conf["dropedDatabaseName"]=$dbName;#爲要移除的資料庫名稱
43 liveuser 8087
	#可省略參數:		
1 liveuser 8088
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
8089
	#$conf["dbPassword"]=$dbPassword;
8090
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
8091
	#$conf["dbPort"]="3306";
185 liveuser 8092
	#參考資料:
8093
	#無.
43 liveuser 8094
	#備註:
8095
	#無.
1 liveuser 8096
	*/
8097
	public static function dropDatabase($conf){
8098
 
8099
		#初始化要回傳的內容
8100
		$result=array();
8101
 
8102
		#取得當前執行的函數名稱
8103
		$result["function"]=__FUNCTION__;
8104
 
8105
		#如果 $conf 不為陣列
8106
		if(gettype($conf)!="array"){
8107
 
8108
			#設置執行失敗
8109
			$result["status"]="false";
8110
 
8111
			#設置執行錯誤訊息
8112
			$result["error"][]="\$conf變數須為陣列形態";
8113
 
8114
			#如果傳入的參數為 null
8115
			if($conf==null){
8116
 
8117
				#設置執行錯誤訊息
8118
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
8119
 
8120
				}#if end
8121
 
8122
			#回傳結果
8123
			return $result;
8124
 
8125
			}#if end
8126
 
43 liveuser 8127
		#函式說明:
1 liveuser 8128
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 8129
		#回傳結果:
1 liveuser 8130
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8131
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8132
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 8133
		#必填參數:
1 liveuser 8134
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
8135
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","dropedDatabaseName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 8136
		#可省略參數:
1 liveuser 8137
		$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
8138
		#$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
8139
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
8140
		unset($conf["variableCheck"]["isexistMuti"]);
8141
 
8142
		#如果 $checkResult["passed"] 等於 "fasle"
8143
		if($checkResult["passed"]=="false"){
8144
 
8145
			#設置錯誤識別
8146
			$result["status"]="false";
8147
 
8148
			#設置錯誤訊息
8149
			$result["error"]=$checkResult;
8150
 
8151
			#回傳結果
8152
			return $result;
8153
 
8154
			}#if end
8155
 
8156
		#檢查要移除的資料庫爲系統資料庫
43 liveuser 8157
		#函式說明:
1 liveuser 8158
		#檢查一個數值是否與陣列裏面的元素相同
43 liveuser 8159
		#回傳結果::
1 liveuser 8160
		#$result["status"],"true"表示有找到相同的,"false"表示沒有找到相同的。
8161
		#$result["equalVarName"],相等的變數內容。
8162
		#$result["equalVarPosition"],相同的元素內容其位置爲該陣列元素的第幾個位置。
43 liveuser 8163
		#必填參數:
1 liveuser 8164
		$conf["search"]["getEqualVar"]["conditionElement"]=$conf["dropedDatabaseName"];#條件元素,要等於的元素內容。
8165
		$conf["search"]["getEqualVar"]["compareElements"]=array("information_schema","mysql","performance_schema");#要比對的陣列變數內容。
8166
		$searchResult=search::getEqualVar($conf["search"]["getEqualVar"]);
8167
		unset($conf["search"]["getEqualVar"]);
8168
 
8169
		#如果檢查失敗
8170
		if($searchResult["status"]=="false"){
8171
 
8172
			#設置失敗代碼
8173
			$result["status"]="false";
8174
 
8175
			#設置錯誤訊息
8176
			$result["error"]=$searchResult;
8177
 
8178
			#回傳結果
8179
			return $result;
8180
 
8181
			}#if end
8182
 
8183
		#如果要移除的資料庫爲系統資料庫
8184
		if($searchResult["founded"]=="true"){
8185
 
8186
			#設置失敗代碼
8187
			$result["status"]="false";
8188
 
8189
			#設置錯誤訊息
8190
			$result["error"]="您不能丟棄系統資料庫";
8191
 
8192
			#回傳結果
8193
			return $result;
8194
 
8195
			}#if end
8196
 
8197
		#丟棄資料庫的sql語法
8198
		$sql="DROP DATABASE ".$conf["dropedDatabaseName"];
8199
 
8200
		#執行sql語法
43 liveuser 8201
		#函式說明:
1 liveuser 8202
		#執行mysql指令
43 liveuser 8203
		#回傳結果::
1 liveuser 8204
		#$result["status"],"true"為執行成功;"false"為執行失敗。
8205
		#$result["error"],錯誤訊息的陣列
8206
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
8207
		#$result["queryString"],mysql查詢的語言
8208
		#查詢號的解果,需要解析。
43 liveuser 8209
		#必填參數:
1 liveuser 8210
		$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
8211
		$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
8212
		$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
43 liveuser 8213
		#可省略參數: 
1 liveuser 8214
 
8215
		#如果 $conf["dbPassword"] 有設定
8216
		if(isset($conf["dbPassword"])){
8217
 
8218
			$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
8219
 
8220
			}#if end
8221
 
8222
 
8223
		#如果 $conf["dbPort"] 有設定
8224
		if(isset($conf["dbPort"])){
8225
 
8226
			$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表不使用密碼
8227
 
8228
			}#if end
8229
 
8230
		$db["execMysqlQuery"]=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
8231
		unset($conf["db"]["execMysqlQuery"]);
8232
 
8233
		#如果 $db["execMysqlQuery"]["status"] 等於 "false"
8234
		if($db["execMysqlQuery"]["status"]=="false"){
8235
 
8236
			#設置錯誤識別
8237
			$result["status"]="false";
8238
 
8239
			#設置錯誤訊息
8240
			$result["error"]=$db["execMysqlQuery"];
8241
 
8242
			#回傳結果
8243
			return $result;
8244
 
8245
			}#if end
8246
 
8247
		#執行到這邊代表執行正常
8248
		$result["status"]="true";
8249
 
8250
		#回傳結果
8251
		return $result;
8252
 
8253
		}#function dropDatabase end
8254
 
8255
	/*
43 liveuser 8256
	#函式說明:
1 liveuser 8257
	#備份資料庫
43 liveuser 8258
	#回傳結果::
1 liveuser 8259
	#$result["status"],"true"代表執行正常,"false"代表執行有誤.
8260
	#$result["error"],錯誤訊息陣列.
8261
	#$result["sqlAddress"],sql檔案的位置.
8262
	#$result["function"],當前執行的函數名稱
43 liveuser 8263
	#必填參數:
1 liveuser 8264
	#$conf["backedDatabaseName"],字串.
8265
	$conf["backedDatabaseName"]=$dbName;#爲要備份的資料庫名稱.
8266
	#$conf["dbAddress"],字串,資料庫的位置.
8267
	$conf["dbAddress"]=$dbAddress;
8268
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號.
8269
	$conf["dbAccount"]=$dbAccount;
8270
	#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
8271
	$conf["fileArgu"]=__FILE__;
43 liveuser 8272
	#可省略參數:
1 liveuser 8273
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
8274
	#$conf["dbPassword"]=$dbPassword;
8275
	#$conf["storePlace"],字串,要將輸出檔案儲存到哪邊,預設爲當前目錄.
8276
	#$conf["storePlace"]="";
8277
	#$conf["exportFileName"],字串,要輸出的檔案名稱,預設爲其export
8278
	#$conf["exportFileName"]="export";
126 liveuser 8279
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設不使用.
1 liveuser 8280
	#$conf["dbPort"]="3306";
185 liveuser 8281
	#參考資料:
8282
	#無.
43 liveuser 8283
	#備註:
8284
	#無.
1 liveuser 8285
	*/
8286
	public static function backupDatabase($conf){
8287
 
8288
		#原始語法
141 liveuser 8289
		# mysqldump --column-statistics=0 -u account --password=Password -Pport --default-character-set=utf8 --events --routines --single-transaction --skip-lock-tables --quick databaseName > "all.sql"
1 liveuser 8290
 
8291
		#初始化要回傳的變數
8292
		$result=array();
8293
 
8294
		#紀錄當前執行的函數名稱
8295
		$result["function"]=__FUNCTION__;
8296
 
8297
		#如果 $conf 不為陣列
8298
		if(gettype($conf)!="array"){
8299
 
8300
			#設置執行失敗
8301
			$result["status"]="false";
8302
 
8303
			#設置執行錯誤訊息
8304
			$result["error"][]="\$conf變數須為陣列形態";
8305
 
8306
			#如果傳入的參數為 null
8307
			if($conf==null){
8308
 
8309
				#設置執行錯誤訊息
8310
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
8311
 
8312
				}#if end
8313
 
8314
			#回傳結果
8315
			return $result;
8316
 
8317
			}#if end
8318
 
43 liveuser 8319
		#函式說明:
1 liveuser 8320
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 8321
		#回傳結果:
1 liveuser 8322
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8323
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8324
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 8325
		#必填參數:
1 liveuser 8326
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
8327
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("fileArgu","backedDatabaseName","dbAccount","dbAddress");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 8328
		#可省略參數:
1 liveuser 8329
		$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
8330
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
8331
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
8332
		unset($conf["variableCheck"]["isexistMuti"]);
8333
 
8334
		#如果檢查失敗
8335
		if($checkResult["status"]=="false"){
8336
 
8337
			#設置錯誤識別
8338
			$result["status"]="false";
8339
 
8340
			#設置錯誤訊息
8341
			$result["error"]=$checkResult;
8342
 
8343
			#回傳錯誤訊息
8344
			return $result;
8345
 
8346
			}#if end
8347
 
8348
		#如果檢查不通過
8349
		if($checkResult["passed"]=="false"){
8350
 
8351
			#設置錯誤識別
8352
			$result["status"]="false";
8353
 
8354
			#設置錯誤訊息
8355
			$result["error"]=$checkResult;
8356
 
8357
			#回傳錯誤訊息
8358
			return $result;
8359
 
8360
			}#if end
8361
 
139 liveuser 8362
		#檢查要備份的資料庫是否爲系統資料庫
43 liveuser 8363
		#函式說明:
1 liveuser 8364
		#檢查一個數值是否與陣列裏面的元素相同
43 liveuser 8365
		#回傳結果::
1 liveuser 8366
		#$result["status"],"true"表示有找到相同的,"false"表示沒有找到相同的。
8367
		#$result["error"],錯誤訊息
8368
		#$result["equalVarName"],相等的變數內容。
8369
		#$result["equalVarPosition"],相同的元素內容其位置爲該陣列元素的第幾個位置。
43 liveuser 8370
		#必填參數:
1 liveuser 8371
		$conf["search"]["getEqualVar"]["conditionElement"]=$conf["backedDatabaseName"];#條件元素,要等於的元素內容。
8372
		$conf["search"]["getEqualVar"]["compareElements"]=array("information_schema","mysql","performance_schema");#要比對的陣列變數內容。
8373
		$searchResult=search::getEqualVar($conf["search"]["getEqualVar"]);
8374
		unset($conf["search"]["getEqualVar"]);
8375
 
139 liveuser 8376
		#如果檢查失敗
1 liveuser 8377
		if($searchResult["status"]=="false"){
8378
 
8379
			#設置錯誤識別
8380
			$result["status"]="false";
8381
 
8382
			#設置錯誤訊息
8383
			$result["error"]=$searchResult;
8384
 
8385
			#回傳結果
8386
			return $result;
8387
 
8388
			}#if end
8389
 
139 liveuser 8390
		#如果要備份的資料庫爲系統資料庫
1 liveuser 8391
		if($searchResult["founded"]=="true"){
8392
 
8393
			#設置錯誤識別
8394
			$result["status"]="false";
8395
 
8396
			#設置錯誤訊息
8397
			$result["error"]="您不能備份系統資料庫";
8398
 
8399
			#回傳結果
8400
			return $result;
8401
 
8402
			}#if end
8403
 
8404
		#初始化連線的密碼
8405
		$dbPassword="";
8406
 
8407
		#如果 $conf["dbPassword"] 有設置
8408
		if(isset($conf["dbPassword"])){
8409
 
8410
			#令存密碼
8411
			$dbPassword=$conf["dbPassword"];
8412
 
8413
			#設置其連線密碼
126 liveuser 8414
			$conf["dbPassword"]="-p".$conf["dbPassword"];
1 liveuser 8415
 
8416
			}#if end
8417
 
8418
		#反之
8419
		else{
8420
 
8421
			#設爲空值
8422
			$conf["dbPassword"]="";
8423
 
8424
			}#else end
8425
 
8426
		#如果 $conf["storePlace"] 沒有設置
8427
		if(!isset($conf["storePlace"])){
8428
 
8429
			#將其設爲空值
8430
			$conf["storePlace"]="";
8431
 
8432
			}#if end
8433
 
486 liveuser 8434
		#反之有設定且結尾不為 "/"
8435
		else if($conf["storePlace"][strlen($conf["storePlace"])-1]!=="/"){
1 liveuser 8436
 
8437
			#在其路徑後方加上 /
8438
			$conf["storePlace"]=$conf["storePlace"]."/";
8439
 
486 liveuser 8440
			}#if end
1 liveuser 8441
 
8442
		#如果 $conf["exportFileName"] 沒有設置
8443
		if(!isset($conf["exportFileName"])){
8444
 
8445
			#設置預設名稱
8446
			$conf["exportFileName"]="export.sql";
8447
 
8448
			}#if end
8449
 
8450
		#反之有設定
8451
		else{
8452
 
8453
			#名稱結尾加上 .sql
8454
			$conf["exportFileName"]=$conf["exportFileName"].".sql";
8455
 
8456
			}#else end
8457
 
8458
		#檢查資料庫是否存在
43 liveuser 8459
		#函式說明:
1 liveuser 8460
		#檢查該資料庫是否存在,結果會回傳一個陣列。
8461
		#回傳結果:
8462
		#$result["status"],設置執行錯誤.
8463
		#$result["error"],錯誤訊息.
8464
		#$result["exist"],有為"true",無為"false".
8465
		#$result["function"],當前執行的函數名稱.
8466
		#必填的參數
8467
		$conf["db::checkDataBaseExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
8468
		$conf["db::checkDataBaseExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
8469
		$conf["db::checkDataBaseExists"]["checkDataBaseName"]=$conf["backedDatabaseName"];#爲要檢查是否存在的資料庫名稱
43 liveuser 8470
		#可省略參數
1 liveuser 8471
 
8472
		#如果密碼不為""
8473
		if($dbPassword!=""){
8474
 
8475
			$conf["db::checkDataBaseExists"]["dbPassword"]=$dbPassword;#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
8476
 
8477
			}#if end
8478
 
8479
		#如果有設置 $conf["dnPort"]
8480
		if(isset($conf["dbPort"])){
8481
 
126 liveuser 8482
			$conf["db::checkDataBaseExists"]["dbPort"]=$conf["dbPort"];
1 liveuser 8483
 
8484
			}#if end
8485
 
8486
		$checkDataBaseExists=db::checkDataBaseExists($conf["db::checkDataBaseExists"]);
8487
		unset($conf["db::checkDataBaseExists"]);
8488
 
8489
		#如果檢查資料庫是否存在失敗
8490
		if($checkDataBaseExists["status"]=="false"){
8491
 
8492
			#設置錯誤識別
8493
			$result["status"]="false";
8494
 
8495
			#設置錯誤訊息
8496
			$result["error"]=$checkDataBaseExists;
8497
 
8498
			#回傳結果
8499
			return $result;
8500
 
8501
			}#if end
8502
 
8503
		#如果資料庫不存在
8504
		if($checkDataBaseExists["exist"]=="false"){
8505
 
8506
			#設置錯誤識別
8507
			$result["status"]="false";
8508
 
8509
			#設置錯誤訊息
8510
			$result["error"]=$checkDataBaseExists;
8511
 
8512
			#回傳結果
8513
			return $result;
8514
 
8515
			}#if end
8516
 
126 liveuser 8517
		#若有設置port
1 liveuser 8518
		if(isset($conf["dbPort"])){
8519
 
126 liveuser 8520
			#指定port
8521
			$port="-P".$conf["dbPort"];
1 liveuser 8522
 
8523
			}#if end
8524
 
126 liveuser 8525
		#反之
8526
		else{
8527
			#設置為空
8528
			$port="";
8529
 
8530
			}#else end
8531
 
141 liveuser 8532
		#透過以下指令判斷是否支援 --column-statistics 參數
8533
		#mysqldump --help | grep "\--column-statistics" | wc -l
8534
		#函式說明:
8535
		#呼叫shell執行系統命令,並取得回傳的內容.
8536
		#回傳結果:
8537
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
8538
		#$result["error"],錯誤訊息陣列.
8539
		#$result["function"],當前執行的函數名稱.
8540
		#$result["argu"],使用的參數.
8541
		#$result["cmd"],執行的指令內容.
8542
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8543
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8544
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8545
		#$result["running"],是否還在執行.
8546
		#$result["pid"],pid.
8547
		#$result["statusCode"],執行結束後的代碼.
8548
		#必填參數:
8549
		#$conf["command"],字串,要執行的指令與.
8550
		$conf["external::callShell"]["command"]="mysqldump";
8551
		#$conf["fileArgu"],字串,變數__FILE__的內容.
8552
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
8553
		#可省略參數:
8554
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
8555
		$conf["external::callShell"]["argu"]=array("--help","|","grep","\--column-statistics","|","wc","-l");
8556
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8557
		#$conf["arguIsAddr"]=array();
145 liveuser 8558
		#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"".
454 liveuser 8559
		#$conf["external::callShell"]["plainArgu"]=array("true","true","true","false","true","true","true");
141 liveuser 8560
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8561
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8562
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
8563
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8564
		#$conf["enablePrintDescription"]="true";
8565
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
8566
		#$conf["printDescription"]="";
8567
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
454 liveuser 8568
		$conf["external::callShell"]["escapeshellarg"]="true";
141 liveuser 8569
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8570
		#$conf["username"]="";
8571
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8572
		#$conf["password"]="";
8573
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8574
		#$conf["useScript"]="";
8575
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8576
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8577
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8578
		#$conf["inBackGround"]="";
8579
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8580
		#$conf["getErr"]="false";
8581
		#備註:
8582
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
8583
		#參考資料:
8584
		#exec=>http://php.net/manual/en/function.exec.php
8585
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8586
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
8587
		$callShell=external::callShell($conf["external::callShell"]);
8588
		unset($conf["external::callShell"]);
8589
 
8590
		#如果執行shell失敗
8591
		if($callShell["status"]==="false"){
8592
 
8593
			#設置錯誤識別
8594
			$result["status"]="false";
8595
 
8596
			#設置錯誤訊息
8597
			$result["error"]=$callShell;
8598
 
8599
			#回傳結果
8600
			return $result;
8601
 
8602
			}#if end
8603
 
8604
		#初始化參數
8605
		$conf["external::callShell"]["argu"]=array();
8606
 
8607
		#如果支援 --column-statistics 參數
8608
		if($callShell["output"][0]==="1"){
8609
 
8610
			#增加參數
8611
			$conf["external::callShell"]["argu"][]="--column-statistics=0";
8612
 
8613
			}#if end
8614
 
126 liveuser 8615
		#輸出資料庫sql檔案		
43 liveuser 8616
		#函式說明:
1 liveuser 8617
		#呼叫shell執行系統命令,並取得回傳的內容.
43 liveuser 8618
		#回傳結果:
1 liveuser 8619
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
126 liveuser 8620
		#$result["error"],錯誤訊息陣列.
8621
		#$result["function"],當前執行的函數名稱.
8622
		#$result["argu"],使用的參數.
8623
		#$result["cmd"],執行的指令內容.
8624
		#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
8625
		#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
8626
		#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
8627
		#$result["running"],是否還在執行.
8628
		#$result["pid"],pid.
8629
		#$result["statusCode"],執行結束後的代碼.
8630
		#必填參數:
8631
		#$conf["command"],字串,要執行的指令與.
8632
		$conf["external::callShell"]["command"]="mysqldump";
8633
		#$conf["fileArgu"],字串,變數__FILE__的內容.
1 liveuser 8634
		$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
8635
		#可省略參數:
126 liveuser 8636
		#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
141 liveuser 8637
		$conf["external::callShell"]["argu"][]="-u";
8638
		$conf["external::callShell"]["argu"][]=$conf["dbAccount"];
8639
		$conf["external::callShell"]["argu"][]=$conf["dbPassword"];
8640
		$conf["external::callShell"]["argu"][]="-h";
8641
		$conf["external::callShell"]["argu"][]=$conf["dbAddress"];
149 liveuser 8642
 
8643
		#如果有指定 port
8644
		if($port!==""){
8645
 
8646
			#設置port
8647
			$conf["external::callShell"]["argu"][]=$port;
8648
 
8649
			}#if end
8650
 
141 liveuser 8651
		$conf["external::callShell"]["argu"][]="--default-character-set=utf8";
8652
		$conf["external::callShell"]["argu"][]="--events";
8653
		$conf["external::callShell"]["argu"][]="--routines";
8654
		$conf["external::callShell"]["argu"][]="--single-transaction";
8655
		$conf["external::callShell"]["argu"][]="--skip-lock-tables";
8656
		$conf["external::callShell"]["argu"][]="--quick";
8657
		$conf["external::callShell"]["argu"][]=$conf["backedDatabaseName"];
8658
		$conf["external::callShell"]["argu"][]=">";
143 liveuser 8659
		$conf["external::callShell"]["argu"][]=$conf["storePlace"].$conf["exportFileName"];
126 liveuser 8660
		#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
8661
		#$conf["arguIsAddr"]=array();
8662
		#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
8663
		#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
8664
		#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
1 liveuser 8665
		#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
8666
		#$conf["enablePrintDescription"]="true";
126 liveuser 8667
		#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
1 liveuser 8668
		#$conf["printDescription"]="";
126 liveuser 8669
		#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
380 liveuser 8670
		$conf["external::callShell"]["escapeshellarg"]="true";
126 liveuser 8671
		#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
8672
		#$conf["username"]="";
8673
		#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
8674
		#$conf["password"]="";
8675
		#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
8676
		#$conf["useScript"]="";
8677
		#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
8678
		#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
8679
		#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
8680
		#$conf["inBackGround"]="";
8681
		#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
8682
		#$conf["getErr"]="false";
8683
		#備註:
8684
		#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
1 liveuser 8685
		#參考資料:
126 liveuser 8686
		#exec=>http://php.net/manual/en/function.exec.php
8687
		#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
8688
		#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
1 liveuser 8689
		$callShell=external::callShell($conf["external::callShell"]);
8690
		unset($conf["external::callShell"]);
126 liveuser 8691
 
1 liveuser 8692
		#如果執行shell失敗
139 liveuser 8693
		if($callShell["status"]==="false"){
1 liveuser 8694
 
8695
			#設置錯誤識別
8696
			$result["status"]="false";
8697
 
8698
			#設置錯誤訊息
8699
			$result["error"]=$callShell;
8700
 
8701
			#回傳結果
8702
			return $result;
8703
 
8704
			}#if end
8705
 
8706
		#設置產生的sql檔案位置
150 liveuser 8707
		$result["sqlAddress"]=$conf["storePlace"].$conf["exportFileName"];
1 liveuser 8708
 
8709
		#設置執行成功
8710
		$result["status"]="true";
8711
 
8712
		#回傳結果
8713
		return $result;
8714
 
8715
		}#function backupDatabase end
8716
 
8717
	/*
8718
	#函式說明:
8719
	#移除表,會回傳一個陣列。
8720
	#回傳結果:
8721
	#$result["status"],若成功則爲"true",失敗則爲,"false"
8722
	#$result["error"],錯誤訊息.
8723
	#$result["function"],當前執行的函數名稱.
43 liveuser 8724
	#必填參數:
1 liveuser 8725
	$conf["dbAddress"],字串,爲mysql-Server的位置
8726
	$conf["dbAddress"]=$dbAddress;
8727
	$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
8728
	$conf["dbAccount"]=$dbAccount;
8729
	$conf["selectedDatabaseName"],字串,爲要移除的資料表位於哪個資料庫
8730
	$conf["selectedDatabaseName"]=$dbName;
8731
	$conf["dropedDataTableName"],字串,爲要移除的資料表名稱
8732
	$conf["dropedDataTableName"]=$tableName;#爲要移除的資料表名稱
43 liveuser 8733
	#可省略參數:		
1 liveuser 8734
	#$conf["dbPassword"],字串.爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
8735
	#$conf["dbPassword"]=$dbPassword;
8736
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
8737
	#$conf["dbPort"]="3306";
185 liveuser 8738
	#參考資料:
8739
	#無.
43 liveuser 8740
	#備註:
8741
	#無.
1 liveuser 8742
	*/
8743
	public static function dropDataTable($conf){
8744
 
8745
		#初始化要回傳的內容
8746
		$result=array();
8747
 
8748
		#取得當前執行的函數名稱
8749
		$result["function"]=__FUNCTION__;
8750
 
8751
		#如果 $conf 不為陣列
8752
		if(gettype($conf)!="array"){
8753
 
8754
			#設置執行失敗
8755
			$result["status"]="false";
8756
 
8757
			#設置執行錯誤訊息
8758
			$result["error"][]="\$conf變數須為陣列形態";
8759
 
8760
			#如果傳入的參數為 null
8761
			if($conf==null){
8762
 
8763
				#設置執行錯誤訊息
8764
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
8765
 
8766
				}#if end
8767
 
8768
			#回傳結果
8769
			return $result;
8770
 
8771
			}#if end
8772
 
43 liveuser 8773
		#函式說明:
1 liveuser 8774
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 8775
		#回傳結果:
1 liveuser 8776
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8777
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8778
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 8779
		#必填參數:
1 liveuser 8780
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
8781
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDatabaseName","dropedDataTableName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 8782
		#可省略參數:
1 liveuser 8783
		$conf["variableType"]=array("string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
8784
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
8785
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
8786
		unset($conf["variableCheck"]["isexistMuti"]);
8787
 
8788
		#如果檢查不正常
8789
		if($checkResult["status"]=="false"){
8790
 
8791
			#設置執行錯誤
8792
			$result["status"]="fasle";
8793
 
8794
			#設置錯誤訊息
8795
			$result["error"]=$checkResult;
8796
 
8797
			#回傳結果:
8798
			return $result;
8799
 
8800
			}#if end
8801
 
8802
		#如果檢查不通過
8803
		if($checkResult["passed"]=="false"){
8804
 
8805
			#設置執行錯誤
8806
			$result["status"]="fasle";
8807
 
8808
			#設置錯誤訊息
8809
			$result["error"]=$checkResult;
8810
 
8811
			#回傳結果:
8812
			return $result;
8813
 
8814
			}#if end
8815
 
8816
		#建立移除資料表的sql語言
8817
		$sql="drop table ".$conf["selectedDatabaseName"].".".$conf["dropedDataTableName"].";";
8818
 
43 liveuser 8819
		#函式說明:
1 liveuser 8820
		#執行mysql查詢的指令
43 liveuser 8821
		#回傳結果::
1 liveuser 8822
		#$result["status"],"true"為執行成功;"false"為執行失敗。
8823
		#$result["error"],錯誤訊息的陣列
8824
		#查詢號的解果,需要解析。
43 liveuser 8825
		#必填參數:
1 liveuser 8826
		$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
8827
		$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
8828
		$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
43 liveuser 8829
		#可省略參數: 
1 liveuser 8830
 
8831
		#如果有設定密碼
8832
		if(isset($conf["dbPassword"])){
8833
 
8834
			$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
8835
 
8836
			}#if end
8837
 
8838
		#如果有設定 $conf["dbPort"]
8839
		if(isset($conf["dbPort"])){
8840
 
8841
			#設置 $conf["dbPort"]
8842
			$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
8843
 
8844
			}#if end
8845
 
8846
		$queryResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
8847
		unset($conf["db"]["execMysqlQuery"]);
8848
 
8849
		#如果移除資料表失敗
8850
		if($queryResult["status"]=="false"){
8851
 
8852
			#設置錯誤識別
8853
			$result["status"]="false";
8854
 
8855
			#設置錯誤訊息
8856
			$result["error"]=$queryResult["error"];
8857
 
8858
			#回傳結果
8859
			return $result;
8860
 
8861
			}#if end
8862
 
8863
		#設置執行成功的訊息
8864
		$result["status"]="true";
8865
 
8866
		#回傳結果
8867
		return $result;
8868
 
8869
		}#funcotion dropDataTable end
8870
 
8871
	/*
43 liveuser 8872
	#函式說明:
1 liveuser 8873
	#查詢所有的資料庫列表,會回傳查詢的結果
43 liveuser 8874
	#回傳結果:
1 liveuser 8875
	#$result["status"],執行是否正常,"true"為正常,"fasle"為不正常
8876
	#$result["error"],爲錯誤訊息
8877
	#$result["function"],當前執行的函數名稱
8878
	#$result["dbName"] 爲查詢的資料庫名稱陣列,第一筆資料庫名稱爲$result["dbName"][0],第二筆資料庫名稱爲$result["dbName"][1],其餘以此類推。
8879
	#$result["dbCounts"] 爲資料庫的總筆數	
43 liveuser 8880
	#必填參數:
1 liveuser 8881
	$conf["dbAddress"],字串,爲mysql-Server的位置.
8882
	$conf["dbAddress"]=$dbAddress;
8883
	$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
8884
	$conf["dbAccount"]=$dbAccount;
43 liveuser 8885
	#可省略參數:
1 liveuser 8886
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
8887
	#$conf["dbPassword"]=$dbPassword;
8888
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
8889
	#$conf["dbPort"]="3306";
185 liveuser 8890
	#參考資料:
8891
	#無.
43 liveuser 8892
	#備註:
8893
	#無.
1 liveuser 8894
	*/
8895
	public static function getDataBaseList($conf){
8896
 
8897
		#初始化要回傳的內容
8898
		$result=array();
8899
 
8900
		#取得當前執行的函數名稱
8901
		$result["function"]=__FUNCTION__;
8902
 
8903
		#如果 $conf 不為陣列
8904
		if(gettype($conf)!="array"){
8905
 
8906
			#設置執行失敗
8907
			$result["status"]="false";
8908
 
8909
			#設置執行錯誤訊息
8910
			$result["error"][]="\$conf變數須為陣列形態";
8911
 
8912
			#如果傳入的參數為 null
8913
			if($conf==null){
8914
 
8915
				#設置執行錯誤訊息
8916
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
8917
 
8918
				}#if end
8919
 
8920
			#回傳結果
8921
			return $result;
8922
 
8923
			}#if end
8924
 
8925
		#檢查參數
43 liveuser 8926
		#函式說明:
1 liveuser 8927
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 8928
		#回傳結果:
1 liveuser 8929
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
8930
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
8931
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 8932
		#必填參數:
1 liveuser 8933
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
8934
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 8935
		#可省略參數:
1 liveuser 8936
		#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
8937
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
8938
		#備註:
8939
		#功能與checkExistAndType函式相同
8940
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
8941
		unset($conf["variableCheck"]["isexistMuti"]);
8942
 
8943
		#如果 $checkResult["passed"]等於"fasle"
8944
		if($checkResult["passed"]=="fasle"){
8945
 
8946
			#設置錯誤識別
8947
			$result["status"]="fasle";
8948
 
8949
			#設置錯誤訊息
8950
			$result["error"]=$checkResult;
8951
 
8952
			#回傳結果
8953
			return $result;
8954
 
8955
			}#if end 
8956
 
8957
		#連線到mysql-server
43 liveuser 8958
		#函式說明:
1 liveuser 8959
		#連線到mysql-server,會回傳一個陣列
8960
		#回傳結果:
8961
		#$result["status"],若連線成功則爲"true",連線失敗則爲"false"。
8962
		#$result["connectInformation"],爲回傳的mysql連線資訊。
8963
		#$result["error"],爲錯誤訊息陣列
8964
		#必填參數:
8965
		$conf["db"]["mysqlConnect"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置。
8966
		$conf["db"]["mysqlConnect"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號。
43 liveuser 8967
		#可省略參數:
1 liveuser 8968
 
8969
		#如果有設置 $conf["dbPassword"]
8970
		if(isset($conf["dbPassword"])){
8971
 
8972
			$conf["db"]["mysqlConnect"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
8973
 
8974
			}#if end
8975
 
8976
		#如果有設置 $conf["dbPort"]
8977
		if(isset($conf["dbPort"])){
8978
 
8979
			$conf["db"]["mysqlConnect"]["dbPort"]=$conf["dbPort"];#連線時用的port.
8980
 
8981
			}#if end
8982
 
8983
		$con=db::mysqlConnect($conf["db"]["mysqlConnect"]);
8984
		unset($conf["db"]["mysqlConnect"]);
8985
 
8986
		#如果 $con["status"] 等於 "fasle"
8987
		if($con["status"]=="fasle"){
8988
 
8989
			#設置錯誤識別
8990
			$result["status"]="false";
8991
 
8992
			#設置錯誤訊息
8993
			$result["error"]=$con;
8994
 
8995
			#回傳結果
8996
			return $result;
8997
 
8998
			}#if end
8999
 
9000
		#執行列出資料庫列表的SQL語法
43 liveuser 9001
		#函式說明:
1 liveuser 9002
		#執行mysql指令
43 liveuser 9003
		#回傳結果::
1 liveuser 9004
		#$result["status"],"true"為執行成功;"false"為執行失敗。
9005
		#$result["error"],錯誤訊息的陣列
9006
		#$result["function"],當前執行的涵式
9007
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
9008
		#$result["queryString"],mysql查詢的語言
9009
		#查詢號的解果,需要解析。
43 liveuser 9010
		#必填參數:
1 liveuser 9011
		$conf["db::execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
9012
		$conf["db::execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
9013
		$conf["db::execMysqlQuery"]["dbSql"]="show databases;";#要執行sql語法
43 liveuser 9014
		#可省略參數: 
1 liveuser 9015
 
9016
		#如果存在 $conf["dbPassword"]
9017
		if(isset($conf["dbPassword"])){
9018
 
9019
			$conf["db::execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
9020
 
9021
			}#if end
9022
 
9023
		#如果存在 $conf["dbPort"]
9024
		if(isset($conf["dbPort"])){
9025
 
9026
			$conf["db::execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
9027
 
9028
			}#if end
9029
 
9030
		$execMysqlQuery=db::execMysqlQuery($conf["db::execMysqlQuery"]);
9031
		unset($conf["db::execMysqlQuery"]);
9032
 
9033
		#如果執行SQL語法失敗
9034
		if($execMysqlQuery["status"]=="false"){
9035
 
9036
			#設置錯誤識別
9037
			$result["status"]="false";
9038
 
9039
			#設置錯誤訊息
9040
			$result["error"]=$execMysqlQuery;
9041
 
9042
			#回傳結果
9043
			return $result;
9044
 
9045
			}#if end
9046
 
9047
		#設定 $i 的初始值
9048
		$times=0;
9049
 
9050
		#逐筆解析內容
9051
		while($row=mysqli_fetch_assoc($execMysqlQuery["queryResource"])) {
9052
 
9053
			#將結果存進 $fetchResult[$times]	    	
9054
			$fetchResult[$times]= $row['Database'];
9055
 
9056
			#$times + 1 (計數用)
9057
			$times++;
9058
 
9059
			}#while end
9060
 
9061
		#取得每筆資料內容(資料庫的名稱)
9062
		$result["dbName"]=$fetchResult;
9063
 
9064
		#取得總共的資料筆數
9065
		$result["dbCounts"]=$times;
9066
 
9067
		#執行到這邊代表執行成功
9068
		$result["status"]="true";
9069
 
9070
		#回傳查詢的結果 $result
9071
		return $result;
9072
 
9073
		}#function getDataBaseList end
9074
 
9075
	/*
43 liveuser 9076
	#函式說明:
1 liveuser 9077
	#查詢特定資料庫裡的資料表列表,會回傳查詢的結果
43 liveuser 9078
	#回傳結果:
1 liveuser 9079
	#$result["status"],執行是否成功,"true"代表執行成功;"false"代表執行失敗。
9080
	#$result["error"],執行錯誤的訊息.
9081
	#$result["function"],當前執行的函式名稱.
9082
	#$result["connectInformation"],爲回傳的mysql連線資訊。
9083
	#$result["tableName"] 爲查詢的資料庫名稱陣列,
9084
		#第一筆資料庫名稱爲$result["tableName"][0],
9085
		#第二筆資料庫名稱爲$result["tableName"][1],
9086
		#其餘以此類推。
9087
	#$result["dataCounts"] 爲資料表的總筆數
43 liveuser 9088
	#必填參數:
1 liveuser 9089
	$conf["dbAddress"],字串,爲mysql-Server的位置
9090
	$conf["dbAddress"]=$dbAddress;
9091
	$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
9092
	$conf["dbAccount"]=$dbAccount;
9093
	$conf["selectedDataBaseName"],字串,爲指定的資料庫名稱
9094
	$conf["selectedDataBaseName"]=$dbName;
43 liveuser 9095
	#可省略參數:
1 liveuser 9096
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
9097
	#$conf["dbPassword"]=$dbPassword;
9098
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
9099
	#$conf["dbPort"]="3306";
185 liveuser 9100
	#參考資料:
9101
	#無.
43 liveuser 9102
	#備註:
9103
	#原始語法,show tables FROM databaseName,代表檢視databaseName裡面的資料表清單。
1 liveuser 9104
	*/
9105
	public static function getDataTableList($conf){
9106
 
9107
		#初始化要回傳的內容
9108
		$result=array();
9109
 
9110
		#取得當前執行的函數名稱
9111
		$result["function"]=__FUNCTION__;
9112
 
9113
		#如果 $conf 不為陣列
9114
		if(gettype($conf)!="array"){
9115
 
9116
			#設置執行失敗
9117
			$result["status"]="false";
9118
 
9119
			#設置執行錯誤訊息
9120
			$result["error"][]="\$conf變數須為陣列形態";
9121
 
9122
			#如果傳入的參數為 null
9123
			if($conf==null){
9124
 
9125
				#設置執行錯誤訊息
9126
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
9127
 
9128
				}#if end
9129
 
9130
			#回傳結果
9131
			return $result;
9132
 
9133
			}#if end
9134
 
43 liveuser 9135
		#函式說明:
1 liveuser 9136
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 9137
		#回傳結果:
1 liveuser 9138
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9139
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9140
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 9141
		#必填參數:
1 liveuser 9142
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
9143
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 9144
		#可省略參數:
1 liveuser 9145
		#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
9146
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
9147
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
9148
		unset($conf["variableCheck"]);
9149
 
9150
		#如果檢查失敗
9151
		if($checkResult["status"]=="false"){
9152
 
9153
			#設置錯誤訊息識別
9154
			$result["status"]="fasle";
9155
 
9156
			#設置錯誤訊息
9157
			$result["error"]=$checkResult;
9158
 
9159
			#回傳錯誤結果
9160
			return $result;
9161
 
9162
			}#if end
9163
 
9164
		#如果檢查不通過
9165
		if($checkResult["passed"]=="false"){
9166
 
9167
			#設置錯誤訊息識別
9168
			$result["status"]="fasle";
9169
 
9170
			#設置錯誤訊息
9171
			$result["error"]=$checkResult;
9172
 
9173
			#回傳錯誤結果
9174
			return $result;
9175
 
9176
			}#if end
9177
 
9178
		#要執行的 sql 語句
9179
		$sql="show tables FROM ".$conf["selectedDataBaseName"].";";
9180
 
43 liveuser 9181
		#函式說明:
1 liveuser 9182
		#執行mysql指令
43 liveuser 9183
		#回傳結果::
1 liveuser 9184
		#$result["status"],"true"為執行成功;"false"為執行失敗。
9185
		#$result["error"],錯誤訊息的陣列
9186
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
9187
		#$result["queryString"],mysql查詢的語言
9188
		#查詢號的解果,需要解析。
43 liveuser 9189
		#必填參數:
1 liveuser 9190
		$conf["db.execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
9191
		$conf["db.execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
9192
		$conf["db.execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
43 liveuser 9193
		#可省略參數: 
1 liveuser 9194
 
9195
		#如果 $conf["dbPassword"] 有設定
9196
		if(isset($conf["dbPassword"])){
9197
 
9198
			#$conf["db.execMysqlQuery"]["dbPassword"]=$dbPassword;#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
9199
			$conf["db.execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
9200
 
9201
			}#if end
9202
 
9203
		#如果 $conf["dbPort"] 有設定
9204
		if(isset($conf["dbPort"])){
9205
 
9206
			#設置 dbPort
9207
			$conf["db.execMysqlQuery"]["dbPort"]=$conf["dbPort"];
9208
 
9209
			}#if end
9210
 
9211
		$queryResult=db::execMysqlQuery($conf["db.execMysqlQuery"]);
9212
		unset($conf["db.execMysqlQuery"]);
9213
 
9214
		#如果執行sql語法失敗
9215
		if($queryResult["status"]=="false"){
9216
 
9217
			#設置執行不正常
9218
			$result["status"]="false";
9219
 
9220
			#設置錯誤訊息
9221
			$result["error"]=$queryResult;
9222
 
9223
			#回傳結果
9224
			return $result;
9225
 
9226
			}#if end
9227
 
9228
		#將查詢的結果放進$queryResult裏面
9229
		$queryResult=$queryResult["queryResource"];
9230
 
9231
		#debug
9232
		#var_dump($queryResult);
9233
 
9234
		#設定 $times 的初始值
9235
		$times=0;
9236
 
9237
		#初始化解析的內容儲存的地方
9238
		$fetchResult=array();
9239
 
9240
		#逐筆解析內容
9241
		while ($row = mysqli_fetch_assoc($queryResult)) {
9242
 
9243
			#將結果存進 $result[$i]		    	
9244
			$fetchResult[$times]= $row["Tables_in_".$conf["selectedDataBaseName"]];
9245
 
9246
			#$times + 1 (計數用)
9247
			$times++;
9248
 
9249
			#debug
9250
			#var_dump($row);
9251
 
9252
			}#while end
9253
 
9254
		#取得每筆資料內容(資料表的名稱)
9255
		$result["tableName"]=$fetchResult;
9256
 
9257
		#取得總共的資料筆數
9258
		$result["dataCounts"]=$times;
9259
 
9260
		#設置執行成功的識別
9261
		$result["status"]="true";
9262
 
9263
		#回傳查詢的結果 $result
9264
		return $result;
9265
 
9266
		}#function getDataTableList end
9267
 
9268
	/*
43 liveuser 9269
	#函式說明:
1 liveuser 9270
	#取得資料表所有欄位的詳細資訊
9271
	#回傳的內容:
9272
	#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
9273
	#$result["error"],錯誤訊息陣列
9274
	#$result["function"],當前執行的函數名稱.
9275
	#$result["sql"],執行的sql語法
9276
	#$result["oriInput"],原始的資料表欄位資訊
9277
	#$result["everyLine"],逐行的欄位資訊
9278
	#$result["tableName"],當前查詢的資料表名稱
9279
	#$result["engine"],資料表使用的儲存引擎
9280
	#$result["charset"],資料表預設的編碼
9281
	#$result["columnName"][$i],各欄位的名稱陣列,$i爲1開始的數字,也可以使用欄位的名稱。
9282
	#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲1開始的數字,也可以使用欄位的名稱。
9283
	#$result["columnVarType"][$i],各欄位變數儲存的型態,$i爲1開始的數字,也可以使用欄位的名稱.
9284
	#$result["columnVarLengthLimit"][$i],個欄位變數的長度限制,若不存在其限制,則為"",$i爲1開始的數字,也可以使用欄位的名稱.
9285
	#$result["columnNotNull"][$i],各欄位是否不可爲null,"true"爲不可以爲null;"false"爲可爲"null",$i爲1開始的數字,也可以使用欄位的名稱。
9286
	#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲1開始的數字,也可以使用欄位的名稱。
9287
	#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲1開始的數字,也可以使用欄位的名稱。
9288
	#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲1開始的數字,也可以使用欄位的名稱。
9289
	#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲1開始的數字,也可以使用欄位的名稱。
9290
	#$result["columnCollate"][$i],各欄位使用的Collate,$i爲1開始的數字,也可以使用欄位的名稱。
9291
	#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
9292
	#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
9293
	#$result["keyConstraintName"][$j],該資料表用於識別索引鍵的CONSTRAINT名稱陣列,$j爲1開始的數字,也可以使用欄位的名稱。
9294
	#$result["primaryKey"],該資料表的主鍵
9295
	#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
9296
	#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
9297
	#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
9298
	#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲1開始的數字,,也可用欄位的名稱來找value.
9299
	#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲1開始的數字,也可用欄位的名稱來找value.
9300
	#$result["foreignKey"]["onUpdateAction"][$i],當參照的欄位資料更新時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
9301
	#$result["foreignKey"]["onDeleteAction"][$i],當參照的欄位資料移除時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
43 liveuser 9302
	#必填參數:
1 liveuser 9303
	#$conf["dbAddress"],字串,資料庫的網路位置.
9304
	$conf["dbAddress"]=$dbAddress;
9305
	#$conf["dbAccount"],字串,連線到資料庫要用的帳號.
9306
	$conf["dbAccount"]=$dbAccount;
9307
	#$conf["selectedDataBase"],字串,連線到資料庫要選擇的資料庫.
9308
	$conf["selectedDataBase"]=$dbName;
9309
	#$conf["selectedDataTable"],字串,連線到資料庫要檢視的資料表.
9310
	$conf["selectedDataTable"]="";
43 liveuser 9311
	#可省略參數:
1 liveuser 9312
	#$conf["dbPassword"],字串,連線到資料庫要用的密碼
9313
	#$conf["dbPassword"]=$dbPassword;
9314
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
9315
	#$conf["dbPort"]="3306";
185 liveuser 9316
	#參考資料:
9317
	#無.
1 liveuser 9318
	#備註:
9319
	#查詢的功能有點弱,目前用getTableColumnDetailInfo替代
9320
	*/
9321
	public static function getDataTableColumn($conf){
9322
 
9323
		return db::getTableColumnDetailInfo($conf);
9324
 
9325
		}#function getDataTableColumn end
9326
 
9327
	/*
43 liveuser 9328
	#函式說明:
1 liveuser 9329
	#取得資料表內特定欄位的資訊
9330
	#回傳的內容:
9331
	#$result["status"],"true"代表執行成功;"false"代表執行失敗.
9332
	#$result["error"],錯誤訊息.
9333
	#$result["function"],當前執行的函數名稱.
9334
	#$result["columnInfo"]["name"],欄位的名稱.
9335
	#$result["columnInfo"]["type"],欄位的儲存型態.
9336
	#$result["columnInfo"]["length"],欄位的長度限制.
9337
	#$result["columnInfo"]["null"],欄位是否可以為null.
9338
	#$result["columnInfo"]["key"],索引鍵的名稱.
9339
	#$result["columnInfo"]["keyType"],欄位的鍵屬性.
9340
	#$result["columnInfo"]["foreignKeyConstraintName"],外建的名稱
9341
	#$result["columnInfo"]["referencesTable"],外鍵參考的資料表.
9342
	#$result["columnInfo"]["referencesColumn"],外鍵參考的資料表欄位.
9343
	#$result["columnInfo"]["onUpdateAction"],當參考的欄位更新時,要怎麼因應.
9344
	#$result["columnInfo"]["onDeleteAction"],當參考的欄位資料消失時,要怎麼因應.
9345
	#$result["columnInfo"]["default"],欄位的預設內容.
9346
	#$result["columnInfo"]["columnCharacterSet"],欄位的字元集.
9347
	#$result["columnInfo"]["columnCollate"],欄位的校對編碼.
43 liveuser 9348
	#必填參數:
1 liveuser 9349
	$conf["dbAddress"],字串,爲mysql-Server的位置
9350
	$conf["dbAddress"]=$dbAddress;
9351
	$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
9352
	$conf["dbAccount"]=$dbAccount;
9353
	$conf["dbName"]=$dbName;#爲指定的資料庫名稱
9354
	$conf["dtName"]="";#為要檢視的資料表名稱
9355
	$conf["columnName"],字串,為要檢視的資料欄位名稱
9356
	$conf["columnName"]="";#為要檢視的資料欄位名稱
43 liveuser 9357
	#可省略參數:
1 liveuser 9358
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
9359
	#$conf["dbPassword"]=$dbPassword;
9360
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
9361
	#$conf["dbPort"]="3306";
185 liveuser 9362
	#參考資料:
9363
	#無.
43 liveuser 9364
	#備註:
9365
	#無.
1 liveuser 9366
	*/
9367
	public static function getDataTableSpecificColumn(&$conf){
9368
 
9369
		#初始化要回傳的內容
9370
		$result=array();
9371
 
9372
		#取得當前執行的函數名稱
9373
		$result["function"]=__FUNCTION__;
9374
 
9375
		#如果 $conf 不為陣列
9376
		if(gettype($conf)!="array"){
9377
 
9378
			#設置執行失敗
9379
			$result["status"]="false";
9380
 
9381
			#設置執行錯誤訊息
9382
			$result["error"][]="\$conf變數須為陣列形態";
9383
 
9384
			#如果傳入的參數為 null
9385
			if($conf==null){
9386
 
9387
				#設置執行錯誤訊息
9388
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
9389
 
9390
				}#if end
9391
 
9392
			#回傳結果
9393
			return $result;
9394
 
9395
			}#if end
9396
 
9397
		#檢查參數
43 liveuser 9398
		#函式說明:
1 liveuser 9399
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
9400
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
9401
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
9402
		#$result["function"],當前執行的函式名稱.
9403
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9404
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9405
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
9406
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
9407
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
9408
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
9409
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
43 liveuser 9410
		#必填參數:
1 liveuser 9411
		#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
9412
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
9413
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
9414
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","dbName","dtName","columnName");
9415
		#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
9416
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string");
9417
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
9418
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
43 liveuser 9419
		#可省略參數:
1 liveuser 9420
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
9421
		#$conf["canBeEmptyString"]="false";
9422
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
9423
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort");
9424
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
9425
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
9426
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
9427
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null);
9428
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
9429
		#$conf["arrayCountEqualCheck"][]=array();
43 liveuser 9430
		#參考資料:
1 liveuser 9431
		#array_keys=>http://php.net/manual/en/function.array-keys.php
9432
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
9433
		unset($conf["variableCheck::checkArguments"]);	
9434
 
9435
		#如果檢查失敗 
9436
		if($checkResult["status"]=="false"){
9437
 
9438
			#設置執行失敗
9439
			$result["status"]="false";
9440
 
9441
			#設置執行失敗訊息
9442
			$result["error"]=$checkResult;
9443
 
9444
			#回傳結果
9445
			return $result;
9446
 
9447
			}#if end
9448
 
9449
		#如果檢查沒有通過
9450
		if($checkResult["passed"]=="false"){
9451
 
9452
			#設置執行失敗
9453
			$result["status"]="false";
9454
 
9455
			#設置執行失敗訊息
9456
			$result["error"]=$checkResult;
9457
 
9458
			#回傳結果
9459
			return $result;
9460
 
9461
			}#if end
9462
 
9463
		#取得所有的欄位資訊
43 liveuser 9464
		#函式說明:
1 liveuser 9465
		#取得資料表所有欄位的詳細資訊
9466
		#回傳的內容:
9467
		#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
9468
		#$result["error"],錯誤訊息陣列
9469
		#$result["function"],當前執行的函數名稱.
9470
		#$result["sql"],執行的sql語法
9471
		#$result["oriInput"],原始的資料表欄位資訊
9472
		#$result["everyLine"],逐行的欄位資訊
9473
		#$result["tableName"],當前查詢的資料表名稱
9474
		#$result["engine"],資料表使用的儲存引擎
9475
		#$result["charset"],資料表預設的編碼
9476
		#$result["columnName"][$i],各欄位的名稱陣列,$i爲1開始的數字,也可以使用欄位的名稱。
9477
		#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲1開始的數字,也可以使用欄位的名稱。
9478
		#$result["columnVarType"][$i],各欄位變數儲存的型態,$i爲1開始的數字,也可以使用欄位的名稱.
9479
		#$result["columnVarLengthLimit"][$i],個欄位變數的長度限制,若不存在其限制,則為"",$i爲1開始的數字,也可以使用欄位的名稱.
9480
		#$result["columnNotNull"][$i],各欄位是否不可爲null,"true"爲不可以爲null;"false"爲可爲"null",$i爲1開始的數字,也可以使用欄位的名稱。
9481
		#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲1開始的數字,也可以使用欄位的名稱。
9482
		#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲1開始的數字,也可以使用欄位的名稱。
9483
		#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲1開始的數字,也可以使用欄位的名稱。
9484
		#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲1開始的數字,也可以使用欄位的名稱。
9485
		#$result["columnCollate"][$i],各欄位使用的Collate,$i爲1開始的數字,也可以使用欄位的名稱。
9486
		#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
9487
		#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
9488
		#$result["keyConstraintName"][$j],該資料表用於識別索引鍵的CONSTRAINT名稱陣列,$j爲1開始的數字,也可以使用欄位的名稱。
9489
		#$result["primaryKey"],該資料表的主鍵
9490
		#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
9491
		#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
9492
		#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
9493
		#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲1開始的數字,,也可用欄位的名稱來找value.
9494
		#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲1開始的數字,也可用欄位的名稱來找value.
9495
		#$result["foreignKey"]["onUpdateAction"][$i],當參照的欄位資料更新時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
9496
		#$result["foreignKey"]["onDeleteAction"][$i],當參照的欄位資料移除時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
43 liveuser 9497
		#必填參數:
1 liveuser 9498
		$conf["db::getTableColumnDetailInfo"]["dbAddress"]=$conf["dbAddress"];#資料庫的網路位置
9499
		$conf["db::getTableColumnDetailInfo"]["dbAccount"]=$conf["dbAccount"];#連線到資料庫要用的帳號
9500
		$conf["db::getTableColumnDetailInfo"]["selectedDataBase"]=$conf["dbName"];#連線到資料庫要選擇的資料庫
9501
		$conf["db::getTableColumnDetailInfo"]["selectedDataTable"]=$conf["dtName"];#連線到資料庫要檢視的資料表
43 liveuser 9502
		#可省略參數:
1 liveuser 9503
 
9504
		#如果有設定連線密碼
9505
		if(isset($conf["dbPassword"])){
9506
 
9507
			$conf["db::getTableColumnDetailInfo"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
9508
 
9509
			}#if end
9510
 
9511
		#如果有設定連線port
9512
		if(isset($conf["dbPort"])){
9513
 
9514
			$conf["db::getTableColumnDetailInfo"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
9515
 
9516
			}#if end
9517
 
9518
		$queryResult=db::getTableColumnDetailInfo($conf["db::getTableColumnDetailInfo"]);
9519
		unset($conf["db::getTableColumnDetailInfo"]);
9520
 
9521
		#如果查詢失敗
9522
		if($queryResult["status"]=="false"){
9523
 
9524
			#設置錯誤
9525
			$result["status"]="false";
9526
 
9527
			#設置錯誤訊息
9528
			$result["error"]=$queryResult;
9529
 
9530
			#回傳結果
9531
			return $result;
9532
 
9533
			}#if end
9534
 
9535
		#var_dump($queryResult);
9536
 
9537
		#檢查是否有我們要的欄位存在
43 liveuser 9538
		#函式說明:
1 liveuser 9539
		#檢查一個數值是否與陣列裏面的元素相同
43 liveuser 9540
		#回傳結果::
1 liveuser 9541
		#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
9542
		#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
9543
		#$result["error"],錯誤訊息
9544
		#$result["function"],當前執行的函數名稱
9545
		#$result["equalVarName"],相等的變數名稱或key.
9546
		#$result["equalVarValue"],相等的變數數值內容.
43 liveuser 9547
		#必填參數:
1 liveuser 9548
		$conf["search"]["getEqualVar"]["conditionElement"]=$conf["columnName"];#條件元素,要等於的元素內容。
9549
		$conf["search"]["getEqualVar"]["compareElements"]=$queryResult["columnName"];#要比對的陣列變數內容。
9550
		$searchResult=search::getEqualVar($conf["search"]["getEqualVar"]);
9551
		unset($conf["search"]["getEqualVar"]);
9552
 
9553
		#如果尋找失敗
9554
		if($searchResult["status"]=="false"){
9555
 
9556
			#設置錯誤
9557
			$result["status"]="false";
9558
 
9559
			#設置錯誤訊息
9560
			$result["error"]=$searchResult;
9561
 
9562
			#回傳結果
9563
			return $result;
9564
 
9565
			}#if end
9566
 
9567
		#如果沒有找到符合的欄位明稱
9568
		if($searchResult["founded"]=="false"){
9569
 
9570
			#設置錯誤
9571
			$result["status"]="false";
9572
 
9573
			#設置錯誤訊息
9574
			$result["error"]="沒有找到指定的欄位!";
9575
 
9576
			#回傳結果
9577
			return $result;
9578
 
9579
			}#if end
9580
 
9581
		#取得欄位資訊的key
9582
		$equalVarKey=$searchResult["equalVarName"];
9583
 
9584
		#取得欄位的名稱
9585
		$result["columnInfo"]["name"]=$queryResult["columnName"][$equalVarKey];
9586
 
9587
		#取欄位的儲存型態與長度限制
9588
		$result["columnInfo"]["type"]=$queryResult["columnVarType"][$equalVarKey];
9589
 
9590
		#檢查欄位儲存型態是否含有「(」與「)」
43 liveuser 9591
		#函式說明:
1 liveuser 9592
		#檢查一個字串裡面是否有多個關鍵字
43 liveuser 9593
		#回傳結果::
1 liveuser 9594
		#$result["status"],"true"代表執行成功,"false"代表執行失敗。
9595
		#$result["error"],錯誤訊息
9596
		#$result["founded"],是否找到所有的關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
43 liveuser 9597
		#必填參數:
1 liveuser 9598
		$conf["search"]["findManyKeyWords"]["keyWords"]=array("(",")");#想要搜尋的關鍵字
9599
		$conf["search"]["findManyKeyWords"]["string"]=$result["columnInfo"]["type"];#要被搜尋的字串內容
43 liveuser 9600
		#可省略參數:
1 liveuser 9601
		#$conf["search"]["findManyKeyWords"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
9602
		$searchResult=search::findManyKeyWords($conf["search"]["findManyKeyWords"]);
9603
		unset($conf["search"]["findManyKeyWords"]);
9604
 
9605
		#如果 檢查欄位儲存型態是否含有「(」與「)」 失敗
9606
		if($searchResult["status"]=="false"){
9607
 
9608
			#設置錯誤
9609
			$result["status"]="false";
9610
 
9611
			#設置錯誤訊息
9612
			$result["error"]=$searchResult;
9613
 
9614
			#回傳結果
9615
			return $result;
9616
 
9617
			}#if end
9618
 
9619
		#如果欄位儲存型態含有「(」與「)」,則將其從「(」開始分割
9620
		if($searchResult["founded"]=="true"){
9621
 
43 liveuser 9622
			#函式說明:
1 liveuser 9623
			#將固定格式的字串分開,並回傳分開的結果。
9624
			#回傳的參數:
9625
			#$result["oriStr"],要分割的原始字串內容
9626
			#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
9627
			#$result["dataCounts"],爲總共分成幾段
43 liveuser 9628
			#必填參數:
1 liveuser 9629
			$conf["stringProcess"]["spiltString"]["stringIn"]=$result["columnInfo"]["type"];#要處理的字串。
9630
			$conf["stringProcess"]["spiltString"]["spiltSymbol"]="(";#爲以哪個符號作爲分割
9631
			$spiltedStr=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
9632
			unset($conf["stringProcess"]["spiltString"]);
9633
 
9634
			#如果分割字串失敗
9635
			if($spiltedStr["status"]=="false"){
9636
 
9637
				#設置錯誤
9638
				$result["status"]="false";
9639
 
9640
				#設置錯誤訊息
9641
				$result["error"]=$spiltedStr;
9642
 
9643
				#回傳結果
9644
				return $result;
9645
 
9646
				}#if end
9647
 
9648
			#取得欄位型態
9649
			$result["columnInfo"]["type"]=$spiltedStr["dataArray"][0];
9650
 
9651
			}#if end 
9652
 
9653
		#取得欄位長度限制
9654
		$result["columnInfo"]["length"]=$queryResult["columnVarLengthLimit"][$conf["columnName"]];
9655
 
9656
		#取得欄位是否可以為null
9657
		$result["columnInfo"]["null"]=$queryResult["columnNotNull"][$conf["columnName"]];
9658
 
9659
		#如果該欄位有key的名稱
9660
		if(isset($queryResult["key"][$conf["columnName"]])){
9661
 
9662
			#該欄位為index key
9663
			$result["columnInfo"]["keyType"]="index key";
9664
 
9665
			#取得欄位的鍵名稱
9666
			$result["columnInfo"]["key"]=$queryResult["keyConstraintName"];
9667
 
9668
			}#if end
9669
 
9670
		#如果該欄位是foreignKey
9671
		if(isset($queryResult["foreignKey"]["constraintName"][$conf["columnName"]])){
9672
 
9673
			#該欄位為foreign key
9674
			$result["columnInfo"]["keyType"]="foreign key";
9675
 
9676
			#取得外鍵的名稱
9677
			$result["columnInfo"]["foreignKeyConstraintName"]=$queryResult["foreignKey"]["constraintName"][$conf["columnName"]];
9678
 
9679
			#取得外鍵參考的資料表
9680
			$result["columnInfo"]["referencesTable"]=$queryResult["foreignKey"]["referencesTable"][$conf["columnName"]];
9681
 
9682
			#取得外按鍵參考的欄位
9683
			$result["columnInfo"]["referencesColumn"]=$queryResult["foreignKey"]["referencesColumn"][$conf["columnName"]];
9684
 
9685
			#當參考的欄位更新時,要怎麼因應
9686
			$result["columnInfo"]["onUpdateAction"]=$queryResult["foreignKey"]["onUpdateAction"][$conf["columnName"]];
9687
 
9688
			#當參考的欄位資料消失時,要怎麼因應
9689
			$result["columnInfo"]["onDeleteAction"]=$queryResult["foreignKey"]["onDeleteAction"][$conf["columnName"]];
9690
 
9691
			}#if enb
9692
 
9693
		#取得欄位的預設內容
9694
		$result["columnInfo"]["default"]=$queryResult["columnDefault"][$conf["columnName"]];
9695
 
9696
		#取得欄位的字元集
9697
		$result["columnInfo"]["columnCharacterSet"]=$queryResult["columnCharacterSet"][$conf["columnName"]];
9698
 
9699
		#取得欄位的校對編碼設定
9700
		$result["columnInfo"]["columnCollate"]=$queryResult["columnCollate"][$conf["columnName"]];
9701
 
9702
		#設置執行成功
9703
		$result["status"]="true";
9704
 
9705
		#回傳結果
9706
		return $result;
9707
 
9708
		}#function getDataTableSpecificColumn end
9709
 
9710
	/*
43 liveuser 9711
	#函式說明:
1 liveuser 9712
	#檢查資料庫裏的資料表有無指定條件的資料
43 liveuser 9713
	#回傳結果::
1 liveuser 9714
	#$result["status"],執行是否成功,成功為"true",失敗為"false"。
9715
	#$result["error"],錯誤訊息	
9716
	#$result["founded"],是否找到資料,"true"代表有符合的資料;"false"代表沒有符合的資料.		
9717
	#$result["sql"],執行的sql字串.
9718
	#$result["function"],當前執行的函數名稱.
43 liveuser 9719
	#必填參數:
1 liveuser 9720
	$conf["dbAddress"],字串,爲mysql-Server的位置
9721
	$conf["dbAddress"]="";
9722
	$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
9723
	$conf["dbAccount"]="";
9724
	$conf["selectedDataBaseName"],字串,爲指定的資料庫名稱,欲選擇的資料庫名稱
9725
	$conf["selectedDataBaseName"]="";
9726
	$conf["selectedDataTableName"],字串,欲選擇的資料表名稱
9727
	$conf["selectedDataTableName"]="";
43 liveuser 9728
	#可省略參數:
1 liveuser 9729
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
9730
	#$conf["dbPassword"]=$dbPassword;
9731
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
9732
	#$conf["dbPort"]="";
9733
	#$conf["conditionTargetName"],字串陣列,用來判斷的資料表數值名稱,需爲陣列,可省略
9734
	#$conf["conditionTargetName"]=array("");
9735
	#$conf["conditionTargetValue"],字串陣列,用來判斷的資料表數值名稱若等於該數值,表示條件成立,需爲陣列,可省略
9736
	#$conf["conditionTargetValue"]=array("");
185 liveuser 9737
	#參考資料:
9738
	#無.
43 liveuser 9739
	#備註:
9740
	#無.
1 liveuser 9741
	*/
9742
	public static function checkDataExists($conf){
9743
 
9744
		#初始化要回傳的內容
9745
		$result=array();
9746
 
9747
		#取得當前執行的函數名稱
9748
		$result["function"]=__FUNCTION__;
9749
 
9750
		#如果 $conf 不為陣列
9751
		if(gettype($conf)!="array"){
9752
 
9753
			#設置執行失敗
9754
			$result["status"]="false";
9755
 
9756
			#設置執行錯誤訊息
9757
			$result["error"][]="\$conf變數須為陣列形態";
9758
 
9759
			#如果傳入的參數為 null
9760
			if($conf==null){
9761
 
9762
				#設置執行錯誤訊息
9763
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
9764
 
9765
				}#if end
9766
 
9767
			#回傳結果
9768
			return $result;
9769
 
9770
			}#if end
9771
 
43 liveuser 9772
		#函式說明:
1 liveuser 9773
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 9774
		#回傳結果:
1 liveuser 9775
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
9776
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
9777
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 9778
		#必填參數:
1 liveuser 9779
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
9780
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 9781
		#可省略參數:
1 liveuser 9782
		$conf["variableType"]=array("string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
9783
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
9784
		#備註:
9785
		#功能與checkExistAndType函式相同
9786
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
9787
		unset($conf["variableCheck"]["isexistMuti"]);
9788
 
9789
		#如果檢查失敗
9790
		if($checkResult["status"]=="false"){
9791
 
9792
			#設置錯誤識別
9793
			$result["status"]="false";
9794
 
9795
			#設置錯誤訊息
9796
			$result["error"]=$checkResult;
9797
 
9798
			#回傳結果
9799
			return $result;
9800
 
9801
			}#if end
9802
 
9803
		#如果檢查沒有通過
9804
		if($checkResult["passed"]=="false"){
9805
 
9806
			#設置錯誤識別
9807
			$result["status"]="false";
9808
 
9809
			#設置錯誤訊息
9810
			$result["error"]=$checkResult;
9811
 
9812
			#回傳結果
9813
			return $result;
9814
 
9815
			}#if end
9816
 
9817
		#如果 $conf["conditionTargetName"] 有設定
9818
		if(isset($conf["conditionTargetName"])){
9819
 
9820
			#如果其形態不爲 array
9821
			if(gettype($conf["conditionTargetName"])!="array"){
9822
 
9823
				#設置錯誤識別
9824
				$result["status"]="false";
9825
 
9826
				#設置錯誤訊息
9827
				$result["error"]="\$conf[\"conditionTargetName\"]須爲陣列值";
9828
 
9829
				#回傳結果
9830
				return $result;
9831
 
9832
				}#if end
9833
 
9834
			}#if end
9835
 
9836
		#如果 $conf["conditionTargetValue"] 有設定
9837
		if(isset($conf["conditionTargetValue"])){
9838
 
9839
			#如果其形態不爲 array
9840
			if(gettype($conf["conditionTargetValue"])!="array"){
9841
 
9842
				#設置錯誤識別
9843
				$result["status"]="false";
9844
 
9845
				#設置錯誤訊息
9846
				$result["error"]="\$conf[\"conditionTargetValue\"]須爲陣列值";
9847
 
9848
				#回傳結果
9849
				return $result;
9850
 
9851
				}#if end
9852
 
9853
			}#if end
9854
 
43 liveuser 9855
		#函式說明:
1 liveuser 9856
		#一次取得資料庫、表的資料
43 liveuser 9857
		#回傳結果:
1 liveuser 9858
		#$result["status"],執行結果"true"為成功;"false"為執行失敗。
9859
		#$result["error"],錯誤訊息陣列。
9860
		#$result["dataContent"],爲資料的內容。
9861
		#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
9862
			#$dataSetNum 爲第$dataSetNum+1筆資料
9863
			#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
9864
		#$result["dataCount"],爲取得的資料筆數。
43 liveuser 9865
		#必填參數:
1 liveuser 9866
		$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"];#爲dbServer的位置。
9867
		$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"];#爲登入dbServer的帳號。
9868
		$conf["db"]["fastGetDbData"]["dbName"]=$conf["selectedDataBaseName"];#爲要存取的資料庫名稱
9869
		$conf["db"]["fastGetDbData"]["tableName"]=$conf["selectedDataTableName"];#爲要存取的資料表名稱
9870
		$conf["db"]["fastGetDbData"]["columnYouWant"]=$conf["conditionTargetName"];#你想要的欄位!
43 liveuser 9871
		#可省略參數:
1 liveuser 9872
 
9873
		#如果 $conf["dbPassword"] 有設置
9874
		if(isset($conf["dbPassword"])){
9875
 
9876
			$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"];#爲要存取dbServer的密碼
9877
 
9878
			}#if end
9879
 
9880
		#如果 $conf["dbPort"] 有設置
9881
		if(isset($conf["dbPort"])){
9882
 
9883
			$conf["db"]["fastGetDbData"]["dbPort"]=$conf["dbPort"];#爲要存取dbServer的port
9884
 
9885
			}#if end
9886
 
9887
		$conf["db"]["fastGetDbData"]["WhereColumnName"]=$conf["conditionTargetName"];#用於判斷語句的欄位項目陣列。
9888
		$conf["db"]["fastGetDbData"]["WhereColumnValue"]=$conf["conditionTargetValue"];#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
9889
		#$conf["db"]["fastGetDbData"]["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
9890
		#$conf["db"]["fastGetDbData"]["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
9891
		#$conf["db"]["fastGetDbData"]["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
9892
		#$conf["db"]["fastGetDbData"]["orderItem"]="";#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
9893
		#$conf["db"]["fastGetDbData"]["ascORdesc"]="";#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
9894
		#$conf["db"]["fastGetDbData"]["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
9895
		#$conf["db"]["fastGetDbData"]["numLimit"]="30";#為要取幾筆資料,可以省略,省略則表示不限制數目。
9896
		#$conf["db"]["fastGetDbData"]["groupBy"]=array("");#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
9897
		$dataResult=db::fastGetDbData($conf["db"]["fastGetDbData"]);
9898
		unset($conf["db"]["fastGetDbData"]);
9899
 
9900
		#如果查詢資料失敗
9901
		if($dataResult["status"]=="false"){
9902
 
9903
			#設置錯誤識別
9904
			$result["status"]="false";
9905
 
9906
			#設置錯誤訊息
9907
			$result["error"]=$dataResult;
9908
 
9909
			#回傳結果
9910
			return $result;
9911
 
9912
			}#if end
9913
 
9914
		#取得執行的sql字串
9915
		$result["sql"]=$dataResult["sql"];
9916
 
9917
		#如果 $dataResult["status"] 等於"false"
9918
		if($dataResult["status"]=="false"){
9919
 
9920
			#設置錯誤識別
9921
			$result["status"]="false";
9922
 
9923
			#設置錯誤訊息
9924
			$result["error"]=$dataResult;
9925
 
9926
			#回傳結果
9927
			return $result;
9928
 
9929
			}#if end
9930
 
9931
		#如果$dataResult["dataCount"]沒設定,就表示沒找到相符的資料
9932
		if(!isset($dataResult["dataCount"])){
9933
 
9934
			#設置錯誤識別
9935
			$result["status"]="true";
9936
 
9937
			#設置沒有找到符合資料
9938
			$result["founded"]="false";
9939
 
9940
			#回傳結果
9941
			return $result;
9942
 
9943
			}#if end
9944
 
9945
		#如果符合的資料等於0
9946
		if($dataResult["dataCount"]==0){
9947
 
9948
			#設置錯誤識別
9949
			$result["status"]="true";
9950
 
9951
			#設置沒有找到符合資料
9952
			$result["founded"]="false";
9953
 
9954
			#回傳結果
9955
			return $result;
9956
 
9957
			}#if end
9958
 
9959
		#執行到這邊代表執行成功
9960
		$result["status"]="true";
9961
 
9962
		#設置有找到符合資料
9963
		$result["founded"]="true";
9964
 
9965
		#回傳結果
9966
		return $result;
9967
 
9968
		}#function checkDataExists
9969
 
9970
	/*
43 liveuser 9971
	#函式說明:
1 liveuser 9972
	#檢查資料表是否存在
43 liveuser 9973
	#回傳結果::
1 liveuser 9974
	#設置執行錯誤的識別
9975
	#$result["status"],"true"代表執行成功;"false"代表執行失敗.
9976
	#$result["error"],錯誤訊息.
9977
	#$result["founded"],是否有有找到相同的,"true"代表有找到符合的資料;"false"代表沒有符合的資料.
9978
	#$result["function"],當前執行的函數名稱.
9979
	#$result["argu"],使用的參數
9980
	#其餘的結果代表參數不正確
43 liveuser 9981
	#必填參數:
1 liveuser 9982
	#$conf["dbAddress"],字串,爲mysql-Server的位置
9983
	$conf["dbAddress"]=$dbAddress;
9984
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
9985
	$conf["dbAccount"]=$dbAccount;
9986
	#$conf["selectedDataBaseName"],字串,爲指定的資料庫名稱
9987
	$conf["selectedDataBaseName"]="";
9988
	#$conf["selectedDataTableName"],字串,為要檢查是否存在的資料表名稱
9989
	$conf["selectedDataTableName"]="";
43 liveuser 9990
	#可省略參數
1 liveuser 9991
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼 
9992
	#$conf["dbPassword"]=$dbPassword;
9993
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
9994
	#$conf["dbPort"]="";
185 liveuser 9995
	#參考資料:
9996
	#無.
43 liveuser 9997
	#備註:
9998
	#無.
1 liveuser 9999
	*/
10000
	public static function checkDataTableExists($conf){
10001
 
10002
		#初始化要回傳的變數
10003
		$result=array();
10004
 
10005
		#取得當前執行的函數名稱
10006
		$result["function"]=__FUNCTION__;
10007
 
10008
		#如果 $conf 不為陣列
10009
		if(gettype($conf)!="array"){
10010
 
10011
			#設置執行失敗
10012
			$result["status"]="false";
10013
 
10014
			#設置執行錯誤訊息
10015
			$result["error"][]="\$conf變數須為陣列形態";
10016
 
10017
			#如果傳入的參數為 null
10018
			if($conf==null){
10019
 
10020
				#設置執行錯誤訊息
10021
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
10022
 
10023
				}#if end
10024
 
10025
			#回傳結果
10026
			return $result;
10027
 
10028
			}#if end
10029
 
10030
		#取得參數
10031
		$result["argu"]=$conf;
10032
 
43 liveuser 10033
		#函式說明:
1 liveuser 10034
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 10035
		#回傳結果:
1 liveuser 10036
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10037
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10038
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 10039
		#必填參數:
1 liveuser 10040
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
10041
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 10042
		#可省略參數:
1 liveuser 10043
		$conf["variableType"]=array("string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
10044
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
10045
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
10046
		unset($conf["variableCheck"]["isexistMuti"]);
10047
 
10048
		#var_dump($checkResult);
10049
 
10050
		#如果檢查不通過
10051
		if($checkResult["passed"]=="false"){
10052
 
10053
			#設置執行錯誤的識別
10054
			$result["status"]="false";
10055
 
10056
			#設置錯誤訊息
10057
			$result["error"]=$checkResult;
10058
 
10059
			#回傳結果
10060
			return $result;
10061
 
10062
			}#if end
10063
 
10064
		#查詢特定資料庫裡的資料表列表,會回傳查詢的結果
10065
		#$result["status"],若成功則爲0,失敗則爲1。
10066
		#$result["error"],錯誤訊息陣列.
10067
		#$result["tableName"] 爲查詢的資料庫名稱陣列,
10068
			#第一筆資料庫名稱爲$result["tableName"][0],
10069
			#第二筆資料庫名稱爲$result["tableName"][1],
10070
			#其餘以此類推。
10071
		#$result["dataCounts"] 爲資料庫的總筆數
43 liveuser 10072
		#必填參數:
1 liveuser 10073
		$conf["db"]["getDataTableList"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
10074
		$conf["db"]["getDataTableList"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
10075
		$conf["db"]["getDataTableList"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲指定的資料庫名稱
43 liveuser 10076
		#可省略參數:
1 liveuser 10077
 
10078
		#如果 $conf["dbPassword"] 有設定
10079
		if(isset($conf["dbPassword"])){
10080
 
10081
			#設定連線時要用的密碼
10082
			$conf["db"]["getDataTableList"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
10083
 
10084
			}#if end
10085
 
10086
		#如果 $conf["dbPort"] 有設定
10087
		if(isset($conf["dbPort"])){
10088
 
10089
			#設定連線時要用的密碼
10090
			$conf["db"]["getDataTableList"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
10091
 
10092
			}#if end		
10093
 
10094
		#原始語法:
10095
		#show tables FROM databaseName,代表檢視databaseName裡面的資料表清單。
10096
		$dataTableList=db::getDataTableList($conf["db"]["getDataTableList"]);
10097
		unset($conf["db"]["getDataTableList"]);
10098
 
10099
		#如果調閱資料表清單出錯
10100
		if($dataTableList["status"]=="false"){
10101
 
10102
			#設置錯誤識別
10103
			$result["status"]="false";
10104
 
10105
			#設置錯誤訊息
10106
			$result["error"]=$dataTableList;
10107
 
10108
			#回傳結果
10109
			return $result;
10110
 
10111
			}#if end
10112
 
10113
		#如果裡面沒有任何1個資料表
10114
		if($dataTableList["dataCounts"]==0){
10115
 
10116
			#設置執行成功的識別
10117
			$result["status"]="true";
10118
 
10119
			#設置有找到相同的
10120
			$result["founded"]="false";
10121
 
10122
			#回傳結果
10123
			return $result;
10124
 
10125
			}#if end
10126
 
43 liveuser 10127
		#函式說明:
1 liveuser 10128
		#檢查一個數值是否與陣列裏面的元素相同
43 liveuser 10129
		#回傳結果::
1 liveuser 10130
		#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
10131
		#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
10132
		#$result["error"],錯誤訊息
10133
		#$result["function"],當前執行的函數名稱
10134
		#$result["argv"],使用的參數
10135
		#$result["equalVarName"],相等的變數名稱或key.
10136
		#$result["equalVarValue"],相等的變數數值內容.
43 liveuser 10137
		#必填參數:
1 liveuser 10138
		$conf["search"]["getEqualVar"]["conditionElement"]=$conf["selectedDataTableName"];#條件元素,要等於的元素內容。
10139
		$conf["search"]["getEqualVar"]["compareElements"]=$dataTableList["tableName"];#要比對的陣列變數內容。
10140
		$checkResult=search::getEqualVar($conf["search"]["getEqualVar"]);
10141
		unset($conf["search"]["getEqualVar"]);
10142
 
10143
		#如果有找到相同的元素
10144
		if($checkResult["founded"]==="true"){
10145
 
10146
			#設置執行成功的識別
10147
			$result["status"]="true";
10148
 
10149
			#設置有找到相同的
10150
			$result["founded"]="true";
10151
 
10152
			#回傳結果
10153
			return $result;
10154
 
10155
			}#if end
10156
 
10157
		#如果沒有找到相同的元素
10158
		if($checkResult["founded"]==="false"){
10159
 
10160
			#設置執行成功的識別
10161
			$result["status"]="true";
10162
 
10163
			#設置有找到相同的
10164
			$result["founded"]="false";
10165
 
10166
			#回傳結果
10167
			return $result;
10168
 
10169
			}#if end
10170
 
10171
		#不應該執行到這邊
10172
 
10173
		#設置執行失敗
10174
		$result["status"]="false";
10175
 
10176
		#設置執行錯誤
10177
		$result["error"]="不應該出現的例外狀況";
10178
 
10179
		#回傳結果
10180
		return $result;
10181
 
10182
		}#funcrion checkDataTableExists end
10183
 
10184
	/*
43 liveuser 10185
	#函式說明:
1 liveuser 10186
	#檢查資料表的欄位是否存在
43 liveuser 10187
	#回傳結果::
1 liveuser 10188
	#設置執行錯誤的識別
10189
	#$result["function"],當前執行的函數名稱.
10190
	#$result["status"],"true"代表執行成功;"false"代表執行失敗.
10191
	#$result["error"],錯誤訊息.
10192
	#$result["warning"],警告訊息陣列
10193
	#$result["passed"],是否通過檢查,"true"代表通過;"false"代表不通過.
10194
	#其餘的結果代表參數不正確
43 liveuser 10195
	#必填參數:
1 liveuser 10196
	#$conf["dbAddr"],字串,爲mysql-Server的位置
10197
	$conf["dbAddr"]=$dbAddress; 
10198
	#$conf["dbAcct"],字串,爲用於連入mysql-Server時要使用的帳號
10199
	$conf["dbAcct"]=$dbAccount;
10200
	#$conf["dbName"],字串,爲指定的資料庫名稱
10201
	$conf["dbName"]="";
10202
	#$conf["dtName"],字串,為要檢查是否存在的資料表名稱
10203
	$conf["dtName"]="";
10204
	#$conf["col"],字串陣列,要檢查的欄位名稱.
10205
	$conf["col"]=array();
43 liveuser 10206
	#可省略參數
1 liveuser 10207
	#$conf["dbPass"],爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼 
10208
	#$conf["dbPass"]=$dbPassword;
10209
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
10210
	#$conf["dbPort"]="";
185 liveuser 10211
	#參考資料:
10212
	#無.
43 liveuser 10213
	#備註:
10214
	#無.
1 liveuser 10215
	*/
10216
	public static function checkTableColExists(&$conf=array()){
10217
 
10218
		#初始化要回傳的結果
10219
		$result=array();
10220
 
10221
		#取得當前執行的函數名稱
10222
		$result["function"]=__FUNCTION__;
10223
 
10224
		#如果沒有參數
10225
		if(func_num_args()==0){
10226
 
10227
			#設置執行失敗
10228
			$result["status"]="false";
10229
 
10230
			#設置執行錯誤訊息
10231
			$result["error"]="函數".$result["function"]."需要參數";
10232
 
10233
			#回傳結果
10234
			return $result;
10235
 
10236
			}#if end
10237
 
10238
		#取得參數
10239
		$result["argu"]=$conf;
10240
 
10241
		#如果 $conf 不為陣列
10242
		if(gettype($conf)!=="array"){
10243
 
10244
			#設置執行失敗
10245
			$result["status"]="false";
10246
 
10247
			#設置執行錯誤訊息
10248
			$result["error"][]="\$conf變數須為陣列形態";
10249
 
10250
			#如果傳入的參數為 null
10251
			if($conf===null){
10252
 
10253
				#設置執行錯誤訊息
10254
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
10255
 
10256
				}#if end
10257
 
10258
			#回傳結果
10259
			return $result;
10260
 
10261
			}#if end
10262
 
10263
		#函式說明:
10264
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
10265
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10266
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
10267
		#$result["function"],當前執行的函式名稱.
10268
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10269
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10270
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10271
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
10272
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
10273
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
10274
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
10275
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
43 liveuser 10276
		#必填參數:
1 liveuser 10277
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10278
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;	
10279
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10280
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
10281
		#可以省略的參數:
10282
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10283
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddr","dbName","dbAcct","dtName","col");
10284
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
10285
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","array");
10286
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
10287
		#$conf["canBeEmptyString"]="false";
10288
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
10289
		#$conf["canNotBeEmpty"]=array();
10290
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
10291
		#$conf["canBeEmpty"]=array();
10292
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
10293
		#$conf["skipableVariableCanNotBeEmpty"]=array();
10294
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
10295
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPass","dbPort");
10296
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
10297
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
10298
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
10299
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null);
10300
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
10301
		#$conf["disallowAllSkipableVarIsEmpty"]="";
10302
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
10303
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
10304
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10305
		#$conf["arrayCountEqualCheck"][]=array();
43 liveuser 10306
		#參考資料:
1 liveuser 10307
		#array_keys=>http://php.net/manual/en/function.array-keys.php
10308
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10309
		unset($conf["variableCheck::checkArguments"]);
10310
 
10311
		#如果檢查失敗
10312
		if($checkArguments["status"]==="false"){
10313
 
10314
			#設置執行失敗
10315
			$result["status"]="false";
10316
 
10317
			#設置錯誤訊息
10318
			$result["error"]=$checkArguments["error"];
10319
 
10320
			#回傳結果
10321
			return $result;
10322
 
10323
			}#if  end
10324
 
10325
		#如果檢查不通過
10326
		if($checkArguments["passed"]==="false"){
10327
 
10328
			#設置執行失敗
10329
			$result["status"]="false";
10330
 
10331
			#設置錯誤訊息
10332
			$result["error"]=$checkArguments["error"];
10333
 
10334
			#回傳結果
10335
			return $result;
10336
 
10337
			}#if  end
10338
 
43 liveuser 10339
		#函式說明:
1 liveuser 10340
		#取得資料表所有欄位的詳細資訊
10341
		#回傳的內容:
10342
		#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
10343
		#$result["error"],錯誤訊息陣列
10344
		#$result["function"],當前執行的函數名稱.
10345
		#$result["sql"],執行的sql語法
10346
		#$result["oriInput"],原始的資料表欄位資訊
10347
		#$result["everyLine"],逐行的欄位資訊
10348
		#$result["tableName"],當前查詢的資料表名稱
10349
		#$result["engine"],資料表使用的儲存引擎
10350
		#$result["charset"],資料表預設的編碼
10351
		#$result["columnName"][$i],各欄位的名稱陣列,$i爲1開始的數字,也可以使用欄位的名稱。
10352
		#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲1開始的數字,也可以使用欄位的名稱。
10353
		#$result["columnVarType"][$i],各欄位變數儲存的型態,$i爲1開始的數字,也可以使用欄位的名稱.
10354
		#$result["columnVarLengthLimit"][$i],個欄位變數的長度限制,若不存在其限制,則為"",$i爲1開始的數字,也可以使用欄位的名稱.
10355
		#$result["columnNotNull"][$i],各欄位是否不可爲null,"true"爲不可以爲null;"false"爲可爲"null",$i爲1開始的數字,也可以使用欄位的名稱。
10356
		#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲1開始的數字,也可以使用欄位的名稱。
10357
		#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲1開始的數字,也可以使用欄位的名稱。
10358
		#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲1開始的數字,也可以使用欄位的名稱。
10359
		#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲1開始的數字,也可以使用欄位的名稱。
10360
		#$result["columnCollate"][$i],各欄位使用的Collate,$i爲1開始的數字,也可以使用欄位的名稱。
10361
		#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
10362
		#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
10363
		#$result["keyConstraintName"][$j],該資料表用於識別索引鍵的CONSTRAINT名稱陣列,$j爲1開始的數字,也可以使用欄位的名稱。
10364
		#$result["primaryKey"],該資料表的主鍵
10365
		#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
10366
		#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
10367
		#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
10368
		#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲1開始的數字,,也可用欄位的名稱來找value.
10369
		#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲1開始的數字,也可用欄位的名稱來找value.
10370
		#$result["foreignKey"]["onUpdateAction"][$i],當參照的欄位資料更新時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
10371
		#$result["foreignKey"]["onDeleteAction"][$i],當參照的欄位資料移除時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
43 liveuser 10372
		#必填參數:
1 liveuser 10373
		$conf["db::getDataTableColumn"]["dbAddress"]=$conf["dbAddr"];#資料庫的網路位置
10374
		$conf["db::getDataTableColumn"]["dbAccount"]=$conf["dbAcct"];#連線到資料庫要用的帳號
10375
		$conf["db::getDataTableColumn"]["selectedDataBase"]=$conf["dbName"];#連線到資料庫要選擇的資料庫
10376
		$conf["db::getDataTableColumn"]["selectedDataTable"]=$conf["dtName"];#連線到資料庫要檢視的資料表
43 liveuser 10377
		#可省略參數:
1 liveuser 10378
		if(isset($conf["dbPass"])){
10379
 
10380
			#$conf["dbPassword"]=$dbPassword;#連線到資料庫要用的密碼
10381
			$conf["db::getDataTableColumn"]["dbPassword"]=$conf["dbPass"];
10382
 
10383
			}#if end
10384
 
10385
		#如果有設置 $conf["dbPort"]
10386
		if(isset($conf["dbPort"])){
10387
 
10388
			#$conf["dbPort"]=$dbPort;#連線到資料庫要用的port
10389
			$conf["db::getDataTableColumn"]["dbPort"]=$conf["dbPass"];
10390
 
10391
			}#if end
10392
 
10393
		#備註:
10394
		#查詢的功能有點弱,目前用getTableColumnDetailInfo替代
10395
		$getDataTableColumn=db::getDataTableColumn($conf["db::getDataTableColumn"]);
10396
		unset($conf["db::getDataTableColumn"]);
10397
 
10398
		#如果查詢失敗
10399
		if($getDataTableColumn["status"]==="false"){
10400
 
10401
			#設置執行失敗
10402
			$result["status"]="false";
10403
 
10404
			#設置錯誤訊息
10405
			$result["error"]=$getDataTableColumn["error"];
10406
 
10407
			#回傳結果
10408
			return $result;
10409
 
10410
			}#if end
10411
 
10412
		#初始化通過檢查
10413
		$result["passed"]="true";
10414
 
10415
		#針對每個要檢查的欄位
10416
		foreach($conf["col"] as $colName){
10417
 
10418
			#如果欄位 $colName 不存在
10419
			if(!in_array($colName,$getDataTableColumn["columnName"])){
10420
 
10421
				#設置欄位不存在的警告訊息
10422
				$result["warning"][]="欄位 ".$colName." 不存在";
10423
 
10424
				#設置未通過檢查
10425
				$result["passed"]="false";
10426
 
10427
				}#if end
10428
 
10429
			}#foreach end
10430
 
10431
		#設置執行正常
10432
		$result["status"]="true";
10433
 
10434
		#回傳結果
10435
		return $result;
10436
 
10437
		}#function checkTableColExists end
10438
 
10439
	/*
43 liveuser 10440
	#函式說明:
1 liveuser 10441
	#檢查該資料庫是否存在,結果會回傳一個陣列。
10442
	#回傳結果:
10443
	#$result["status"],"true"代表執行成功;"false"代表執行失敗.
10444
	#$result["error"],錯誤訊息.
10445
	#$result["exist"],有為"true",無為"false".
10446
	#$result["function"],當前執行的函數名稱.
43 liveuser 10447
	#必填參數:
1 liveuser 10448
	$conf["dbAddress"],字串,爲mysql-Server的位置
10449
	$conf["dbAddress"]=$dbAddress;
10450
	$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
10451
	$conf["dbAccount"]=$dbAccount;
10452
	$conf["checkDataBaseName"],字串,爲要檢查是否存在的資料庫名稱
10453
	$conf["checkDataBaseName"]="";
43 liveuser 10454
	#可省略參數:
1 liveuser 10455
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
10456
	#$conf["dbPassword"]="";
10457
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
10458
	#$conf["dbPort"]="";
185 liveuser 10459
	#參考資料:
10460
	#無.
43 liveuser 10461
	#備註:
10462
	#無.
1 liveuser 10463
	*/	
10464
	public static function checkDataBaseExists($conf){
10465
 
10466
		#初始化要回傳的變數
10467
		$result=array();
10468
 
10469
		#紀錄當前執行的函數名稱
10470
		$result["function"]=__FUNCTION__;
10471
 
10472
		#如果 $conf 不為陣列
10473
		if(gettype($conf)!="array"){
10474
 
10475
			#設置執行失敗
10476
			$result["status"]="false";
10477
 
10478
			#設置執行錯誤訊息
10479
			$result["error"][]="\$conf變數須為陣列形態";
10480
 
10481
			#如果傳入的參數為 null
10482
			if($conf==null){
10483
 
10484
				#設置執行錯誤訊息
10485
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
10486
 
10487
				}#if end
10488
 
10489
			#回傳結果
10490
			return $result;
10491
 
10492
			}#if end
10493
 
10494
		#檢查參數
43 liveuser 10495
		#函式說明:
1 liveuser 10496
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 10497
		#回傳結果:
1 liveuser 10498
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10499
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10500
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 10501
		#必填參數:
1 liveuser 10502
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
10503
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","checkDataBaseName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 10504
		#可省略參數:
1 liveuser 10505
		#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
10506
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
10507
		#備註:
10508
		#功能與checkExistAndType函式相同
10509
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
10510
		unset($conf["variableCheck"]["isexistMuti"]);
10511
 
10512
		#如果 $checkResult["status"] 等於 "false"
10513
		if($checkResult["status"]=="false"){
10514
 
10515
			#設置執行失敗
10516
			$result["status"]="false";
10517
 
10518
			#設置執行錯誤
10519
			$result["error"]=$checkResult;
10520
 
10521
			#回傳結果
10522
			return $result;
10523
 
10524
			}#if end	
10525
 
10526
		#如果 $checkResult["passed"] 等於 "false"
10527
		if($checkResult["passed"]=="false"){
10528
 
10529
			#設置執行失敗
10530
			$result["status"]="false";
10531
 
10532
			#設置執行錯誤
10533
			$result["error"]=$checkResult;
10534
 
10535
			#回傳結果
10536
			return $result;
10537
 
10538
			}#if end
10539
 
10540
		#取得資料庫列表的語法
10541
		#查詢所有的資料庫列表,會回傳查詢的結果
10542
		#$result["status"],執行是否正常,"true"為正常,"fasle"為不正常
10543
		#$result["error"],爲錯誤訊息
10544
		#$result["connectInformation"],爲回傳的mysql連線資訊。
10545
		#$result["dbName"] 爲查詢的資料庫名稱陣列,第一筆資料庫名稱爲$result["dbName"][0],第二筆資料庫名稱爲$result["dbName"][1],其餘以此類推。
10546
		#$result["dbCounts"] 爲資料庫的總筆數	
43 liveuser 10547
		#必填參數:
1 liveuser 10548
		$conf["db"]["getDataBaseList"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
10549
		$conf["db"]["getDataBaseList"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
43 liveuser 10550
		#可省略參數:
1 liveuser 10551
 
10552
		#如果 $conf["dbPassword"] 有設定
10553
		if(isset($conf["dbPassword"])){
10554
 
10555
			$conf["db"]["getDataBaseList"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
10556
 
10557
			}#if end
10558
 
10559
		#如果 $conf["dbPort"] 有設定
10560
		if(isset($conf["dbPort"])){
10561
 
10562
			$conf["db"]["getDataBaseList"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的3306.
10563
 
10564
			}#if end
10565
 
10566
		$queryResult=db::getDataBaseList($conf["db"]["getDataBaseList"]);
10567
		unset($conf["db"]["getDataBaseList"]);
10568
 
10569
		#如果 $queryResult["status"] 等於 "fasle"
10570
		if($queryResult["status"]=="false"){
10571
 
10572
			#設置錯誤識別
10573
			$result["status"]="false";
10574
 
10575
			#設置錯誤訊息
10576
			$result["error"]=$queryResult;
10577
 
10578
			#回傳結果
10579
			return $result;
10580
 
10581
			}#if end
10582
 
10583
		#有幾個資料庫就檢查該名稱有沒有重複
10584
		for($i=0;$i<$queryResult["dbCounts"];$i++){
10585
 
10586
			#檢查名稱是否相同			
10587
			if($queryResult["dbName"][$i]==$conf["checkDataBaseName"]){
10588
 
10589
				#相同名稱代表資料庫重複
10590
				$result["exist"]="true";
10591
 
10592
				#跳出迴圈
10593
				break;
10594
 
10595
				}#判斷式結束
10596
 
10597
			}#迴圈結束
10598
 
10599
		#如果 $result["exist"] 沒有設定
10600
		if(!isset($result["exist"])){
10601
 
10602
			#代表都沒有相同的名稱就代表沒有重複
10603
			$result["exist"]="false";
10604
 
10605
			}#if end
10606
 
10607
		#執行到這邊代表執行正常
10608
		$result["status"]="true";
10609
 
10610
		#回傳結果
10611
		return $result;	
10612
 
10613
		}#function end
10614
 
10615
	/*
43 liveuser 10616
	#函式說明:
1 liveuser 10617
	#尋找特定資料庫裏特定資料表裏面特定欄位有無可用整數編號,可以指定數字的起點與終點,此函式會回傳可用的編號。
10618
	#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10619
	#$result["error"],錯誤訊息陣列 
10620
	#$result["function"],當前執行的函數.
10621
	#$result["founded"],爲搜尋可以用的數字是否成功,"true"表示成功,"false"表示失敗.
10622
	#$result["usableNumber"],爲可用的整數。
10623
	#$result["sql"],執行的sql語法.
43 liveuser 10624
	#必填參數:
1 liveuser 10625
	#$conf["dbAddress"],字串,爲mysql-Server的位置.
10626
	$conf["dbAddress"]=$dbAddress;
10627
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
10628
	$conf["dbAccount"]=$dbAccount;
10629
	#$conf["selectedDataBaseName"],字串,爲要檢查的資料庫名稱
10630
	$conf["selectedDataBaseName"]=$dbName;
10631
	#$conf["checkDataTableName"],字串,爲要檢查的資料表名稱
10632
	$conf["checkDataTableName"]="";
10633
	#$conf["conditionTargetName"]字串,用來判斷的資料表數值名稱
10634
	$conf["conditionTargetName"]="";
10635
	#$conf["startPoint"],字串,要執行的迴圈起點(資料的起始檢查點),須為整數.
10636
	$conf["startPoint"]="";
10637
	#$conf["endPoint"],字串,要執行的迴圈終點(資料的結束檢查點),須為整數.
10638
	$conf["endPoint"]="";
43 liveuser 10639
	#可省略參數:
1 liveuser 10640
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
10641
	#$conf["dbPassword"]=$dbPassword;
10642
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
10643
	#$conf["dbPort"]="";
185 liveuser 10644
	#$conf["otherConditionTargetName"]=array();#查詢欄位項目可用數值的其它條件欄位名稱,爲陣列值。須搭配 $conf["otherConditionTargetValue"] 一起使用
1 liveuser 10645
	#$conf["otherConditionTargetName"]=array();
185 liveuser 10646
	#$conf["otherConditionTargetValue"]=array();#查詢欄位項目可用數值的其它條件欄位數值,爲陣列值。須搭配 $conf["otherConditionTargetName"] 一起使用
1 liveuser 10647
	#$conf["otherConditionTargetValue"]=array();
185 liveuser 10648
	#參考資料:
10649
	#無.
43 liveuser 10650
	#備註:
10651
	#無.
1 liveuser 10652
	*/
10653
	public static function findUsableNumber($conf){
10654
 
10655
		#初始化要回傳的內容
10656
		$result=array();
10657
 
10658
		#取得當前執行的函數名稱
10659
		$result["function"]=__FUNCTION__;
10660
 
10661
		#如果 $conf 不為陣列
10662
		if(gettype($conf)!="array"){
10663
 
10664
			#設置執行失敗
10665
			$result["status"]="false";
10666
 
10667
			#設置執行錯誤訊息
10668
			$result["error"][]="\$conf變數須為陣列形態";
10669
 
10670
			#如果傳入的參數為 null
10671
			if($conf==null){
10672
 
10673
				#設置執行錯誤訊息
10674
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
10675
 
10676
				}#if end
10677
 
10678
			#回傳結果
10679
			return $result;
10680
 
10681
			}#if end
10682
 
10683
		#可用號碼的預設值,用int型態儲存.
10684
		(int)$userableNumber=0;
10685
 
43 liveuser 10686
		#函式說明:
1 liveuser 10687
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 10688
		#回傳結果:
1 liveuser 10689
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10690
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10691
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10692
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 10693
		#必填參數:
1 liveuser 10694
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
10695
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","checkDataTableName","conditionTargetName","startPoint","endPoint");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 10696
		#可省略參數:
1 liveuser 10697
		$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string","string","string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
10698
		#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
10699
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
10700
		unset($conf["variableCheck"]["isexistMuti"]);
10701
 
10702
		#如果 $checkResult["status"] 等於 "false"
10703
		if($checkResult["status"]=="false"){
10704
 
10705
			#設置錯誤識別
10706
			$result["status"]="false";
10707
 
10708
			#設置錯誤訊息
10709
			$result["error"]=$checkResult;
10710
 
10711
			#回傳結果
10712
			return $result;
10713
 
10714
			}#if end
10715
 
10716
		#如果 $checkResult["passed"] 等於 "false"
10717
		if($checkResult["passed"]=="false"){
10718
 
10719
			#設置錯誤識別
10720
			$result["status"]="false";
10721
 
10722
			#設置錯誤訊息
10723
			$result["error"]=$checkResult;
10724
 
10725
			#回傳結果
10726
			return $result;
10727
 
10728
			}#if end
10729
 
10730
		#從$startPoint開始到$endPoint結束,供執行 $endPoint-$startPoint 次。
10731
		for($i=$conf["startPoint"];$i<=$conf["endPoint"];$i++){
10732
 
10733
			#更新可用號碼
10734
			$userableNumber=$i;
10735
 
10736
			#查詢目標號碼是否已存在
43 liveuser 10737
			#函式說明:
1 liveuser 10738
			#一次取得資料庫、表的資料
43 liveuser 10739
			#回傳結果:
1 liveuser 10740
			#$result["status"],執行結果"true"為成功;"false"為執行失敗。
10741
			#$result["error"],錯誤訊息陣列。
10742
			#$result["dataContent"],爲資料的內容。
10743
			#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
10744
				#$dataSetNum 爲第$dataSetNum+1筆資料
10745
				#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
10746
			#$result["dataCount"],爲取得的資料筆數。
10747
			#$result["sql"],執行的sql字串.
43 liveuser 10748
			#必填參數:
1 liveuser 10749
			$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"];#爲dbServer的位置。
10750
			$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"];#爲登入dbServer的帳號。
10751
			$conf["db"]["fastGetDbData"]["dbName"]=$conf["selectedDataBaseName"];#爲要存取的資料庫名稱
10752
			$conf["db"]["fastGetDbData"]["tableName"]=$conf["checkDataTableName"];#爲要存取的資料表名稱
10753
			$conf["db"]["fastGetDbData"]["columnYouWant"]=array($conf["conditionTargetName"]);#你想要的欄位!
43 liveuser 10754
			#可省略參數:
1 liveuser 10755
 
10756
			#如果 $conf["dbPassword"] 有設置
10757
			if(isset($conf["dbPassword"])){
10758
 
10759
				$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"];#爲要存取dbServer的密碼
10760
 
10761
				}#if end
10762
 
10763
			#如果 $conf["dbPort"] 有設置
10764
			if(isset($conf["dbPort"])){
10765
 
10766
				$conf["db"]["fastGetDbData"]["dbPort"]=$conf["dbPort"];#爲要存取dbServer的port
10767
 
10768
				}#if end
10769
 
10770
			#要檢查可用數字的欄位為塞選的欄位
10771
			$conf["db"]["fastGetDbData"]["WhereColumnName"][]=$conf["conditionTargetName"];
10772
 
10773
			#如果 $conf["otherConditionTargetName"] 有設置
10774
			if(isset($conf["otherConditionTargetName"])){
10775
 
10776
				#針對 $conf["otherConditionTargetName"] 的每個元素 
10777
				foreach($conf["otherConditionTargetName"] as $columnName){
10778
 
10779
					$conf["db"]["fastGetDbData"]["WhereColumnName"][]=$columnName;#用於判斷語句的欄位項目陣列.
10780
 
10781
					}#foreach end
10782
 
10783
				}#if end
10784
 
10785
			#要檢查可用數字的欄位數值為塞選的欄位對應數值
10786
			$conf["db"]["fastGetDbData"]["WhereColumnValue"][]=$userableNumber;
10787
 
10788
			#如果 $conf["otherConditionTargetValue"] 有設置
10789
			if(isset($conf["otherConditionTargetValue"])){
10790
 
10791
				#針對每個 $conf["otherConditionTargetValue"] 元素
10792
				foreach($conf["otherConditionTargetValue"] as $columnValue){
10793
 
10794
					$conf["db"]["fastGetDbData"]["WhereColumnValue"][]=$columnValue;#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容.
10795
 
10796
					}#foreach end
10797
 
10798
				}#if end
10799
 
10800
			#$conf["db"]["fastGetDbData"]["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
10801
			#$conf["db"]["fastGetDbData"]["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
10802
			#$conf["db"]["fastGetDbData"]["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
10803
			#$conf["db"]["fastGetDbData"]["orderItem"]="";#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
10804
			#$conf["db"]["fastGetDbData"]["ascORdesc"]="";#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
10805
			#$conf["db"]["fastGetDbData"]["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
10806
			#$conf["db"]["fastGetDbData"]["numLimit"]="30";#為要取幾筆資料,可以省略,省略則表示不限制數目。
10807
			#$conf["db"]["fastGetDbData"]["groupBy"]=array("");#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
10808
			$db["fastGetDbData"]=db::fastGetDbData($conf["db"]["fastGetDbData"]);
10809
			unset($conf["db"]["fastGetDbData"]);
10810
 
10811
			#如果取得資料失敗
10812
			if($db["fastGetDbData"]["status"]=="false"){
10813
 
10814
				#設置錯誤識別
10815
				$result["status"]="false";
10816
 
10817
				#設置錯誤訊息
10818
				$result["error"]=$db["fastGetDbData"];
10819
 
10820
				#回傳結果
10821
				return $result;
10822
 
10823
				}#if end
10824
 
10825
			#如果該條件下沒有符合的資料
10826
			if($db["fastGetDbData"]["dataCount"]==0){
10827
 
10828
				#取得可用的編號
10829
				$result["usableNumber"]=$i;
10830
 
10831
				#設置有找到符合的數字
10832
				$result["founded"]="true";
10833
 
10834
				#跳出迴圈
10835
				break;
10836
 
10837
				}#if end
10838
 
10839
			#反之該條件下有符合的資料
10840
			else{
10841
 
10842
				#設置沒有找到符合的數字
10843
				$result["founded"]="false";
10844
 
10845
				}#else end
10846
 
10847
			}#for end
10848
 
10849
		#執行到這邊代表執行正常
10850
		$result["status"]="true";
10851
 
10852
		#回傳結果
10853
		return $result;
10854
 
10855
		}#function findUsableNumber end
10856
 
10857
	/*
43 liveuser 10858
	#函式說明:
1 liveuser 10859
	#取得特定的資料表資料
10860
	#回傳的參數:
10861
	#$result["status"],執行結果"true"為成功;"false"為執行失敗。
10862
	#$result["error"],錯誤訊息陣列。
10863
	#$result["function"],當前執行的函數名稱
10864
	#$result["sql"],執行的sql語法
10865
	#$result["sqlQueryResult"]#爲資料連線處理完畢之後的結果,需要 sendQueryDataToVariabele 涵式來解析。
10866
	#$result["dataCount"]#符合條件的資料筆數
43 liveuser 10867
	#必填參數:
1 liveuser 10868
	#$conf["dbAddress"],字串,爲mysql-Server的位置。
10869
	$conf["dbAddress"]=$dbAddress;
10870
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號。
10871
	$conf["dbAccount"]=$dbAccount;
10872
	#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱。
10873
	$conf["selectedDataBaseName"]=$dbName;
10874
	#$conf["selectedDataTableName"],字串,爲欲選擇的資料表名稱。
10875
	$conf["selectedDataTableName"]="";
43 liveuser 10876
	#可省略參數:	
1 liveuser 10877
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
10878
	#$conf["dbPassword"]=$dbPassword;
10879
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
10880
	#$conf["dbPort"]="";
10881
	#$conf["WhereColumnCombine"],字串陣列,用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
10882
	#$conf["WhereColumnCombine"]=array("");
10883
	#$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。
10884
	#$conf["WhereColumnName"]=array("");
10885
	#$conf["WhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
10886
	#$conf["WhereColumnOperator"]=array("");
10887
	#$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
10888
	#$conf["WhereColumnValue"]=array("");
10889
	#$conf["WhereColumnAndOr"],字串陣列,用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
10890
	#$conf["WhereColumnAndOr"]=array("");
10891
	#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
10892
	#$conf["whereIn"]=array(array("colName",array("a","b","c")));
10893
	#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
10894
	#$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
10895
	#$conf["orderItem"],字串,爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
10896
	#$conf["orderItem"]="";
10897
	#$conf["ascORdesc"],字串,爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
10898
	#$conf["ascORdesc"]="";
10899
	#$conf["numberStart"],字串,為從第幾筆開始讀取,預設為0,代筆第一筆。
10900
	#$conf["numberStart"]="0";
10901
	#$conf["number"],字串,為要取幾筆資料,可以省略,省略則表示不限制數目。
10902
	#$conf["number"]="30"
10903
	#$conf["groupBy"],字串陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
10904
	#$conf["groupBy"]=array("");
10905
	#參考資料:
10906
	#http://stackoverflow.com/questions/5021243/mysql-query-multiple-group-by
43 liveuser 10907
	#備註:
10908
	#無.
1 liveuser 10909
	*/
10910
	public static function dataTableSelect(&$conf){
10911
 
10912
		#初始化要回傳的變數
10913
		$result=array();
10914
 
10915
		#取得當前執行的函數名稱
10916
		$result["function"]=__FUNCTION__;
10917
 
10918
		#如果 $conf 不為陣列
10919
		if(gettype($conf)!="array"){
10920
 
10921
			#設置執行失敗
10922
			$result["status"]="false";
10923
 
10924
			#設置執行錯誤訊息
10925
			$result["error"][]="\$conf變數須為陣列形態";
10926
 
10927
			#如果傳入的參數為 null
10928
			if($conf==null){
10929
 
10930
				#設置執行錯誤訊息
10931
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
10932
 
10933
				}#if end
10934
 
10935
			#回傳結果
10936
			return $result;
10937
 
10938
			}#if end
10939
 
10940
		#檢查參數
43 liveuser 10941
		#函式說明:
1 liveuser 10942
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
10943
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
10944
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
10945
		#$result["function"],當前執行的函式名稱.
10946
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
10947
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
10948
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
10949
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
10950
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
10951
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
10952
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
43 liveuser 10953
		#必填參數:
1 liveuser 10954
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
10955
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
10956
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
10957
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName");
10958
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
10959
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string");
10960
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
10961
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
43 liveuser 10962
		#可省略參數:
1 liveuser 10963
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
10964
		#$conf["canBeEmptyString"]="false";
10965
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
10966
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort","WhereColumnCombine","WhereColumnName","WhereColumnOperator","WhereColumnValue","WhereColumnAndOr","orderItem","ascORdesc","numberStart","number","groupBy","whereIn","whereNotIn");
10967
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
10968
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","array","array","array","array","string","string","string","string","array","array","array");
10969
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
10970
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null,null,null,null,null,null,"0",null,null,null,null);
10971
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
10972
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("WhereColumnName","WhereColumnValue");
10973
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("WhereColumnValue","WhereColumnOperator");
43 liveuser 10974
		#參考資料:
1 liveuser 10975
		#array_keys=>http://php.net/manual/en/function.array-keys.php
10976
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
10977
		unset($conf["variableCheck::checkArguments"]);
10978
 
10979
		#如果檢查失敗
10980
		if($checkResult["status"]==="false"){
10981
 
10982
			#設置執行失敗的訊息
10983
			$result["status"]="false";
10984
 
10985
			#設置錯誤訊息
10986
			$result["error"]=$checkResult;
10987
 
10988
			#回傳結果
10989
			return $result;
10990
 
10991
			}#if end
10992
 
10993
		#如果檢查不通過
10994
		if($checkResult["passed"]==="false"){
10995
 
10996
			#設置執行失敗的訊息
10997
			$result["status"]="false";
10998
 
10999
			#設置錯誤訊息
11000
			$result["error"]=$checkResult;
11001
 
11002
			#回傳結果
11003
			return $result;
11004
 
11005
			}#if end
11006
 
338 liveuser 11007
		#連線到資料庫
11008
		#函式說明:
11009
		#連線到資料庫,結果會回傳一個陣列
339 liveuser 11010
		#$result["status"],若連線成功則爲"true",連線失敗則爲"false".
11011
		#$result["connectInformation"],爲回傳的mysql連線資訊.
11012
		#$result["error"],錯誤訊息	.
11013
		#$result["function"],當前執行的函數名稱.	
338 liveuser 11014
		#必填參數:
11015
		$conf["db"]["dbConnect"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
11016
		$conf["db"]["dbConnect"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
342 liveuser 11017
		#$conf["dbName"],字串,爲要連的資料庫名稱
11018
		$conf["db"]["dbConnect"]["dbName"]=$conf["selectedDataBaseName"];
338 liveuser 11019
		#可省略參數:
11020
 
11021
		#如果 $conf["dbPassword"] 有設定
11022
		if(isset($conf["dbPassword"])){
11023
 
11024
			$conf["db"]["dbConnect"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
11025
 
11026
			}#if end
11027
 
11028
		#如果 $conf["dbPort"] 有設定
11029
		if(isset($conf["dbPort"])){
11030
 
11031
			$conf["db"]["dbConnect"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
11032
 
11033
			}#if end
11034
 
11035
		$con=db::dbConnect($conf["db"]["dbConnect"]);
11036
		unset($conf["db"]);
11037
 
11038
		#如果連線到資料庫失敗
339 liveuser 11039
		if($con["status"]==="false"){
338 liveuser 11040
 
11041
			#設置執行失敗
11042
			$result["status"]="false";
11043
 
11044
			#設置執行錯誤訊息
11045
			$result["error"]=$con;
11046
 
11047
			#回傳結果
11048
			return $result;
11049
 
11050
			}#if end
11051
 
341 liveuser 11052
		#var_dump($con);	
339 liveuser 11053
 
338 liveuser 11054
		#取得mysqli物件
11055
		$mysqli=$con["connectInformation"];
11056
 
1 liveuser 11057
		#如果 $conf["WhereColumnAndOr"] 沒有設定,但是有指定判斷條件的欄位
11058
		if(!isset($conf["WhereColumnAndOr"])  && isset($conf["WhereColumnName"])){
11059
 
11060
			#則$conf["WhereColumnAndOr"]爲有 count($conf["WhereColumnName"])-1 個 "AND" 的字串陣列
11061
			for($i=0;$i<(count($conf["WhereColumnName"])-1);$i++){
11062
 
11063
				$conf["WhereColumnAndOr"][$i]="AND";
11064
 
11065
				}#for end
11066
 
11067
			}#if end
11068
 
11069
		#如果 $conf["WhereColumnCombine"] 沒有設定,但是有指定判斷條件的欄位
11070
		if(!isset($conf["WhereColumnCombine"])  && isset($conf["WhereColumnName"])){
11071
 
11072
			#則 $conf["WhereColumnCombine"] 爲有 count($conf["WhereColumnName"]) 個 "" 的字串陣列
11073
			for($i=0;$i<count($conf["WhereColumnName"]);$i++){
11074
 
11075
				$conf["WhereColumnCombine"][$i]="";
11076
 
11077
				}#for end
11078
 
11079
			}#if end
11080
 
11081
		#如果 $conf["WhereColumnOperator"] 沒有設定,但是有設定判斷條件的欄位
11082
		if(!isset($conf["WhereColumnOperator"]) && isset($conf["WhereColumnName"])){
11083
 
11084
			#則 $conf["WhereColumnOperator"] 爲有 count($conf["WhereColumnName"]) 個 "" 的字串陣列
11085
			for($i=0;$i<count($conf["WhereColumnName"]);$i++){
11086
 
11087
				$conf["WhereColumnOperator"][$i]="=";
11088
 
11089
				}#for end
11090
 
11091
			}#if end
11092
 
11093
		#如果 $conf"ascORdesc"] 沒有設定,則不指定遞增或遞減排序
11094
		if(!isset($conf["ascORdesc"])){
11095
 
11096
			#排序變數爲空字串
11097
			$conf["ascORdesc"]="";
11098
 
11099
			}#if end
11100
 
11101
		#如果 $conf["number"] 沒設定,則不限定要取幾筆資料
11102
		if(!isset($conf["number"])){
11103
 
11104
			#限定筆數爲空字串
11105
			$queryStringLimit = "";
11106
 
11107
			}#if end 
11108
 
11109
		#如果 $conf["number"] 不爲空,則限定要取出幾筆
11110
		else{
11111
 
11112
			#如果 $conf["numberStart"] 有設定
11113
			if(isset($conf["numberStart"])){
11114
 
11115
				$queryStringLimit  = " LIMIT ".$conf["numberStart"]." , ".$conf["number"]." ";
11116
 
11117
				}#if end
11118
 
11119
			#反之 $conf["numberStart"] 沒有設定
11120
			else{
11121
 
11122
				$queryStringLimit  = " LIMIT 0 , ".$conf["number"]." ";
11123
 
11124
				}#else end
11125
 
11126
			}#else end
11127
 
11128
		#如果存在 $conf["orderItem"] 
11129
		if(isset($conf["orderItem"])){
11130
 
11131
			#如果排序的依據是 rand() 或 RAND()
11132
			if($conf["orderItem"] == "rand()" || $conf["orderItem"] == "RAND()"){
11133
 
11134
				# 依 $order 為排序依據,進行 隨機 排序
11135
				$queryStringOrder  = " ORDER BY ".$conf["orderItem"]." ".$conf["ascORdesc"]." "; 			
11136
 
11137
				}#if end
11138
 
11139
			#反之 $order 為排序依據
11140
			else{
11141
 
11142
				#爲 acs 或 desc, 依 $order 為排序依據,進行 asc OR desc 排序
11143
				$queryStringOrder  = " ORDER BY ".$conf["orderItem"]." ".$conf["ascORdesc"]." "; 
11144
 
11145
				}#else end
11146
 
11147
			}#if end
11148
 
11149
		#反之 不存在
11150
		else{
11151
 
11152
			#預設為不指定
11153
			$queryStringOrder="";
11154
 
11155
			}#else end
11156
 
11157
		#如果有設定 $conf["WhereColumnName"] 參數
11158
		if(isset($conf["WhereColumnName"])){
11159
 
11160
			#條件判斷的起始語句
11161
			$conf["whereCondition"]="WHERE ";
11162
 
11163
			#有幾個判斷用的欄位就執行幾次
11164
			for($i=0;$i<count($conf["WhereColumnName"]);$i++){
11165
 
11166
				#如果是左掛號
11167
				if($conf["WhereColumnCombine"][$i]=="("){
11168
 
11169
					$conf["whereCondition"]=$conf["whereCondition"]." ".$conf["WhereColumnCombine"][$i]." ";
11170
 
11171
					}#if end
11172
 
11173
				#如果欄位數值不是字串,也不是NULL
11174
				if(gettype($conf["WhereColumnValue"][$i])!=="string" && $conf["WhereColumnValue"][$i]!==NULL){
11175
 
11176
					#設置執行失敗
11177
					$result["status"]="false";
11178
 
11179
					#設置執行錯誤
11180
					$result["error"][]="WhereColumnValue 參數須為陣列字串";
11181
 
11182
					#回傳結果
11183
					return $result;
11184
 
11185
					}#if end
11186
 
11187
				#結合各個條件語句
11188
				$conf["whereCondition"]=$conf["whereCondition"]." `".$conf["WhereColumnName"][$i]."` ";
11189
				$conf["whereCondition"]=$conf["whereCondition"]." ".$conf["WhereColumnOperator"][$i]." ";
338 liveuser 11190
				$conf["whereCondition"]=$conf["whereCondition"]." '".mysqli_real_escape_string($mysqli,$conf["WhereColumnValue"][$i])."' ";
1 liveuser 11191
 
11192
				#如果右掛號
11193
				if($conf["WhereColumnCombine"][$i]==")"){
11194
 
11195
					$conf["whereCondition"]=$conf["whereCondition"]." ".$conf["WhereColumnCombine"][$i]." ";
11196
 
11197
					}#if end
11198
 
11199
				#如果不是最後一筆項目,就放置AND or OR
11200
				if($i<count($conf["WhereColumnName"])-1){
11201
 
11202
					$conf["whereCondition"]=$conf["whereCondition"]." ".$conf["WhereColumnAndOr"][$i]." ";
11203
 
11204
					}#if end	
11205
 
11206
				}#for end					
11207
 
11208
			}#if end
11209
 
11210
		#反之,套件變數設爲空字串
11211
		else{
11212
 
11213
			$conf["whereCondition"]="";
11214
 
11215
			}#else end
11216
 
11217
		#初始化 where in 語句
11218
		$whereIn=" ";
11219
 
11220
		#如果 $conf["whereIn"] 存在
11221
		if(isset($conf["whereIn"])){
11222
 
11223
			#如果 $conf["whereCondition"] 等於 空
11224
			if($conf["whereCondition"]!==""){
11225
 
11226
				#先加上串接的 AND
11227
				$whereIn=$whereIn."AND ";
11228
 
11229
				}#if end
11230
 
11231
			#反之為第一個where條件
11232
			else{
11233
 
11234
				#設置where開頭
11235
				$whereIn=$whereIn."where ";
11236
 
11237
				}#else end
11238
 
11239
			#針對每個要用 in 條件判斷的語句
11240
			for($i=0;$i<count($conf["whereIn"]);$i++){
11241
 
11242
				#取得要判斷的欄位
11243
				$col=$conf["whereIn"][$i][0];
11244
 
11245
				#加上 in 的開頭語句
11246
				$whereIn=$whereIn."`".$col."` in(";
11247
 
11248
				#針對每個 in 的值
11249
				for($j=0;$j<count($conf["whereIn"][$i][1]);$j++){
11250
 
11251
					#串接條件
338 liveuser 11252
					$whereIn=$whereIn."'".mysqli_real_escape_string($mysqli,$conf["whereIn"][$i][1][$j])."'";
1 liveuser 11253
 
11254
					#如果不是最後一個條件
11255
					if($j!==count($conf["whereIn"][$i][1])-1){
11256
 
11257
						#後面還有條件
11258
						$whereIn=$whereIn.",";
11259
 
11260
						}#if end
11261
 
11262
					#反之是最後一個條件
11263
					else{
11264
 
11265
						#後面沒有條件
11266
						$whereIn=$whereIn.")";
11267
 
11268
						}#else end
11269
 
11270
					}#for end
11271
 
11272
				}#for end
11273
 
11274
			#如果沒有in的條件
11275
			if($whereIn===" AND `".$col."` in(" OR $whereIn===" AND " OR $whereIn===" " OR $whereIn===" where "){
11276
 
11277
				#設為 ""
11278
				$whereIn="";
11279
 
11280
				}#if end
11281
 
11282
			}#if end
11283
 
11284
		#串接 where in 語句
11285
		$conf["whereCondition"]=$conf["whereCondition"].$whereIn;
11286
 
11287
		#初始化 where not in 語句
11288
		$whereNotIn=" ";	
11289
 
11290
		#如果 $conf["whereNotIn"] 存在
11291
		if(isset($conf["whereNotIn"])){
11292
 
11293
			#如果 $conf["whereCondition"] 等於 空
11294
			if(str_replace(" ","",$conf["whereCondition"])!==""){
11295
 
11296
				#先加上串接的 AND
11297
				$whereNotIn=$whereNotIn."AND ";
11298
 
11299
				}#if end
11300
 
11301
			#反之為第一個where條件
11302
			else{
11303
 
11304
				#設置where開頭
11305
				$whereNotIn=$whereNotIn."where ";
11306
 
11307
				}#else end
11308
 
11309
			#針對每個要用 in 條件判斷的語句
11310
			for($i=0;$i<count($conf["whereNotIn"]);$i++){
11311
 
11312
				#取得要判斷的欄位
11313
				$col=$conf["whereNotIn"][$i][0];
11314
 
11315
				#加上 in 的開頭語句
11316
				$whereNotIn=$whereNotIn."`".$col."` not in(";
11317
 
11318
				#針對每個 in 的值
11319
				for($j=0;$j<count($conf["whereNotIn"][$i][1]);$j++){
11320
 
11321
					#串接條件
338 liveuser 11322
					$whereNotIn=$whereNotIn."'".mysqli_real_escape_string($mysqli,$conf["whereNotIn"][$i][1][$j])."'";
1 liveuser 11323
 
11324
					#如果不是最後一個條件
11325
					if($j!==count($conf["whereNotIn"][$i][1])-1){
11326
 
11327
						#後面還有條件
11328
						$whereNotIn=$whereNotIn.",";
11329
 
11330
						}#if end
11331
 
11332
					#反之是最後一個條件
11333
					else{
11334
 
11335
						#後面沒有條件
11336
						$whereNotIn=$whereNotIn.")";
11337
 
11338
						}#else end
11339
 
11340
					}#for end
11341
 
11342
				}#for end
11343
 
11344
			#如果沒有in的條件
11345
			if($whereNotIn===" AND `".$col."` not in(" OR $whereNotIn===" AND " OR $whereNotIn===" " OR $whereNotIn===" where "){
11346
 
11347
				#設為 ""
11348
				$whereNotIn="";
11349
 
11350
				}#if end
11351
 
11352
			}#if end
11353
 
11354
		#串接 where not in 語句
11355
		$conf["whereCondition"]=$conf["whereCondition"].$whereNotIn;
11356
 
11357
		#如果 $conf["groupBy"] 有指定
11358
		if(isset($conf["groupBy"])){
11359
 
11360
			#初始化分類語句的字串
11361
			$groupByQueryStr="GROUP BY ";
11362
 
11363
			#設定要以哪些欄位爲分組的依據
11364
			for($i=0;$i<count($conf["groupBy"]);$i++){
11365
 
11366
				#如果不是最後一筆
11367
				if($i!=count($conf["groupBy"])-1){
11368
 
11369
					#語法裡面含有 , 代表還有其他欄位
11370
					$groupByQueryStr=$groupByQueryStr." `".$conf["groupBy"][$i]."` , ";
11371
 
11372
					}#if end
11373
 
11374
				#反之是最後一筆資料
11375
				else{
11376
 
11377
					#語法結尾沒有 , 代表沒有其他欄位
11378
					$groupByQueryStr=$groupByQueryStr." `".$conf["groupBy"][$i]."` ";
11379
 
11380
					}#else end
11381
 
11382
				}#for end
11383
 
11384
			#取得分組的語法
11385
			$conf["groupBy"]=$groupByQueryStr;
11386
 
11387
			}#if end
11388
 
11389
		#如果 $conf["groupBy"] 沒有設定
11390
		else{
11391
 
11392
			#則將其設爲空值
11393
			$conf["groupBy"]="";
11394
 
11395
			}#else end
11396
 
338 liveuser 11397
		#要執行的sql語法
11398
		$result["sql"]=$queryStringFinal="SELECT * FROM `".$conf["selectedDataBaseName"]."`.`".$conf["selectedDataTableName"]."` ".$conf["whereCondition"]." ".$conf["groupBy"]." ".$queryStringOrder.$queryStringLimit;
11399
 
1 liveuser 11400
		#執行 SQL 語法
43 liveuser 11401
		#函式說明:
1 liveuser 11402
		#執行mysql指令
43 liveuser 11403
		#回傳結果::
1 liveuser 11404
		#$result["status"],"true"為執行成功;"false"為執行失敗。
11405
		#$result["error"],錯誤訊息的陣列
11406
		#$result["function"],當前執行的涵式
11407
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
11408
		#$result["queryString"],mysql查詢的語言
11409
		#查詢號的解果,需要解析。
43 liveuser 11410
		#必填參數:
1 liveuser 11411
		$conf["db::execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
11412
		$conf["db::execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
11413
		$conf["db::execMysqlQuery"]["dbSql"]=$queryStringFinal;#要執行sql語法
43 liveuser 11414
		#可省略參數:
1 liveuser 11415
 
11416
		#如果 $conf["dbPassword"] 有設定
11417
		if(isset($conf["dbPassword"])){
11418
 
11419
			$conf["db::execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
11420
 
11421
			}#if end
11422
 
11423
		#如果 $conf["dbPort"] 有設定
11424
		if(isset($conf["dbPort"])){
11425
 
11426
			$conf["db::execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的3306.
11427
 
11428
			}#if end
343 liveuser 11429
		#$conf["dbLink"],物件,mysqli物件,由mysqli_connect()回傳的物件內容,若為數值則改用賬號密碼等資訊進行連線,反之則沿用連線物件.
11430
		$conf["db::execMysqlQuery"]["dbLink"]=$mysqli;			
1 liveuser 11431
		$execMysqlQuery=db::execMysqlQuery($conf["db::execMysqlQuery"]);
11432
		unset($conf["db::execMysqlQuery"]);
11433
 
11434
		#如果執行錯誤
11435
		if($execMysqlQuery["status"]=="false"){
11436
 
11437
			#設置執行錯誤的識別
11438
			$result["status"]="false";
11439
 
11440
			#設置錯誤訊息
11441
			$result["error"]=$execMysqlQuery;
11442
 
11443
			#回傳錯誤訊息
11444
			return $result;
11445
 
11446
			}#if end
11447
 
11448
		#取得查詢後的結果
11449
		$result["sqlQueryResult"]=$execMysqlQuery["queryResource"];
11450
 
11451
		#取得符合條件的資料筆數
11452
		$result["dataCount"]=mysqli_num_rows($execMysqlQuery["queryResource"]);
11453
 
11454
		#執行到這邊代表執行成功
11455
		$result["status"]="true";
11456
 
11457
		#回傳查詢的結果;	
11458
		return $result;	
11459
 
11460
		}#end dataTableSelect
11461
 
11462
	/*
43 liveuser 11463
	#函式說明:
1 liveuser 11464
	#解析 dataTableSelect($conf) 後的結果,亦即將執行sql語法後所得到的結果解析放進變數裏面
43 liveuser 11465
	#回傳結果:
1 liveuser 11466
	#$result["status"],執行結果"true"為成功;"false"為失敗
11467
	#$result["error"],錯誤訊息
11468
	#$result["function"],儲存當前函數名稱
11469
	#$result["dataColumnName"],為資料欄位的名稱陣列.
11470
		#$result["dataColumnName"][$i]代表第一個欄位名稱.
11471
	#$result["dataContent"],爲資料的內容。
11472
	#$result["dataContent"][$conf["tableValueName"][$i]][$dataSetNum],
11473
		#$conf["tableValueName"][$i] 爲第 $i+1 個欄位的名稱.
11474
		#$dataSetNum 爲第$dataSetNum+1筆資料.
11475
		#若欄位不存在則會以空字串替代.
11476
	#$result["dataCount"],爲取得的資料筆數。
43 liveuser 11477
	#必填參數:
1 liveuser 11478
	$conf["sqlQueryResult"],object,爲執行sql語法所獲得的查詢結果。
11479
	$conf["sqlQueryResult"]="";
11480
	$conf["tableValueName"],字串陣列,爲該資料表列項目的每一項名稱,須爲陣列值,若為「array("*")」則代表所有欄位.
11481
	$conf["tableValueName"]=array();
11482
	$conf["dbAddress"],字串,爲mysql-Server的位置
11483
	$conf["dbAddress"]=$dbAddress;
11484
	$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
11485
	$conf["dbAccount"]=$dbAccount;
43 liveuser 11486
	#可省略參數:
1 liveuser 11487
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
11488
	#$conf["dbPassword"]=$dbPassword;
11489
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
11490
	#$conf["dbPort"]="";
11491
	#$conf["valueName"],字串陣列,爲該資料表列項目的每一項所要對應的變數名稱,預設為欄位的名稱($conf["tableValueName"]).
11492
	#$conf["valueName"]=$conf["tableValueName"];
11493
	#參考資料:
11494
	#http://www.w3school.com.cn/php/func_mysql_fetch_array.asp => 解析取得的資料表欄位時,能夠選擇回傳含有欄位名稱與數字代表的key.
43 liveuser 11495
	#備註:
11496
	#無.
1 liveuser 11497
	*/
11498
	public static function sendQueryDataToVariabele(&$conf){
11499
 
11500
		#初始化要回傳的內容
11501
		$result=array();
11502
 
11503
		#取得當前執行的函數名稱
11504
		$result["function"]=__FUNCTION__;
11505
 
11506
		#如果 $conf 不為陣列
11507
		if(gettype($conf)!="array"){
11508
 
11509
			#設置執行失敗
11510
			$result["status"]="false";
11511
 
11512
			#設置執行錯誤訊息
11513
			$result["error"][]="\$conf變數須為陣列形態";
11514
 
11515
			#如果傳入的參數為 null
11516
			if($conf==null){
11517
 
11518
				#設置執行錯誤訊息
11519
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
11520
 
11521
				}#if end
11522
 
11523
			#回傳結果
11524
			return $result;
11525
 
11526
			}#if end
11527
 
11528
		#檢查參數
43 liveuser 11529
		#函式說明:
1 liveuser 11530
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
11531
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11532
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11533
		#$result["function"],當前執行的函式名稱.
11534
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11535
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11536
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11537
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
11538
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11539
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11540
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
43 liveuser 11541
		#必填參數:
1 liveuser 11542
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11543
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11544
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11545
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","sqlQueryResult","tableValueName");
11546
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
11547
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","object","array");
11548
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11549
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
43 liveuser 11550
		#可省略參數:
1 liveuser 11551
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
11552
		#$conf["canBeEmptyString"]="false";
11553
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11554
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort","valueName");
11555
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
11556
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array");
11557
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
11558
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"\$conf[\"tableValueName\"]");
11559
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11560
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("valueName","tableValueName");
43 liveuser 11561
		#參考資料:
1 liveuser 11562
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11563
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11564
		unset($conf["variableCheck::checkArguments"]);
11565
 
11566
		#如果檢查失敗
11567
		if($checkResult["status"]=="false"){
11568
 
11569
			#設置執行失敗的訊息
11570
			$result["status"]="false";
11571
 
11572
			#設置錯誤訊息
11573
			$result["error"]=$checkResult;
11574
 
11575
			#回傳結果
11576
			return $result;
11577
 
11578
			}#if end
11579
 
11580
		#如果檢查不通過
11581
		if($checkResult["passed"]=="false"){
11582
 
11583
			#設置執行失敗的訊息
11584
			$result["status"]="false";
11585
 
11586
			#設置錯誤訊息
11587
			$result["error"]=$checkResult;
11588
 
11589
			#回傳結果
11590
			return $result;
11591
 
11592
			}#if end
11593
 
11594
		#給予初始值表示從0筆開始統計
11595
		$dataSetNum=0;
11596
 
11597
		#取得資料表的欄位數量
11598
		$columnCounts=count($conf["tableValueName"]);
11599
 
11600
		#初始化識別是否要匯出全部欄位的變數
11601
		$exportAll="false";
11602
 
11603
		#初始化儲存取得的欄位名稱陣列
11604
		$result["dataColumnName"]=array();
11605
 
11606
		#如果剛好只有一個元素
11607
		if($columnCounts==1){
11608
 
11609
			#如果第一個元素為 "*"
11610
			if($conf["tableValueName"][0]=="*"){
11611
 
11612
				#則代表要全部欄位均匯出.
11613
				$exportAll="true";
11614
 
11615
				#初始化計數的變數
11616
				$dataSetNum=0;
11617
 
11618
				#將讀取到的資料一次只讀取一列
11619
				while($row = mysqli_fetch_array($conf["sqlQueryResult"])){
11620
 
11621
					#筆數加1
11622
					$dataSetNum++;
11623
 
11624
					#針對每個欄位
11625
					foreach($row as $columnName => $columnValue){
11626
 
11627
						#取得欄位的內容並用欄位名稱作為key
11628
						$result["dataContent"][$columnName][]=$columnValue;
11629
 
11630
						#如果 $dataSetNum 等於 1
11631
						#亦即第一筆資料
11632
						if($dataSetNum==1 && gettype($columnName)!="integer"){
11633
 
11634
							#取得每個欄位名稱
11635
							$result["dataColumnName"][]=$columnName;
11636
 
11637
							}#if end
11638
 
11639
						}#foreach end
11640
 
11641
					}#while end
11642
 
11643
				#將資料筆數放進 $result["dataCount"] 裏面
11644
				$result["dataCount"]=$dataSetNum;
11645
 
11646
				}#if end
11647
 
11648
			}#if end
11649
 
11650
		#如果 $exportAll 等於 "fasle" 則代表要根據需求匯出指定的欄位.
11651
		if($exportAll=="false"){
11652
 
11653
			#如果 $conf["valueName"] 沒有設置
11654
			if(!isset($conf["valueName"])){
11655
 
11656
				#預設為 $conf["tableValueName"]
11657
				$conf["valueName"]=$conf["tableValueName"];
11658
 
11659
				}#if end
11660
 
11661
			#取得每個欄位名稱
11662
			$result["dataColumnName"]=$conf["tableValueName"];
11663
 
11664
			#將讀取到的資料一次只讀取一列
11665
			while($row = mysqli_fetch_array($conf["sqlQueryResult"])){
11666
 
11667
				#$i筆項列資料,則運行$i次。
11668
				for($i=0;$i<$columnCounts;$i++){			
11669
 
11670
					#如果欄位不存在
11671
					if(!isset($row[$conf["tableValueName"][$i]])){
11672
 
11673
						#將解析的資料內容用空字串替代放進$result["dataContent"]變數裏面
11674
						$result["dataContent"][$conf["valueName"][$i]][$dataSetNum] = "";
11675
 
11676
						}#if end
11677
 
11678
					#將解析的資料內容結果放進$result["dataContent"]變數裏面
11679
					$result["dataContent"][$conf["valueName"][$i]][$dataSetNum] = $row[$conf["tableValueName"][$i]];	
11680
 
11681
					}#for end
11682
 
11683
				#資料筆數編號加1
11684
				$dataSetNum++;	
11685
 
11686
				}#while end
11687
 
11688
			#將資料筆數放進 $result["dataCount"] 裏面
11689
			$result["dataCount"]=$dataSetNum;
11690
 
11691
			}#if end
11692
 
343 liveuser 11693
 
1 liveuser 11694
 
11695
		#執行道這邊代表執行成功
11696
		$result["status"]="true";
11697
 
11698
		#將取得的結果回傳
11699
		return $result;
11700
 
11701
		}#function sendQueryDataToVariabele end
11702
 
11703
	/*
43 liveuser 11704
	#函式說明:
1 liveuser 11705
	#一次取得資料庫、表的資料
43 liveuser 11706
	#回傳結果:
1 liveuser 11707
	#$result["status"],執行結果"true"為成功;"false"為執行失敗。
11708
	#$result["error"],錯誤訊息陣列。
11709
	#$result["function"],當前執行的漢書名稱.
11710
	#$result["argu"],使用的參數.
11711
	#$result["dataColumnName"],抓取的資料欄位名稱陣列.
11712
		#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
11713
	#$result["dataContent"],爲資料的內容。
11714
	#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
11715
		#$dataSetNum 爲第$dataSetNum+1筆資料
11716
		#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
11717
	#$result["dataCount"],爲取得的資料筆數。
11718
	#$result["sql"],執行的sql字串.
43 liveuser 11719
	#必填參數:
1 liveuser 11720
	#$conf["dbAddress"],字串,爲dbServer的位置。
11721
	$conf["dbAddress"]=$dbAddress;
11722
	#$conf["dbAccount"],字串,爲登入dbServer的帳號。
11723
	$conf["dbAccount"]=$dbAccount;
11724
	#$conf["dbName"],字串,爲要存取的資料庫名稱
11725
	$conf["dbName"]=$dbName;
11726
	#$conf["tableName"],字串,爲要存取的資料表名稱
11727
	$conf["tableName"]="";
11728
	#$conf["columnYouWant"],字串陣列,你想要的欄位!,若設為「array("*")」則代表全部欄位.
11729
	$conf["columnYouWant"]=array();
43 liveuser 11730
	#可省略參數:
1 liveuser 11731
	#$conf["dbPassword"],字串,爲要存取dbServer的密碼.
11732
	#$conf["dbPassword"]=$dbPassword;
11733
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
11734
	#$conf["dbPort"]="";
11735
	#$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。
11736
	#$conf["WhereColumnName"]=array("");
11737
	#$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
11738
	#$conf["WhereColumnValue"]=array("");
11739
	#$conf["WhereColumnCombine"],字串陣列,用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
11740
	#$conf["WhereColumnCombine"]=array("");
11741
	#$conf["WhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、"!="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
11742
	#$conf["WhereColumnOperator"]=array("");
11743
	#$conf["WhereColumnAndOr"],字串陣列,用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
11744
	#$conf["WhereColumnAndOr"]=array("");
11745
	#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
11746
	#$conf["whereIn"]=array(array("colName",array("a","b","c")));
11747
	#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
11748
	#$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
11749
	#$conf["orderItem"],字串,爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
11750
	#$conf["orderItem"]="";
11751
	#$conf["ascORdesc"],字串,爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
11752
	#$conf["ascORdesc"]="";
11753
	#$conf["numberStart"],字串,為從第幾筆開始讀取,預設為0,代筆第一筆。
11754
	#$conf["numberStart"]="0";
11755
	#$conf["numLimit"],字串,為要取幾筆資料,可以省略,省略則表示不限制數目。
11756
	#$conf["numLimit"]="30";
11757
	#$conf["groupBy"],字串陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
11758
	#$conf["groupBy"]=array("");
185 liveuser 11759
	#參考資料:
11760
	#無.
43 liveuser 11761
	#備註:
11762
	#無.
1 liveuser 11763
	*/
11764
	public static function fastGetDbData(&$conf){
11765
 
11766
		#初始化要回傳的內容
11767
		$result=array();
11768
 
11769
		#取得當前執行的函數名稱
11770
		$result["function"]=__FUNCTION__;
11771
 
11772
		#如果 $conf 不為陣列
11773
		if(gettype($conf)!="array"){
11774
 
11775
			#設置執行失敗
11776
			$result["status"]="false";
11777
 
11778
			#設置執行錯誤訊息
11779
			$result["error"][]="\$conf變數須為陣列形態";
11780
 
11781
			#如果傳入的參數為 null
11782
			if($conf==null){
11783
 
11784
				#設置執行錯誤訊息
11785
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
11786
 
11787
				}#if end
11788
 
11789
			#回傳結果
11790
			return $result;
11791
 
11792
			}#if end
11793
 
11794
		#取得使用的
11795
		$result["argu"]=$conf;
11796
 
11797
		#檢查參數
43 liveuser 11798
		#函式說明:
1 liveuser 11799
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
11800
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
11801
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
11802
		#$result["function"],當前執行的函式名稱.
11803
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
11804
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
11805
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
11806
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
11807
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
11808
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
11809
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
43 liveuser 11810
		#必填參數:
1 liveuser 11811
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
11812
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
11813
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
11814
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","dbName","tableName","columnYouWant");
11815
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
11816
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","array");
11817
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
11818
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
43 liveuser 11819
		#可省略參數:
1 liveuser 11820
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
11821
		#$conf["canBeEmptyString"]="false";
11822
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
11823
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort","WhereColumnName","WhereColumnValue","WhereColumnCombine","WhereColumnOperator","WhereColumnAndOr","orderItem","ascORdesc","numberStart","numLimit","groupBy","whereIn","whereNotIn");
11824
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
11825
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","array","array","array","array","string","string","string","string","array","array","array");
11826
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
11827
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null,null,null,null,null,null,"0",null,null,null,null);
11828
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
11829
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("WhereColumnName","WhereColumnValue");
11830
		$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("WhereColumnValue","WhereColumnOperator");
43 liveuser 11831
		#參考資料:
1 liveuser 11832
		#array_keys=>http://php.net/manual/en/function.array-keys.php
11833
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
11834
		unset($conf["variableCheck::checkArguments"]);
11835
 
11836
		#如果檢查失敗
11837
		if($checkResult["status"]=="false"){
11838
 
11839
			#設置執行失敗的訊息
11840
			$result["status"]="false";
11841
 
11842
			#設置錯誤訊息
11843
			$result["error"]=$checkResult;
11844
 
11845
			#回傳結果
11846
			return $result;
11847
 
11848
			}#if end
11849
 
11850
		#如果檢查不通過
11851
		if($checkResult["passed"]=="false"){
11852
 
11853
			#設置執行失敗的訊息
11854
			$result["status"]="false";
11855
 
11856
			#設置錯誤訊息
11857
			$result["error"]=$checkResult;
11858
 
11859
			#回傳結果
11860
			return $result;
11861
 
11862
			}#if end
11863
 
11864
		#初始化要檢查的欄位
11865
		$colToCheck=array();
11866
 
11867
		#如果有指定要的欄位
11868
		if($conf["columnYouWant"]!==array("*")){
11869
 
11870
			#針對每個欄位
11871
			foreach($conf["columnYouWant"] as $col){
11872
 
11873
				#取得欄位名稱
11874
				$colToCheck[]=$col;
11875
 
11876
				}#foreach end			
11877
 
11878
			}#if end
11879
 
11880
		#如果有設置
11881
		if(isset($conf["WhereColumnName"])){
11882
 
11883
			#針對每個欄位
11884
			foreach($conf["WhereColumnName"] as $col){
11885
 
11886
				#取得欄位名稱
11887
				$colToCheck[]=$col;
11888
 
11889
				}#foreach end			
11890
 
11891
			}#if end
11892
 
11893
		#如果有設置 $conf["whereIn"]
11894
		if(isset($conf["whereIn"])){
11895
 
11896
			#針對每個 where in 條件
11897
			for($i=0;$i<count($conf["whereIn"]);$i++){
11898
 
11899
				#取得欄位名稱
11900
				$colToCheck[]=$conf["whereIn"][$i][0];
11901
 
11902
				}#for end
11903
 
11904
			}#if end
11905
 
11906
		#如果要檢查的欄位不是空陣列
11907
		if($colToCheck!==array()){
11908
 
11909
			#檢查需要判斷資料表欄位是否存在
43 liveuser 11910
			#函式說明:
1 liveuser 11911
			#檢查資料表的欄位是否存在
43 liveuser 11912
			#回傳結果::
1 liveuser 11913
			#設置執行錯誤的識別
11914
			#$result["function"],當前執行的函數名稱.
11915
			#$result["status"],"true"代表執行成功;"false"代表執行失敗.
11916
			#$result["error"],錯誤訊息.
11917
			#$result["warning"],警告訊息陣列
11918
			#$result["passed"],是否通過檢查,"true"代表通過;"false"代表不通過.
11919
			#其餘的結果代表參數不正確
43 liveuser 11920
			#必填參數:
1 liveuser 11921
			#$conf["dbAddr"],字串,爲mysql-Server的位置
11922
			$conf["db::checkTableColExists"]["dbAddr"]=$conf["dbAddress"]; 
11923
			#$conf["dbAcct"],字串,爲用於連入mysql-Server時要使用的帳號
11924
			$conf["db::checkTableColExists"]["dbAcct"]=$conf["dbAccount"];
11925
			#$conf["dbName"],字串,爲指定的資料庫名稱
11926
			$conf["db::checkTableColExists"]["dbName"]=$conf["dbName"];
11927
			#$conf["dtName"],字串,為要檢查是否存在的資料表名稱
11928
			$conf["db::checkTableColExists"]["dtName"]=$conf["tableName"];
11929
			#$conf["col"],字串陣列,要檢查的欄位名稱.
11930
			$conf["db::checkTableColExists"]["col"]=array_unique($colToCheck);
43 liveuser 11931
			#可省略參數
1 liveuser 11932
 
11933
			#如果有設置 $conf["dbPassword"]
11934
			if(isset($conf["dbPassword"])){
11935
 
11936
				#$conf["dbPass"],爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼 
11937
				$conf["db::checkTableColExists"]["dbPass"]=$conf["dbPassword"];
11938
 
11939
				}#if end
11940
 
11941
			#如果有設置 $conf["dbPort"]
11942
			if(isset($conf["dbPort"])){
11943
 
11944
				#$conf["dbPort"],爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的port 3306 
11945
				$conf["db::checkTableColExists"]["dbPort"]=$conf["dbPort"];
11946
 
11947
				}#if end
11948
 
11949
			$checkTableColExists=db::checkTableColExists($conf["db::checkTableColExists"]);
11950
			unset($conf["db::checkTableColExists"]);
11951
 
11952
			#如果檢查失敗
11953
			if($checkTableColExists["status"]==="false"){
11954
 
11955
				#設置執行失敗
11956
				$result["status"]="false";
11957
 
11958
				#設置執行錯誤訊息
11959
				$result["error"]=$checkTableColExists;
11960
 
11961
				#回傳結果
11962
				return $result;
11963
 
11964
				}#if end
11965
 
11966
			#如果檢查不通過
11967
			if($checkTableColExists["passed"]==="false"){
11968
 
11969
				#設置執行失敗
11970
				$result["status"]="false";
11971
 
11972
				#設置執行錯誤訊息
11973
				$result["error"]=$checkTableColExists;
11974
 
11975
				#回傳結果
11976
				return $result;
11977
 
11978
				}#if end
11979
 
11980
			}#if end
11981
 
43 liveuser 11982
		#函式說明:
1 liveuser 11983
		#dataTableSelectCustom的改良版
11984
		#回傳的參數:
11985
		#$result["status"],執行結果"true"為成功;"false"為執行失敗。
11986
		#$result["error"],錯誤訊息陣列。
11987
		#$result["sql"],執行的sql語法。
11988
		#$result["sqlQueryResult"]#爲資料連線處理完畢之後的結果,需要 sendQueryDataToVariabele 涵式來解析。
11989
		#$result["connectInformation"]#連結到資料庫的資訊。
11990
		#$result["dataCount"]#符合條件的資料筆數
43 liveuser 11991
		#必填參數:
1 liveuser 11992
		$conf["db"]["dataTableSelectCustomV2"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置。
11993
		$conf["db"]["dataTableSelectCustomV2"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號。
11994
		$conf["db"]["dataTableSelectCustomV2"]["selectedDataBaseName"]=$conf["dbName"];#要選取的資料庫名稱	。
11995
		$conf["db"]["dataTableSelectCustomV2"]["selectedDataTableName"]=$conf["tableName"];#爲欲選擇的資料表名稱。
43 liveuser 11996
		#可省略參數:
1 liveuser 11997
 
11998
		#如果存在 $conf["dbPassword"]
11999
		if(isset($conf["dbPassword"])){
12000
 
12001
			#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
12002
			$conf["db"]["dataTableSelectCustomV2"]["dbPassword"]=$conf["dbPassword"];
12003
 
12004
			}#if end
12005
 
12006
		#如果存在 $conf["dbPort"]
12007
		if(isset($conf["dbPort"])){
12008
 
12009
			#爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port
12010
			$conf["db"]["dataTableSelectCustomV2"]["dbPort"]=$conf["dbPort"];
12011
 
12012
			}#if end
12013
 
12014
		#如果存在 $conf["WhereColumnCombine"]
12015
		if(isset($conf["WhereColumnCombine"])){
12016
 
12017
			#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
12018
			$conf["db"]["dataTableSelectCustomV2"]["WhereColumnCombine"]=$conf["WhereColumnCombine"];
12019
 
12020
			}#if end
12021
 
12022
		#如果 $conf["WhereColumnName"] 存在
12023
		if(isset($conf["WhereColumnName"])){
12024
 
12025
			$conf["db"]["dataTableSelectCustomV2"]["WhereColumnName"]=$conf["WhereColumnName"];#用於判斷語句的欄位項目陣列。
12026
 
12027
			}#if end	
12028
 
12029
		#如果存在 $conf["WhereColumnOperator"]
12030
		if(isset($conf["WhereColumnOperator"])){
12031
 
12032
			#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
12033
			$conf["db"]["dataTableSelectCustomV2"]["WhereColumnOperator"]=$conf["WhereColumnOperator"];
12034
 
12035
			}#if end
12036
 
12037
		#如果 $conf["WhereColumnValue"] 有設置
12038
		if(isset($conf["WhereColumnValue"])){
12039
 
12040
			$conf["db"]["dataTableSelectCustomV2"]["WhereColumnValue"]=$conf["WhereColumnValue"];#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
12041
 
12042
			}#if end
12043
 
12044
		#如果 $conf["WhereColumnAndOr"] 存在
12045
		if(isset($conf["WhereColumnAndOr"])){
12046
 
12047
			#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
12048
			$conf["db"]["dataTableSelectCustomV2"]["WhereColumnAndOr"]=$conf["WhereColumnAndOr"];
12049
 
12050
			}#if end
12051
 
12052
		#如果 $conf["orderItem"] 存在
12053
		if(isset($conf["orderItem"])){
12054
 
12055
			#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
12056
			$conf["db"]["dataTableSelectCustomV2"]["orderItem"]=$conf["orderItem"];
12057
 
12058
			}#if end
12059
 
12060
		#如果 $conf["ascORdesc"] 存在
12061
		if(isset($conf["ascORdesc"])){
12062
 
12063
			#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
12064
			$conf["db"]["dataTableSelectCustomV2"]["ascORdesc"]=$conf["ascORdesc"];
12065
 
12066
			}#if end
12067
 
12068
		#如果 $conf["numberStart"] 存在
12069
		if(isset($conf["numberStart"])){
12070
 
12071
			$conf["db"]["dataTableSelectCustomV2"]["numberStart"]=$conf["numberStart"];
12072
 
12073
			}#if end
12074
 
12075
		#如果 $conf["numLimit"] 存在
12076
		if(isset($conf["numLimit"])){
12077
 
12078
			#為要取幾筆資料,可以省略,省略則表示不限制數目。
12079
			$conf["db"]["dataTableSelectCustomV2"]["number"]=$conf["numLimit"];
12080
 
12081
			}#if end
12082
 
12083
		#如果 $conf["groupBy"] 存在
12084
		if(isset($conf["groupBy"])){
12085
 
12086
			#爲要以那個欄爲作爲分羣的依據(該欄位相同的數值僅會取出一筆)。
12087
			$conf["db"]["dataTableSelectCustomV2"]["groupBy"]=$conf["groupBy"];
12088
 
12089
			}#if end
12090
 
12091
		#如果 $conf["whereIn"] 存在
12092
		if(isset($conf["whereIn"])){
12093
 
12094
			#where in 條件		
12095
			$conf["db"]["dataTableSelectCustomV2"]["whereIn"]=$conf["whereIn"];
12096
 
12097
			}#if end
12098
 
12099
		#如果 $conf["whereNotIn"] 存在
12100
		if(isset($conf["whereNotIn"])){
12101
 
12102
			#where not in 條件	
12103
			$conf["db"]["dataTableSelectCustomV2"]["whereNotIn"]=$conf["whereNotIn"];
12104
 
12105
			}#if end
12106
 
12107
		$dataTableSelectCustomV2=db::dataTableSelect($conf["db"]["dataTableSelectCustomV2"]);
12108
		unset($conf["db"]);
12109
 
12110
		#如果sql查詢失敗
12111
		#如果 $dataTableSelectCustomV2["status"] 等於 "false"
12112
		if($dataTableSelectCustomV2["status"]=="false"){
12113
 
12114
			#則設置執行錯誤的識別
12115
			$result["status"]="false";
12116
 
12117
			#設置錯誤訊息
12118
			$result["error"]=$dataTableSelectCustomV2;
12119
 
12120
			#回傳結果
12121
			return $result;
12122
 
12123
			}#if end
12124
 
12125
		#取得執行的sql字串
12126
		$result["sql"]=$dataTableSelectCustomV2["sql"];
12127
 
12128
		#解析 dataTableSelect($conf) 後的結果,亦即將執行sql語法後所得到的結果解析放進變數裏面
43 liveuser 12129
		#回傳結果:
1 liveuser 12130
		#$result["status"],執行結果"true"為成功;"false"為執行失敗。
12131
		#$result["error"],錯誤訊息陣列。
12132
		#$result["dataColumnName"],為資料欄位的名稱陣列.
12133
		#$result["dataColumnName"][$i]代表第一個欄位名稱.
12134
		#$result["dataContent"],爲資料的內容。
12135
		#$result["dataContent"][$conf["tableValueName"][$i]][$dataSetNum],
12136
			#$dataSetNum 爲第$dataSetNum+1筆資料
12137
			#$conf["tableValueName"][$i] 爲第 $i+1 個欄位的名稱
12138
		#$result["dataCount"],爲取得的資料筆數。
43 liveuser 12139
		#必填參數:
1 liveuser 12140
		$conf["db"]["sendQueryDataToVariabele"]["sqlQueryResult"]=$dataTableSelectCustomV2["sqlQueryResult"];#爲執行sql語法所獲得的查詢結果。
12141
		$conf["db"]["sendQueryDataToVariabele"]["tableValueName"]=$conf["columnYouWant"];#$conf["tableValueName"]=array();#爲該資料表列項目的每一項名稱,須爲陣列值,若為「array("*")」則代表所有欄位.
12142
		$conf["db"]["sendQueryDataToVariabele"]["valueName"]=$conf["columnYouWant"];#爲該資料表列項目的每一項所要對應的變數名稱,須爲陣列值。
12143
		$conf["db"]["sendQueryDataToVariabele"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
12144
		$conf["db"]["sendQueryDataToVariabele"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
43 liveuser 12145
		#可省略參數:
1 liveuser 12146
 
12147
		#如果存在 $conf["dbPassword"]
12148
		if(isset($conf["dbPassword"])){
12149
 
12150
			#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
12151
			$conf["db"]["sendQueryDataToVariabele"]["dbPassword"]=$conf["dbPassword"];
12152
 
12153
			}#if end
12154
 
12155
		#如果存在 $conf["dbPort"]
12156
		if(isset($conf["dbPort"])){
12157
 
12158
			#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表使用預設 port 3306
12159
			$conf["db"]["sendQueryDataToVariabele"]["dbPort"]=$conf["dbPort"];
12160
 
12161
			}#if end
12162
 
12163
		$sendQueryDataToVariabele=db::sendQueryDataToVariabele($conf["db"]["sendQueryDataToVariabele"]);
12164
		unset($conf["db"]);
12165
 
12166
		#如果 $sendQueryDataToVariabele["status"] 等於 "false"
12167
		if($sendQueryDataToVariabele["status"]=="false"){
12168
 
12169
			#設置執行錯誤的識別
12170
			$result["status"]="false";
12171
 
12172
			#設置錯誤訊息
12173
			$result["error"]=$sendQueryDataToVariabele;
12174
 
12175
			#回傳結果
12176
			return $result;
12177
 
12178
			}#if end
12179
 
12180
		#如果 $sendQueryDataToVariabele["dataContent"] 沒有設置
12181
		if(!isset($sendQueryDataToVariabele["dataContent"])){
12182
 
12183
			#那就代表沒有找到符合的資料
12184
			$sendQueryDataToVariabele["dataContent"]=NULL;
12185
 
12186
			#取得抓取到的資料內容
12187
			$result["dataContent"]=$sendQueryDataToVariabele["dataContent"];
12188
 
12189
			}#if end
12190
 
12191
		#反之代表有資料
12192
		else{
12193
 
12194
			#取得抓取到的資料內容
12195
			$result["dataContent"]=$sendQueryDataToVariabele["dataContent"];
12196
 
12197
			#抓取欄位名稱
12198
			$result["dataColumnName"]=$sendQueryDataToVariabele["dataColumnName"];
12199
 
12200
			}#else end
12201
 
12202
		#如果 $sendQueryDataToVariabele["dataCount"] 沒有設定
12203
		if(!isset($sendQueryDataToVariabele["dataCount"])){
12204
 
12205
			#則代表沒有抓到符合的資料
12206
			(int)$sendQueryDataToVariabele["dataCount"]=0;
12207
 
12208
			#取得資料筆數
12209
			$result["dataCount"]=$sendQueryDataToVariabele["dataCount"];
12210
 
12211
			}#if end
12212
 
12213
		#反之代表有符合的資料
12214
		else{
12215
 
12216
			#取得抓取到的資料筆數
12217
			$result["dataCount"]=$sendQueryDataToVariabele["dataCount"];
12218
 
12219
			}#else end
12220
 
12221
		#執行到這邊表示執行成功
12222
		$result["status"]="true";
12223
 
12224
		#回傳結果
12225
		return $result;
12226
 
12227
		}#function fastGetDbData end
12228
 
12229
	/*
43 liveuser 12230
	#函式說明:
1 liveuser 12231
	#透過一個父資料表取得多個關聯子資料表的資料,並合併成一張表
43 liveuser 12232
	#回傳結果:
1 liveuser 12233
	#$result["status"],執行結果"true"為成功;"false"為執行失敗。
12234
	#$result["error"],錯誤訊息陣列。
12235
	#$reuslt["function"],當前執行的函數
12236
	#$result["parentTable"]["dataContent"],爲合併了子資料表欄位的父資料表的內容。
12237
	#$result["parentTable"]["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
12238
		#$dataSetNum 爲第$dataSetNum+1筆資料
12239
		#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
12240
	#$result["parentTable"]["dataCount"],爲取得的資料筆數。
43 liveuser 12241
	#必填參數:
1 liveuser 12242
	#$conf["dbAddress"],字串陣列,爲每個dbServer的位置。
12243
	$conf["dbAddress"]=array($dbAddress);
12244
	#$conf["dbAccount"],字串陣列,爲登入每個dbServer的帳號。
12245
	$conf["dbAccount"]=array($dbAccount);
12246
	#$conf["dbName"],字串陣列,爲每個要存取的資料庫名稱
12247
	$conf["dbName"]=array($dbName);
12248
	#$conf["tableName"],字串陣列,爲每個要存取的資料表名稱,$conf["tableName"][0]為父資料表.
12249
	$conf["tableName"]=array("");
12250
	#$conf["linkColumnName"]=array(array(""));#二維字串陣列,為可以從父表關連到其他資料表的欄位名稱.
12251
		#$conf["linkColumnName"][$i]=array("parentColumnName","childColumnName"),為父資料表的"parentColumnName"欄位跟第$i+1個關聯資料表的"childColumnName"關聯.
12252
	$conf["linkColumnName"]=array(array(""));
12253
	#$conf["columnYouWant"]=array(array(""));#二維字串陣列,為每個資料表依序想要的欄位.
12254
	$conf["columnYouWant"]=array(array(""));#二維字串陣列,為每個資料表依序想要的欄位.
43 liveuser 12255
	#可省略參數:
1 liveuser 12256
	#$conf["dbPassword"],字串陣列,爲要存取每個dbServer的密碼
12257
	#$conf["dbPassword"]=array($dbPassword);
12258
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
12259
	#$conf["dbPort"]="";
12260
	#$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。
12261
	#$conf["WhereColumnName"]=array("");
12262
	#$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
12263
	#$conf["WhereColumnValue"]=array("");	
12264
	#$conf["WhereColumnCombine"],字串陣列,用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
12265
	#$conf["WhereColumnCombine"]=array("");
12266
	#$conf["WhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
12267
	#$conf["WhereColumnOperator"]=array("");
12268
	#$conf["WhereColumnAndOr"],字串陣列,用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
12269
	#$conf["WhereColumnAndOr"]=array("");
12270
	#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
12271
	#$conf["whereIn"]=array(array("colName",array("a","b","c")));
12272
	#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
12273
	#$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
12274
	#$conf["orderItem"],字串,排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
12275
	#$conf["orderItem"]="";
12276
	#$conf["ascORdesc"],字串,要低增還是遞減排序,asc爲遞增;desc爲遞減。
12277
	#$conf["ascORdesc"]="";
12278
	#$conf["numberStart"],字串,從第幾筆開始讀取,預設為"0",代筆第一筆。
12279
	#$conf["numberStart"]="0";
12280
	#$conf["numLimit"],字串,要取幾筆資料,可以省略,省略則表示不限制數目。
12281
	#$conf["numLimit"]="30";
12282
	#$conf["groupBy"],字串陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
12283
	#$conf["groupBy"]=array();
185 liveuser 12284
	#參考資料:
12285
	#無.
43 liveuser 12286
	#備註:
12287
	#無.
1 liveuser 12288
	*/
12289
	public static function fastGetMultiLinkedDbData(&$conf){
12290
 
12291
		#初始化要回傳的內容
12292
		$result=array();
12293
 
12294
		#取得當前執行的函數名稱
12295
		$result["function"]=__FUNCTION__;
12296
 
12297
		#如果 $conf 不為陣列
12298
		if(gettype($conf)!="array"){
12299
 
12300
			#設置執行失敗
12301
			$result["status"]="false";
12302
 
12303
			#設置執行錯誤訊息
12304
			$result["error"][]="\$conf變數須為陣列形態";
12305
 
12306
			#如果傳入的參數為 null
12307
			if($conf==null){
12308
 
12309
				#設置執行錯誤訊息
12310
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
12311
 
12312
				}#if end
12313
 
12314
			#回傳結果
12315
			return $result;
12316
 
12317
			}#if end
12318
 
12319
		#檢查參數
43 liveuser 12320
		#函式說明:
1 liveuser 12321
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12322
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12323
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12324
		#$result["function"],當前執行的函式名稱.
12325
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12326
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12327
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12328
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
43 liveuser 12329
		#必填參數:
1 liveuser 12330
		#$conf["variableCheck.checkArguments"]["varInput"],陣列變數,要檢查的陣列變數.
12331
		$conf["variableCheck.checkArguments"]["varInput"]=&$conf;
12332
		#$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12333
		$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","dbName","tableName","linkColumnName","columnYouWant");
12334
		#$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
12335
		$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array","array","array");
12336
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12337
		$conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
43 liveuser 12338
		#可省略參數:
1 liveuser 12339
		#$conf["variableCheck.checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
12340
		#$conf["variableCheck.checkArguments"]["canBeEmptyString"]="false";
12341
		#$conf["variableCheck.checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12342
		$conf["variableCheck.checkArguments"]["skipableVariableName"]=array("dbPassword","WhereColumnName","WhereColumnValue","WhereColumnCombine","WhereColumnOperator","WhereColumnAndOr","orderItem","ascORdesc","numberStart","numLimit","groupBy","whereIn","whereNotIn");
12343
		#$conf["variableCheck.checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
12344
		$conf["variableCheck.checkArguments"]["skipableVariableType"]=array("array","array","array","array","array","array","string","string","string","string","array","array","array");
12345
		#$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定.
12346
		#$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"]=array("");
12347
		$checkResult=variableCheck::checkArguments($conf["variableCheck.checkArguments"]);
12348
		unset($conf["variableCheck.checkArguments"]);
12349
 
12350
		#如果檢查出錯
12351
		if($checkResult["status"]=="false"){
12352
 
12353
			#設置錯誤識別
12354
			$result["status"]="false";
12355
 
12356
			#設置錯誤訊息
12357
			$result["error"]=$checkResult;
12358
 
12359
			#回傳結果
12360
			return $result;
12361
 
12362
			}#if end
12363
 
12364
		#如果檢查出錯
12365
		if($checkResult["passed"]=="false"){
12366
 
12367
			#設置錯誤識別
12368
			$result["status"]="false";
12369
 
12370
			#設置錯誤訊息
12371
			$result["error"]=$checkResult;
12372
 
12373
			#回傳結果
12374
			return $result;
12375
 
12376
			}#if end
12377
 
12378
		#取得父表的資料
43 liveuser 12379
		#函式說明:
1 liveuser 12380
		#一次取得資料庫、表的資料
43 liveuser 12381
		#回傳結果:
1 liveuser 12382
		#$result["status"],執行結果"true"為成功;"false"為執行失敗。
12383
		#$result["error"],錯誤訊息陣列。
12384
		#$result["dataContent"],爲資料的內容。
12385
			#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
12386
			#$dataSetNum 爲第$dataSetNum+1筆資料
12387
			#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
12388
		#$result["dataCount"],爲取得的資料筆數。
43 liveuser 12389
		#必填參數:
1 liveuser 12390
		$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"][0];#爲dbServer的位置。
12391
		$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"][0];#爲登入dbServer的帳號。
12392
		$conf["db"]["fastGetDbData"]["dbName"]=$conf["dbName"][0];#爲要存取的資料庫名稱
12393
		$conf["db"]["fastGetDbData"]["tableName"]=$conf["tableName"][0];#爲要存取的資料表名稱
12394
		$conf["db"]["fastGetDbData"]["columnYouWant"]=$conf["columnYouWant"][0];#你想要的欄位!
43 liveuser 12395
		#可省略參數:
1 liveuser 12396
 
12397
		#如果 $conf["dbPassword"][0] 有設置
12398
		if(isset($conf["dbPassword"][0])){
12399
 
12400
			$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"][0];#爲要存取dbServer的密碼
12401
 
12402
			}#if end
12403
 
12404
		#如果 $conf["WhereColumnName"] 有設置
12405
		if(isset($conf["WhereColumnName"])){
12406
 
12407
			$conf["db"]["fastGetDbData"]["WhereColumnName"]=$conf["WhereColumnName"];#用於判斷語句的欄位項目陣列。
12408
 
12409
			}#if end
12410
 
12411
		#如果 $conf["WhereColumnValue"] 有設置
12412
		if(isset($conf["WhereColumnValue"])){
12413
 
12414
			$conf["db"]["fastGetDbData"]["WhereColumnValue"]=$conf["WhereColumnValue"];#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
12415
 
12416
			}#if end
12417
 
12418
		#如果 $conf["WhereColumnCombine"] 有設置
12419
		if(isset($conf["WhereColumnCombine"])){
12420
 
12421
			$conf["db"]["fastGetDbData"]["WhereColumnCombine"]=$conf["WhereColumnCombine"];#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
12422
 
12423
			}#if end
12424
 
12425
		#如果 $conf["WhereColumnOperator"] 有設置
12426
		if(isset($conf["WhereColumnOperator"])){
12427
 
12428
			$conf["db"]["fastGetDbData"]["WhereColumnOperator"]=$conf["WhereColumnOperator"];#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
12429
 
12430
			}#if end
12431
 
12432
		#如果 $conf["WhereColumnAndOr"][$i] 有設置
12433
		if(isset($conf["WhereColumnAndOr"])){
12434
 
12435
			$conf["db"]["fastGetDbData"]["WhereColumnAndOr"]=$conf["WhereColumnAndOr"];#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
12436
 
12437
			}#if end
12438
 
12439
		#如果 $conf["orderItem"] 有設置
12440
		if(isset($conf["orderItem"])){
12441
 
12442
			$conf["db"]["fastGetDbData"]["orderItem"]=$conf["orderItem"];#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
12443
 
12444
			}#if end
12445
 
12446
		#如果 $conf["ascORdesc"] 有設置
12447
		if(isset($conf["ascORdesc"])){
12448
 
12449
			$conf["db"]["fastGetDbData"]["ascORdesc"]=$conf["ascORdesc"];#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
12450
 
12451
			}#if end
12452
 
12453
		#如果 $conf["numberStart"] 有設置
12454
		if(isset($conf["numberStart"])){
12455
 
12456
			$conf["db"]["fastGetDbData"]["numberStart"]=$conf["numberStart"];#為從第幾筆開始讀取,預設為0,代筆第一筆。
12457
 
12458
			}#if end
12459
 
12460
		#如果 $conf["numLimit"] 有設置
12461
		if(isset($conf["numLimit"])){
12462
 
12463
			$conf["db"]["fastGetDbData"]["numLimit"]=$conf["numLimit"];#為要取幾筆資料,可以省略,省略則表示不限制數目。
12464
 
12465
			}#if end
12466
 
12467
		#如果 $conf["groupBy"] 有設置
12468
		if(isset($conf["groupBy"])){
12469
 
12470
			$conf["db"]["fastGetDbData"]["groupBy"]=$conf["groupBy"];#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
12471
 
12472
			}#if end
12473
 
12474
		#如果 $conf["whereIn"] 存在
12475
		if(isset($conf["whereIn"])){
12476
 
12477
			#where in 條件		
12478
			$conf["db"]["fastGetDbData"]["whereIn"]=$conf["whereIn"];
12479
 
12480
			}#if end
12481
 
12482
		#如果 $conf["whereNotIn"] 存在
12483
		if(isset($conf["whereNotIn"])){
12484
 
12485
			#where not in 條件	
12486
			$conf["db"]["fastGetDbData"]["whereNotIn"]=$conf["whereNotIn"];
12487
 
12488
			}#if end
12489
 
12490
		#儲存到 $result["mainTable"] 陣列裡面
12491
		$result["parentTable"]=db::fastGetDbData($conf["db"]["fastGetDbData"]);
12492
		unset($conf["db"]["fastGetDbData"]);
12493
 
12494
		#如果 $result["mainTable"]["status"] 為 "false"
12495
		if($result["parentTable"]["status"]=="false"){
12496
 
12497
			#取得錯誤訊息
12498
			$result["error"]=$result["parentTable"]["error"];
12499
 
12500
			#設置執行結果為 "false"
12501
			$result["status"]="false";
12502
 
12503
			#回傳結果
12504
			return $result;
12505
 
12506
			}#if end
12507
 
12508
		#根據 $conf["linkColumnName"] 的數量
12509
		for($i=0;$i<count($conf["linkColumnName"]);$i++){
12510
 
12511
			#取得父資料表的關聯欄位名稱
12512
			$parentTableLinkColumnName=$conf["linkColumnName"][$i][0];
12513
 
12514
			#取得子資料表的關聯欄位名稱
12515
			$childTableLinkColumnName=$conf["linkColumnName"][$i][1];
12516
 
12517
			#根據父資料表的資料筆數
12518
			for($j=0;$j<$result["parentTable"]["dataCount"];$j++){
12519
 
12520
				#如果要連結的欄位不在 select 的欄位裡面
12521
				if(!isset($result["parentTable"]["dataContent"][$parentTableLinkColumnName])){
12522
 
12523
					#設置執行錯誤
12524
					$result["status"]="false";
12525
 
12526
					#設置執行錯誤內容
12527
					$result["error"]="欄位 ".$parentTableLinkColumnName." 必須在參數 columnYouWant 裡面.";
12528
 
12529
					#回傳結果
12530
					return $result;
12531
 
12532
					}#if end
12533
 
12534
				#父資料表第$j筆資料關聯欄位的數值內容
12535
				$parentTableLinkColumnValue=$result["parentTable"]["dataContent"][$parentTableLinkColumnName][$j];
12536
 
12537
				#var_dump($parentTableLinkColumnValue);
12538
 
12539
				#根據第$j筆資料的父關聯欄位數值來尋找子關聯資料表的欄位數值
43 liveuser 12540
				#函式說明:
1 liveuser 12541
				#一次取得資料庫、表的資料
43 liveuser 12542
				#回傳結果:
1 liveuser 12543
				#$result["status"],執行結果"true"為成功;"false"為執行失敗。
12544
				#$result["error"],錯誤訊息陣列。
12545
				#$result["dataContent"],爲資料的內容。
12546
				#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
12547
					#$dataSetNum 爲第$dataSetNum+1筆資料
12548
					#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
12549
				#$result["dataCount"],爲取得的資料筆數。
43 liveuser 12550
				#必填參數:
1 liveuser 12551
				$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"][$i+1];#爲dbServer的位置。
12552
				$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"][$i+1];#爲登入dbServer的帳號。
12553
				$conf["db"]["fastGetDbData"]["dbName"]=$conf["dbName"][$i+1];#爲要存取的資料庫名稱
12554
				$conf["db"]["fastGetDbData"]["tableName"]=$conf["tableName"][$i+1];#爲要存取的資料表名稱
12555
				$conf["db"]["fastGetDbData"]["columnYouWant"]=$conf["columnYouWant"][$i+1];#你想要的欄位!
43 liveuser 12556
				#可省略參數:
1 liveuser 12557
 
12558
				#如果 $conf["dbPassword"][$i+1] 有設定
12559
				if(isset($conf["dbPassword"][$i+1])){
12560
 
12561
					#則設置其連線密碼
12562
					$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"][$i+1];#爲要存取dbServer的密碼
12563
 
12564
					}#if end
12565
 
12566
				#如果 $conf["dbPort"][$i+1] 有設定
12567
				if(isset($conf["dbPort"][$i+1])){
12568
 
12569
					#則設置其連線的 port
12570
					$conf["db"]["fastGetDbData"]["dbPort"]=$conf["dbPort"][$i+1];#爲要存取dbServer的port
12571
 
12572
					}#if end
12573
 
12574
				$conf["db"]["fastGetDbData"]["WhereColumnName"]=array($childTableLinkColumnName);#用於判斷語句的欄位項目陣列。
12575
				$conf["db"]["fastGetDbData"]["WhereColumnValue"]=array($parentTableLinkColumnValue);#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
12576
				#$conf["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
12577
				#$conf["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
12578
				#$conf["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
12579
				#$conf["orderItem"]="";#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
12580
				#$conf["ascORdesc"]="";#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
12581
				#$conf["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
12582
				#$conf["numLimit"]="30";#為要取幾筆資料,可以省略,省略則表示不限制數目。
12583
				#$conf["groupBy"]=array("");#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
12584
				$childTable[$j]=db::fastGetDbData($conf["db"]["fastGetDbData"]);
12585
				unset($conf["db"]["fastGetDbData"]);
12586
 
12587
				#如果取得資料失敗
12588
				if($childTable[$j]["status"]=="false"){
12589
 
12590
					#取得錯誤訊息
12591
					$result["error"]=$childTable[$j];
12592
 
12593
					#設置執行結果為 "false"
12594
					$result["status"]="false";
12595
 
12596
					#回傳結果
12597
					return $result;
12598
 
12599
					}#if end
12600
 
12601
				#如果 $childTable[$j]["dataContent"] 有設置,則代表有符合的資料
12602
				if(isset($childTable[$j]["dataContent"])){
12603
 
12604
					#針對每個取得的新欄位
12605
					foreach($childTable[$j]["dataContent"] as $newColumnNameArray=>$newColumnNameValue){
12606
 
12607
						#新增第$j筆的欄位名稱與數值
12608
						$result["parentTable"]["dataContent"][$conf["tableName"][$i+1].".".$newColumnNameArray][$j]=$newColumnNameValue[0];
12609
 
12610
						}#foreach end
12611
 
12612
					}#if end
12613
 
12614
				#反之代表 $childTable[$j]["dataContent"] 沒有設置,沒有符合的資料
12615
				else{
12616
 
12617
					#根據每個要取得的欄位名稱
12618
					foreach($conf["columnYouWant"][$i+1] as $newColumnName){
12619
 
12620
						#新增第$j筆的欄位名稱與數值
12621
						$result["parentTable"]["dataContent"][$conf["tableName"][$i+1].".".$newColumnName][$j]="";
12622
 
12623
						}#foreach end
12624
 
12625
					}#else end
12626
 
12627
				}#for end
12628
 
12629
			}#for end
12630
 
12631
		#執行到這邊代表執行成功
12632
		#設置執行結果為 "true"
12633
		$result["status"]="true";
12634
 
12635
		#回傳結果
12636
		return $result;
12637
 
12638
		}#function fastGetMutiLinkedDbData end
12639
 
12640
	/*
12641
	#函式說明:
12642
	#透過php來join多張資料表資料,提供各個欄位的包含資料庫、資料表、的資訊,會產生sql inner join的效果,資料會越來越多.
43 liveuser 12643
	#回傳結果:
1 liveuser 12644
	#$result["status"],執行結果"true"為成功;"false"為執行失敗。
12645
	#$result["error"],錯誤訊息陣列。
12646
	#$reuslt["function"],當前執行的函數
12647
	#$result["content"],爲合併了子資料表欄位的父資料表的內容。
12648
	#$result["content"][$conf["WhereColumnName"][$i]][$dataSetNum]
12649
		#$dataSetNum 爲第$dataSetNum+1筆資料
12650
		#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
12651
	#$result["parentTable"]["dataCount"],爲取得的資料筆數。
43 liveuser 12652
	#必填參數:
1 liveuser 12653
	#$conf["dbInfo"]["資料庫名稱"],字串陣列,爲要存取的"資料庫名稱"的連線資訊.
12654
	#$conf["dbIfno"]["資料庫名稱"]["dbAddr"],字串,dbServer的位置.
12655
	#$conf["dbInfo"]["資料庫名稱"]["dbAddr"]="";
12656
	#$conf["dbIfno"]["資料庫名稱"]["dbAcct"],字串,dbServer的連線帳號.
12657
	#$conf["dbInfo"]["資料庫名稱"]["dbAcct"]="";	
12658
	#$conf["mainTable"],字串,為 主資料庫.資料表 的名稱,例如 "dbA.dtA".
12659
	$conf["mainTable"]="";
12660
	#$conf["linkColumnName"],二字串陣列,為資料表間相連結的欄位名稱,格式為 array("mergedDb.mergedDt.mergedCol","linkDb.linkDt.linkCol") 就代表當前組好的欄位 mergedDb.mergedDt.mergedCol 跟資料庫 linkDB 表 linkDt 欄位 linkCol 進行資料的配對。
12661
	$conf["linkColumnName"]=array(array(""));	
43 liveuser 12662
	#可省略參數:
1 liveuser 12663
	#$conf["dbInfo"]["資料庫名稱"]["dbPass"],字串,dbServer的連線密碼.
12664
	#$conf["dbInfo"]["資料庫名稱"]["dbPass"]="";
12665
	#$conf["dbInfo"]["資料庫名稱"]["dbPort"],字串,db連線用的port.
12666
	#$conf["dbInfo"]["資料庫名稱"]["dbPort"]="";
12667
	#$conf["columnYouWant"],字串陣列,為想要的資料表欄位,格式為 "dbName.dtName.colName".
12668
	#$conf["columnYouWant"]=array();
12669
	#$conf["mainDtWhereColName"],字串陣列,用於主表判斷語句的欄位項目陣列.
12670
	#$conf["mainDtWhereColName"]=array("");
12671
	#$conf["mainDtWhereColVal"]=,字串陣列,用於主表判斷語句的欄位項目數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容.
12672
	#$conf["mainDtWhereColVal"]=array("");
12673
	#$conf["mainDtWhereColCombine"],字串陣列,用於主表判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
12674
	#$conf["mainDtWhereColCombine"]=array("");
12675
	#$conf["mainWhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
12676
	#$conf["mainWhereColumnOperator"]=array("");
12677
	#$conf["mainWhereColumnAndOr"],字串陣列,用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
12678
	#$conf["mainWhereColumnAndOr"]=array("");
12679
	#$conf["mainWhereIn"],字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
12680
	#$conf["mainWhereIn"]=array(array("colName",array("a","b","c")));
12681
	#$conf["mainWhereNotIn"],字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
12682
	#$conf["mainWhereNotIn"]=array(array("colName",array("a","b","c")));
12683
	#$conf["mainNumberStart"],字串,從第幾筆開始讀取,預設為"0",代筆第一筆。
12684
	#$conf["mainNumberStart"]="0";
12685
	#$conf["mainNumLimit"],字串,要取幾筆資料,可以省略,省略則表示不限制數目.
12686
	#$conf["mainNumLimit"]="30";
12687
	#$conf["mainGroupBy"],字串陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
12688
	#$conf["mainGroupBy"]=array();
12689
	#$conf["mainOrderItem"],字串,組好的資料的排序項目依據
12690
	#$conf["mainOrderItem"]="";
12691
	#$conf["mainAscORdesc"],字串,組好的資料要低增還是遞減排序,asc爲遞增;desc爲遞減,預設不做處理.
12692
	#$conf["mainAscORdesc"]="";	
185 liveuser 12693
	#參考資料:
12694
	#無.
43 liveuser 12695
	#備註:
12696
	#無.
1 liveuser 12697
	*/
12698
	public static function joinByPHP(&$conf=array()){
12699
 
12700
		#初始化要回傳的內容
12701
		$result=array();
12702
 
12703
		#取得當前執行的函數名稱
12704
		$result["function"]=__FUNCTION__;
12705
 
12706
		#如果 $conf 不為陣列
12707
		if(gettype($conf)!="array"){
12708
 
12709
			#設置執行失敗
12710
			$result["status"]="false";
12711
 
12712
			#設置執行錯誤訊息
12713
			$result["error"][]="\$conf變數須為陣列形態";
12714
 
12715
			#如果傳入的參數為 null
12716
			if($conf==null){
12717
 
12718
				#設置執行錯誤訊息
12719
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
12720
 
12721
				}#if end
12722
 
12723
			#回傳結果
12724
			return $result;
12725
 
12726
			}#if end
12727
 
12728
		#檢查參數
43 liveuser 12729
		#函式說明:
1 liveuser 12730
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12731
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12732
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12733
		#$result["function"],當前執行的函式名稱.
12734
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12735
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12736
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12737
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
43 liveuser 12738
		#必填參數:
1 liveuser 12739
		#$conf["variableCheck.checkArguments"]["varInput"],陣列變數,要檢查的陣列變數.
12740
		$conf["variableCheck.checkArguments"]["varInput"]=&$conf;
12741
		#$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12742
		$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("dbInfo","mainTable","linkColumnName");
12743
		#$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
12744
		$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array("array","string","array");
12745
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12746
		$conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
43 liveuser 12747
		#可省略參數:
1 liveuser 12748
		#$conf["variableCheck.checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
12749
		#$conf["variableCheck.checkArguments"]["canBeEmptyString"]="false";
12750
		#$conf["variableCheck.checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12751
		$conf["variableCheck.checkArguments"]["skipableVariableName"]=array("columnYouWant","mainDtWhereColName","mainDtWhereColVal","mainDtWhereColCombine","mainWhereColumnOperator","mainWhereColumnAndOr","mainWhereIn","mainWhereNotIn","mainNumberStart","mainNumLimit","mainGroupBy","mainOrderItem","mainAscORdesc");
12752
		#$conf["variableCheck.checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
12753
		$conf["variableCheck.checkArguments"]["skipableVariableType"]=array("array","array","array","array","array","array","array","array","string","string","array","string","string");
12754
		#$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定.
12755
		#$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"]=array("");
12756
		$checkResult=variableCheck::checkArguments($conf["variableCheck.checkArguments"]);
12757
		unset($conf["variableCheck.checkArguments"]);
12758
 
12759
		#如果檢查出錯
12760
		if($checkResult["status"]=="false"){
12761
 
12762
			#設置錯誤識別
12763
			$result["status"]="false";
12764
 
12765
			#設置錯誤訊息
12766
			$result["error"]=$checkResult;
12767
 
12768
			#回傳結果
12769
			return $result;
12770
 
12771
			}#if end
12772
 
12773
		#如果檢查出錯
12774
		if($checkResult["passed"]=="false"){
12775
 
12776
			#設置錯誤識別
12777
			$result["status"]="false";
12778
 
12779
			#設置錯誤訊息
12780
			$result["error"]=$checkResult;
12781
 
12782
			#回傳結果
12783
			return $result;
12784
 
12785
			}#if end
12786
 
12787
		#取得 $conf["mainTable"] 的資料
12788
 
12789
		#檢查主表是否為 db.dt 的
12790
		$foundDot=strpos($conf["mainTable"],'.');
12791
 
12792
		#如果不是
12793
		if(!$foundDot){
12794
 
12795
			#設置錯誤識別
12796
			$result["status"]="false";
12797
 
12798
			#設置錯誤訊息
12799
			$result["error"][]="參數 \$conf[\"mainTable\"] 必須為 資料庫名稱.資料表名稱";
12800
 
12801
			#回傳結果
12802
			return $result;
12803
 
12804
			}#if end
12805
 
12806
		#反之
12807
		else{
12808
 
12809
			#用 . 去切割字串
12810
			$dbdtsplitedstr=explode('.',$conf["mainTable"]);
12811
 
12812
			#如果切割出來不等於兩段
12813
			if(count($dbdtsplitedstr)!==2){
12814
 
12815
				#設置錯誤識別
12816
				$result["status"]="false";
12817
 
12818
				#設置錯誤訊息
12819
				$result["error"][]="參數 \$conf[\"mainTable\"] 必須為 資料庫名稱.資料表名稱";
12820
 
12821
				#回傳結果
12822
				return $result;
12823
 
12824
				}#if end
12825
 
12826
			#取得 mainTable 的 db name
12827
			$mainDb=&$dbdtsplitedstr[0];
12828
 
12829
			#取得 mainTable 的名稱
12830
			$mainDt=&$dbdtsplitedstr[1];
12831
 
12832
			}#else end
12833
 
12834
		#若主資料表連線參數不存在
12835
		if(!isset($conf["dbInfo"][$mainDb])){
12836
 
12837
			#設置錯誤識別
12838
			$result["status"]="false";
12839
 
12840
			#設置錯誤訊息
12841
			$result["error"][]="參數 \$conf[\"dbInfo\"][$mainDb] 必須提供";
12842
 
12843
			#回傳結果
12844
			return $result;
12845
 
12846
			}#if end
12847
 
12848
		#檢查主表的參數
12849
		#函式說明:
12850
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
12851
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
12852
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
12853
		#$result["function"],當前執行的函式名稱.
12854
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
12855
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
12856
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
12857
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
12858
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
12859
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
12860
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
12861
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
43 liveuser 12862
		#必填參數:
1 liveuser 12863
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
12864
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf["dbInfo"][$mainDb];	
12865
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
12866
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
12867
		#可以省略的參數:
12868
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
12869
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddr","dbAcct");
12870
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
12871
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
12872
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
12873
		$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
12874
		#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
12875
		#$conf["canNotBeEmpty"]=array();
12876
		#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
12877
		#$conf["canBeEmpty"]=array();
12878
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
12879
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("dbPass","dbPort");
12880
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
12881
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPass","dbPort");
12882
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
12883
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
12884
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
12885
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null);
12886
		#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
12887
		#$conf["disallowAllSkipableVarIsEmpty"]="";
12888
		#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
12889
		#$conf["disallowAllSkipableVarIsEmptyArray"]="";
12890
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
12891
		#$conf["arrayCountEqualCheck"][]=array();
43 liveuser 12892
		#參考資料:
1 liveuser 12893
		#array_keys=>http://php.net/manual/en/function.array-keys.php
12894
		$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
12895
		unset($conf["variableCheck::checkArguments"]);
12896
 
12897
		#如果執行失敗
12898
		if($checkArguments["status"]==="false"){
12899
 
12900
			#設置錯誤識別
12901
			$result["status"]="false";
12902
 
12903
			#設置錯誤訊息
12904
			$result["error"]=$checkArguments;
12905
 
12906
			#回傳結果
12907
			return $result;
12908
 
12909
			}#if end
12910
 
12911
		#如果檢查不通過
12912
		if($checkArguments["passed"]==="false"){
12913
 
12914
			#設置錯誤識別
12915
			$result["status"]="false";
12916
 
12917
			#設置錯誤訊息
12918
			$result["error"]=$checkArguments;
12919
 
12920
			#回傳結果
12921
			return $result;
12922
 
12923
			}#if end
12924
 
43 liveuser 12925
		#函式說明:
1 liveuser 12926
		#一次取得資料庫、表的資料
43 liveuser 12927
		#回傳結果:
1 liveuser 12928
		#$result["status"],執行結果"true"為成功;"false"為執行失敗。
12929
		#$result["error"],錯誤訊息陣列。
12930
		#$result["function"],當前執行的漢書名稱.
12931
		#$result["dataColumnName"],抓取的資料欄位名稱陣列.
12932
			#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
12933
		#$result["dataContent"],爲資料的內容。
12934
		#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
12935
			#$dataSetNum 爲第$dataSetNum+1筆資料
12936
			#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
12937
		#$result["dataCount"],爲取得的資料筆數。
12938
		#$result["sql"],執行的sql字串.
43 liveuser 12939
		#必填參數:
1 liveuser 12940
		$conf["db::fastGetDbData"]["dbAddress"]=$conf["dbInfo"][$mainDb]["dbAddr"];#爲dbServer的位置。
12941
		$conf["db::fastGetDbData"]["dbAccount"]=$conf["dbInfo"][$mainDb]["dbAcct"];#爲登入dbServer的帳號。
12942
		$conf["db::fastGetDbData"]["dbName"]=$mainDb;#爲要存取的資料庫名稱
12943
		$conf["db::fastGetDbData"]["tableName"]=$mainDt;#爲要存取的資料表名稱
12944
		$conf["db::fastGetDbData"]["columnYouWant"]=array("*");#你想要的欄位!,若設為「array("*")」則代表全部欄位.
43 liveuser 12945
		#可省略參數:
1 liveuser 12946
 
12947
		#如果有給予連線密碼
12948
		if(isset($conf["dbInfo"][$mainDb]["dbPass"])){
12949
 
12950
			$conf["db::fastGetDbData"]["dbPassword"]=$conf["dbInfo"][$mainDb]["dbPass"];#爲要存取dbServer的密碼
12951
 
12952
			}#if end
12953
 
12954
		#如果有給予連線port
12955
		if(isset($conf["dbInfo"][$mainDb]["dbPort"])){
12956
 
12957
			$conf["db::fastGetDbData"]["dbPort"]=$conf["dbInfo"][$mainDb]["dbPort"];#爲要存取dbServer的port
12958
 
12959
			}#if end
12960
 
12961
		#如果有設置 $conf["mainDtWhereColName"]
12962
		if(isset($conf["mainDtWhereColName"])){
12963
 
12964
			#設置參數
12965
			$conf["db::fastGetDbData"]["WhereColumnName"]=$conf["mainDtWhereColName"];
12966
 
12967
			}#if end
12968
 
12969
		#如果有設置 $conf["mainDtWhereColVal"]
12970
		if(isset($conf["mainDtWhereColVal"])){
12971
 
12972
			#設置參數
12973
			$conf["db::fastGetDbData"]["WhereColumnValue"]=$conf["mainDtWhereColVal"];#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
12974
 
12975
			}#if end
12976
 
12977
		#如果有設置 $conf["mainDtWhereColCombine"]
12978
		if(isset($conf["mainDtWhereColCombine"])){
12979
 
12980
			#設置參數
12981
			$conf["db::fastGetDbData"]["WhereColumnCombine"]=$conf["mainDtWhereColCombine"];#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
12982
 
12983
			}#if end
12984
 
12985
		#如果有設置 $conf["mainWhereColumnOperator"]
12986
		if(isset($conf["mainWhereColumnOperator"])){
12987
 
12988
			#設置參數
12989
			$conf["db::fastGetDbData"]["WhereColumnOperator"]=$conf["mainWhereColumnOperator"];#用於判斷語句的比較符號陣列,可以用的符號有「"="、"!="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
12990
 
12991
			}#if end
12992
 
12993
		#如果有設置 $conf["mainWhereColumnAndOr"]
12994
		if(isset($conf["mainWhereColumnAndOr"])){
12995
 
12996
			#設置參數
12997
			$conf["db::fastGetDbData"]["WhereColumnAndOr"]=$conf["mainWhereColumnAndOr"];#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
12998
 
12999
			}#if end
13000
 
13001
		#如果有設置 $conf["mainWhereIn"]
13002
		if(isset($conf["mainWhereIn"])){
13003
 
13004
			#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
13005
			$conf["db::fastGetDbData"]["whereIn"]=$conf["mainWhereIn"];
13006
 
13007
			}#if end
13008
 
13009
		#如果有設置 $conf["mainWhereNotIn"]
13010
		if(isset($conf["mainWhereNotIn"])){
13011
 
13012
			#設置參數
13013
			#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
13014
			$conf["db::fastGetDbData"]["whereNotIn"]=$conf["mainWhereNotIn"];
13015
 
13016
			}#if end
13017
 
13018
		#如果有設置 $conf["mainNumberStart"]
13019
		if(isset($conf["mainNumberStart"])){
13020
 
13021
			#設置參數
13022
			$conf["db::fastGetDbData"]["numberStart"]=$conf["mainNumberStart"];#為從第幾筆開始讀取,預設為0,代筆第一筆。
13023
 
13024
			}#if end
13025
 
13026
		#如果有設置 $conf["mainNumLimit"]
13027
		if(isset($conf["mainNumLimit"])){
13028
 
13029
			#設置參數
13030
			$conf["db::fastGetDbData"]["numLimit"]=$conf["mainNumLimit"];#為要取幾筆資料,可以省略,省略則表示不限制數目。
13031
 
13032
			}#if end
13033
 
13034
		#如果有設置 $conf["mainGroupBy"]
13035
		if(isset($conf["mainGroupBy"])){
13036
 
13037
			#設置參數
13038
			$conf["db::fastGetDbData"]["groupBy"]=$conf["mainGroupBy"];#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
13039
 
13040
			}#if end
13041
 
13042
		#如果有設置 $conf["mainOrderItem"]
13043
		if(isset($conf["mainOrderItem"])){
13044
 
13045
			#設置參數
13046
			$conf["db::fastGetDbData"]["orderItem"]=$conf["mainOrderItem"];#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
13047
 
13048
			}#if end
13049
 
13050
		#如果有設置 $conf["mainAscORdesc"]
13051
		if(isset($conf["mainAscORdesc"])){
13052
 
13053
			#設置參數
13054
			#$conf["mainAscORdesc"],字串,組好的資料要低增還是遞減排序,asc爲遞增;desc爲遞減,預設不做處理.
13055
			$conf["db::fastGetDbData"]["mainAscORdesc"]=$conf["mainAscORdesc"];
13056
 
13057
			}#if end
13058
 
13059
		$fastGetDbData=db::fastGetDbData($conf["db::fastGetDbData"]);
13060
		unset($conf["db::fastGetDbData"]);
13061
 
13062
		#如果執行失敗
13063
		if($fastGetDbData["status"]==="false"){
13064
 
13065
			#設置錯誤識別
13066
			$result["status"]="false";
13067
 
13068
			#設置錯誤訊息
13069
			$result["error"]=$fastGetDbData;
13070
 
13071
			#回傳結果
13072
			return $result;
13073
 
13074
			}#if end
13075
 
13076
		#var_dump($fastGetDbData);
13077
 
13078
		#初始化儲存合併好的資料
13079
		$merged=array();
13080
 
13081
		#如果該存在的變數不存在
13082
		if(!isset($fastGetDbData["dataColumnName"])){
13083
 
13084
			#設置錯誤識別
13085
			$result["status"]="false";
13086
 
13087
			#設置錯誤訊息
13088
			$result["error"]=$fastGetDbData;
13089
 
13090
			#回傳結果
13091
			return $result;
13092
 
13093
			}#if end
13094
 
13095
		#針對每個欄位
13096
		foreach($fastGetDbData["dataColumnName"] as $colName){
13097
 
13098
			#將當前資料的欄位用 dbName.dtName.dataColName 儲存
13099
			$merged[$mainDb.".".$mainDt.".".$colName]=$fastGetDbData["dataContent"][$colName];
13100
 
13101
			}#foreach end
13102
 
13103
		#移除變數節省記憶體
13104
		unset($fastGetDbData);
13105
 
13106
		#取得陣列元素數目
13107
		$mergedCount=count($merged);
13108
 
13109
		#移除以數字為欄位索引的變數
13110
		for($i=0;$i<$mergedCount/2;$i++){
13111
 
13112
			#移除索引
13113
			unset($merged[$i]);
13114
 
13115
			}#for end
13116
 
13117
		#var_dump($merged);exit;
13118
 
13119
		#針對每個 $conf["linkColumnName"] 
13120
		foreach($conf["linkColumnName"] as $linkCondition){
13121
 
13122
			#如果不是陣列
13123
			if(gettype($linkCondition)!=="array"){
13124
 
13125
				#設置錯誤識別
13126
				$result["status"]="false";
13127
 
13128
				#設置錯誤訊息
13129
				$result["error"][]="參數 linkColumnName 的陣列元素應該為陣列.";
13130
 
13131
				#回傳結果
13132
				return $result;
13133
 
13134
				}#if end
13135
 
13136
			#如果數量不為2
13137
			if(count($linkCondition)!==2){
13138
 
13139
				#設置錯誤識別
13140
				$result["status"]="false";
13141
 
13142
				#設置錯誤訊息
13143
				$result["error"][]="參數 linkColumnName 的陣列元素應為有兩個元素的陣列.";
13144
 
13145
				#回傳結果
13146
				return $result;
13147
 
13148
				}#if end
13149
 
13150
			#取得原始欄位的名稱
13151
			$oriCol=&$linkCondition[0];	
13152
 
13153
			#如果用來比對的原欄位不存在
13154
			if(!isset($merged[$oriCol])){
13155
 
13156
				#設置錯誤識別
13157
				$result["status"]="false";
13158
 
13159
				#設置錯誤訊息
13160
				$result["error"][]="用來比對的原始資料沒有欄位 「".$oriCol."」 存在.";
13161
 
13162
				#回傳結果
13163
				return $result;
13164
 
13165
				}#if end
13166
 
13167
			#取得要增加的欄位名稱
13168
			$newCol=&$linkCondition[1];	
13169
 
13170
			#檢查增加的欄位名稱是否有 "."
13171
			$foundDot=strpos($newCol,'.');
13172
 
13173
			#如果不是
13174
			if(!$foundDot){
13175
 
13176
				#設置錯誤識別
13177
				$result["status"]="false";
13178
 
13179
				#設置錯誤訊息
13180
				$result["error"][]="參數 linkColumnName 的欄位格式 ".$newCol." 必須為 資料庫名稱.資料表名稱.資料欄位名稱";
13181
 
13182
				#回傳結果
13183
				return $result;
13184
 
13185
				}#if end
13186
 
13187
			#反之
13188
			else{
13189
 
13190
				#用 . 去切割字串
13191
				$dbdtsplitedstr=explode('.',$newCol);
13192
 
13193
				#如果切割出來不等於兩段
13194
				if(count($dbdtsplitedstr)!==3){
13195
 
13196
					#設置錯誤識別
13197
					$result["status"]="false";
13198
 
13199
					#設置錯誤訊息
13200
					$result["error"][]="參數 linkColumnName 的欄位格式 ".$newCol." 必須為 資料庫名稱.資料表名稱.資料欄位名稱";
13201
 
13202
					#回傳結果
13203
					return $result;
13204
 
13205
					}#if end
13206
 
13207
				#取得 linkTable 的 db name
13208
				$linkDb=&$dbdtsplitedstr[0];
13209
 
13210
				#取得 linkTable 的名稱
13211
				$linkDt=&$dbdtsplitedstr[1];
13212
 
13213
				#取得 linkCol 的名稱
13214
				$linkCol=&$dbdtsplitedstr[2];
13215
 
13216
				}#else end
13217
 
13218
			#檢查次表的參數
13219
			#函式說明:
13220
			#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
13221
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13222
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
13223
			#$result["function"],當前執行的函式名稱.
13224
			#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13225
			#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13226
			#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
13227
			#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
13228
			#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
13229
			#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
13230
			#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
13231
			#$result["notNeedVar"],字串陣列,多餘的參數名稱.
43 liveuser 13232
			#必填參數:
1 liveuser 13233
			#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
13234
			$conf["variableCheck::checkArguments"]["varInput"]=&$conf["dbInfo"][$linkDb];	
13235
			#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
13236
			$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
13237
			#可以省略的參數:
13238
			#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
13239
			$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddr","dbAcct");
13240
			#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
13241
			$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
13242
			#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
13243
			$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
13244
			#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
13245
			#$conf["canNotBeEmpty"]=array();
13246
			#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
13247
			#$conf["canBeEmpty"]=array();
13248
			#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
13249
			$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("dbPass");
13250
			#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
13251
			$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPass");
13252
			#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
13253
			$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
13254
			#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
13255
			$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
13256
			#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
13257
			#$conf["disallowAllSkipableVarIsEmpty"]="";
13258
			#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
13259
			#$conf["disallowAllSkipableVarIsEmptyArray"]="";
13260
			#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
13261
			#$conf["arrayCountEqualCheck"][]=array();
43 liveuser 13262
			#參考資料:
1 liveuser 13263
			#array_keys=>http://php.net/manual/en/function.array-keys.php
13264
			$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
13265
			unset($conf["variableCheck::checkArguments"]);
13266
 
13267
			#var_dump($checkArguments);
13268
			#exit;
13269
 
13270
			#如果執行失敗
13271
			if($checkArguments["status"]==="false"){
13272
 
13273
				#設置錯誤識別
13274
				$result["status"]="false";
13275
 
13276
				#設置錯誤訊息
13277
				$result["error"]=$checkArguments;
13278
 
13279
				#回傳結果
13280
				return $result;
13281
 
13282
				}#if end
13283
 
13284
			#如果檢查不通過
13285
			if($checkArguments["passed"]==="false"){
13286
 
13287
				#設置錯誤識別
13288
				$result["status"]="false";
13289
 
13290
				#設置錯誤訊息
13291
				$result["error"]=$checkArguments;
13292
 
13293
				#回傳結果
13294
				return $result;
13295
 
13296
				}#if end
13297
 
13298
			#初始化新合併過後的資料
13299
			$newMerged=&$merged;
13300
 
13301
			#初始化儲存既有的欄位名稱
13302
			$mergedColName=array_keys($merged);
13303
 
13304
			#取得既有的欄位的數量
13305
			$mergedColCount=count($mergedColName);		
13306
 
13307
			#主表有幾筆資料就執行幾次
13308
			foreach($merged[$oriCol] as $index=>$mainColVal){
13309
 
43 liveuser 13310
				#函式說明:
1 liveuser 13311
				#一次取得資料庫、表的資料
43 liveuser 13312
				#回傳結果:
1 liveuser 13313
				#$result["status"],執行結果"true"為成功;"false"為執行失敗。
13314
				#$result["error"],錯誤訊息陣列。
13315
				#$result["function"],當前執行的漢書名稱.
13316
				#$result["dataColumnName"],抓取的資料欄位名稱陣列.
13317
					#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
13318
				#$result["dataContent"],爲資料的內容。
13319
				#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
13320
					#$dataSetNum 爲第$dataSetNum+1筆資料
13321
					#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
13322
				#$result["dataCount"],爲取得的資料筆數。
13323
				#$result["sql"],執行的sql字串.
43 liveuser 13324
				#必填參數:
1 liveuser 13325
				$conf["db::fastGetDbData"]["dbAddress"]=$conf["dbInfo"][$linkDb]["dbAddr"];#爲dbServer的位置。
13326
				$conf["db::fastGetDbData"]["dbAccount"]=$conf["dbInfo"][$linkDb]["dbAcct"];#爲登入dbServer的帳號。
13327
				$conf["db::fastGetDbData"]["dbName"]=$linkDb;#爲要存取的資料庫名稱
13328
				$conf["db::fastGetDbData"]["tableName"]=$linkDt;#爲要存取的資料表名稱
13329
				$conf["db::fastGetDbData"]["columnYouWant"]=array("*");#你想要的欄位!,若設為「array("*")」則代表全部欄位.
43 liveuser 13330
				#可省略參數:
1 liveuser 13331
 
13332
				#如果有設置次表的密碼
13333
				if(isset($conf["dbInfo"][$linkDb]["dbPass"])){
13334
 
13335
					$conf["db::fastGetDbData"]["dbPassword"]=$conf["dbInfo"][$linkDb]["dbPass"];#爲要存取dbServer的密碼
13336
 
13337
					}#if end			
13338
 
13339
				$conf["db::fastGetDbData"]["WhereColumnName"]=array($linkCol);#用於判斷語句的欄位項目陣列。
13340
				$conf["db::fastGetDbData"]["WhereColumnValue"]=array($mainColVal);#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
13341
				#$conf["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
13342
				#$conf["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、"!="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
13343
				#$conf["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
13344
				#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
13345
				#$conf["whereIn"]=array(array("colName",array("a","b","c")));
13346
				#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
13347
				#$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
13348
				#$conf["orderItem"]="";#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
13349
				#$conf["ascORdesc"]="";#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
13350
				#$conf["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
13351
				#$conf["db::fastGetDbData"]["numLimit"]="1";#為要取幾筆資料,可以省略,省略則表示不限制數目。
13352
				#$conf["groupBy"]=array("");#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
13353
				$fastGetDbData=db::fastGetDbData($conf["db::fastGetDbData"]);
13354
				unset($conf["db::fastGetDbData"]);
13355
 
13356
				#如果query失敗
13357
				if($fastGetDbData["status"]==="false"){
13358
 
13359
					#設置執行失敗
13360
					$result["status"]="false";
13361
 
13362
					#設置錯誤訊息
13363
					$result["error"]=$fastGetDbData;
13364
 
13365
					#回傳結果;
13366
					return $result;
13367
 
13368
					}#if end
13369
 
13370
				#如果如果沒有符合的資料
13371
				if($fastGetDbData["dataCount"]===0){
13372
 
13373
					#如果有欄位名稱存在
13374
					if(isset($fastGetDbData["dataColumnName"])){
13375
 
13376
						#次表有幾個欄位就執行幾次
13377
						foreach($fastGetDbData["dataColumnName"] as $linkedColName){
13378
 
13379
							#給予NULL
13380
							$newMerged[$linkDb.".".$linkDt.".".$linkedColName][$index]=NULL;
13381
 
13382
							}#foreach end					
13383
 
13384
						}#if end
13385
 
13386
					}#if end
13387
 
13388
				#反之有資料
13389
				else{
13390
 
13391
					#次表有幾個欄位就執行幾次
13392
					foreach($fastGetDbData["dataColumnName"] as $linkedColName){
13393
 
13394
						#設置新的欄位資料
13395
						$newMerged[$linkDb.".".$linkDt.".".$linkedColName][$index]=$fastGetDbData["dataContent"][$linkedColName][0];
13396
 
13397
						}#foreach end
13398
 
13399
					#有幾筆資料就執行幾次
13400
					for($i=1;$i<$fastGetDbData["dataCount"];$i++){
13401
 
13402
						#取得資新料的索引
13403
						$newMergedDataIndex=count($newMerged[$mergedColName[0]]);
13404
 
13405
						#有幾個欄位就執行幾次
13406
						for($j=0;$j<$mergedColCount;$j++){
13407
 
13408
							#複製既有的欄位資料
13409
							$newMerged[$mergedColName[$j]][$newMergedDataIndex]=$newMerged[$mergedColName[$j]][$index];
13410
 
13411
							}#for end							
13412
 
13413
						#次表有幾個欄位就執行幾次
13414
						foreach($fastGetDbData["dataColumnName"] as $linkedColName){	
13415
 
13416
							#加上新的欄位資料
13417
							$newMerged[$linkDb.".".$linkDt.".".$linkedColName][$newMergedDataIndex]=$fastGetDbData["dataContent"][$linkedColName][$i];
13418
 
13419
							}#foreach end
13420
 
13421
						}#for end					
13422
 
13423
					}#else end
13424
 
13425
				}#foreach end
13426
 
13427
			}#foreach end
13428
 
13429
		#如果有設置要的欄位
13430
		if(isset($conf["columnYouWant"])){
13431
 
13432
			#初始化儲存僅需要的欄位
13433
			$filteredCol=array();
13434
 
13435
			#依照每個需要的欄位
13436
			foreach($conf["columnYouWant"] as $colYouWant){
13437
 
13438
				#如果要的欄位不存在
13439
				if(!isset($newMerged[$colYouWant])){
13440
 
13441
					#設置執行不正常;  
13442
					$result["status"]="false";
13443
 
13444
					#設置錯誤訊息
13445
					$result["error"][]="欄位 ".$colYouWant." 不存在於查詢後的結果!";
13446
 
13447
					#回傳結果
13448
					return $result;
13449
 
13450
					}#if end
13451
 
13452
				#取得欄位內容
13453
				$filteredCol[$colYouWant]=&$newMerged[$colYouWant];
13454
 
13455
				}#foreach end
13456
 
13457
			#置換成篩選過後的欄位資訊
13458
			$newMerged=$filteredCol;
13459
 
13460
			}#if end
13461
 
13462
		#設置執行正常
13463
		$result["status"]="true";
13464
 
13465
		#設置join完的資料;
13466
		$result["content"]=$merged;
13467
 
13468
		#回傳結果
13469
		return $result;
13470
 
13471
		}#function joinByPHP end
13472
 
13473
	/*
43 liveuser 13474
	#函式說明:
1 liveuser 13475
	#取得該資料表總共有幾筆資料
43 liveuser 13476
	#回傳變數:
1 liveuser 13477
	#$result["status"],爲執行是否正常,若爲"true"則成功,若爲"false"則表示失敗了
13478
	#$result["function"],當前執行的函數名稱
13479
	#$result["error"],錯誤訊息
13480
	#$result["dataCount"],資料表裏面的資料筆數。
43 liveuser 13481
	#必填參數:
1 liveuser 13482
	#$conf["dbAddress"],字串,爲mysql-Server的位置.
13483
	$conf["dbAddress"]=$dbAddress;
13484
	#$conf["dbAccount"]字串,爲用於連入mysql-Server時要使用的帳號.
13485
	$conf["dbAccount"]=$dbAccount;
13486
	#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱	
13487
	$conf["selectedDataBaseName"]=$dbName;
13488
	#$conf["selectedDataTableName"],字串,為要計算的對象資料表
13489
	$conf["selectedDataTableName"]="";#為要計算的對象資料表
43 liveuser 13490
	#可省略參數:
1 liveuser 13491
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
13492
	#$conf["dbPassword"]=$dbPassword;
13493
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表用預設的 port 3306.
13494
	#$conf["dbPort"]=$dbPort;
185 liveuser 13495
	#參考資料:
13496
	#無.
43 liveuser 13497
	#備註:
13498
	#無.
1 liveuser 13499
	*/	
13500
	public static function getDataCountsInTable($conf){
13501
 
13502
		#初始化要回傳的內容
13503
		$result=array();
13504
 
13505
		#取得當前執行的函數名稱
13506
		$result["function"]=__FUNCTION__;
13507
 
13508
		#如果 $conf 不為陣列
13509
		if(gettype($conf)!="array"){
13510
 
13511
			#設置執行失敗
13512
			$result["status"]="false";
13513
 
13514
			#設置執行錯誤訊息
13515
			$result["error"][]="\$conf變數須為陣列形態";
13516
 
13517
			#如果傳入的參數為 null
13518
			if($conf==null){
13519
 
13520
				#設置執行錯誤訊息
13521
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
13522
 
13523
				}#if end
13524
 
13525
			#回傳結果
13526
			return $result;
13527
 
13528
			}#if end
13529
 
13530
		#檢查參數
43 liveuser 13531
		#函式說明:
1 liveuser 13532
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 13533
		#回傳結果:
1 liveuser 13534
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
13535
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13536
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13537
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 13538
		#必填參數:
1 liveuser 13539
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
13540
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbPassword","selectedDataBaseName","selectedDataTableName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 13541
		#可省略參數:
1 liveuser 13542
		#$conf["variableCheck"]["isexistMuti"]["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
13543
		#$conf["variableCheck"]["isexistMuti"]"canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
13544
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
13545
		unset($conf["variableCheck"]["isexistMuti"]);
13546
 
13547
		#如果 $checkResult["status"] 等於 "false"
13548
		if($checkResult["status"]=="false"){
13549
 
13550
			#設置錯識別
13551
			$result["status"]="false";
13552
 
13553
			#設置錯誤訊息
13554
			$result["error"]=$checkResult;
13555
 
13556
			#回傳結果
13557
			return $result;
13558
 
13559
			}#if end
13560
 
13561
		#如果 $checkResult["passed"] 等於 "false"
13562
		if($checkResult["passed"]=="false"){
13563
 
13564
			#設置錯識別
13565
			$result["passed"]="false";
13566
 
13567
			#設置錯誤訊息
13568
			$result["error"]=$checkResult;
13569
 
13570
			#回傳結果
13571
			return $result;
13572
 
13573
			}#if end
13574
 
43 liveuser 13575
		#函式說明:
1 liveuser 13576
		#執行mysql指令
43 liveuser 13577
		#回傳結果::
1 liveuser 13578
		#$result["status"],"true"為執行成功;"false"為執行失敗。
13579
		#$result["error"],錯誤訊息的陣列
13580
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
13581
		#$result["queryString"],mysql查詢的語言
13582
		#查詢號的解果,需要解析。
43 liveuser 13583
		#必填參數:
1 liveuser 13584
		$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
13585
		$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
13586
		$conf["db"]["execMysqlQuery"]["dbSql"]="select count(*) from ".$conf["selectedDataBaseName"].".".$conf["selectedDataTableName"]." ;";#要執行sql語法
43 liveuser 13587
		#可省略參數:
1 liveuser 13588
 
13589
		#如果 $conf["dbPassword"] 有設定
13590
		if(isset($conf["dbPassword"])){
13591
 
13592
			$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
13593
 
13594
			}#if end
13595
 
13596
		#如果 $conf["dbPort"] 有設定
13597
		if(isset($conf["dbPort"])){
13598
 
13599
			$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的 port.
13600
 
13601
			}#if end
13602
 
13603
		#執行查尋	
13604
		$countResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
13605
		unset($conf["db"]["execMysqlQuery"]);
13606
 
13607
		#如果執行失敗
13608
		if($countResult["status"]=="false"){
13609
 
13610
			#設置錯誤識別
13611
			$result["status"]="false";
13612
 
13613
			#設置錯誤訊息
13614
			$result["error"]=$countResult;
13615
 
13616
			#回傳結果
13617
			return $result;
13618
 
13619
			}#if end
13620
 
13621
		#解析 dataTableSelect($conf) 後的結果,亦即將執行sql語法後所得到的結果解析放進變數裏面
43 liveuser 13622
		#回傳結果:
1 liveuser 13623
		#$result["status"],執行結果"true"為成功;"false"為失敗
13624
		#$result["error"],錯誤訊息
13625
		#$result["dataColumnName"],為資料欄位的名稱陣列.
13626
			#$result["dataColumnName"][$i]代表第一個欄位名稱.
13627
		#$result["dataContent"],爲資料的內容。
13628
		#$result["dataContent"][$conf["tableValueName"][$i]][$dataSetNum],
13629
			#$dataSetNum 爲第$dataSetNum+1筆資料
13630
			#$conf["tableValueName"][$i] 爲第 $i+1 個欄位的名稱
13631
		#$result["dataCount"],爲取得的資料筆數。
43 liveuser 13632
		#必填參數:
1 liveuser 13633
		$conf["db"]["sendQueryDataToVariabele"]["sqlQueryResult"]=$countResult["queryResource"];#爲執行sql語法所獲得的查詢結果。
13634
		$conf["db"]["sendQueryDataToVariabele"]["tableValueName"]=array("count(*)");#爲該資料表列項目的每一項名稱,須爲陣列值,若為「array("*")」則代表所有欄位.
13635
		$conf["db"]["sendQueryDataToVariabele"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
13636
		$conf["db"]["sendQueryDataToVariabele"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
43 liveuser 13637
		#可省略參數:
1 liveuser 13638
 
13639
		#如果 $conf["dbPassword"] 有設置
13640
		if(isset($conf["dbPassword"])){
13641
 
13642
			$conf["db"]["sendQueryDataToVariabele"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
13643
 
13644
			}#if end
13645
 
13646
		#如果 $conf["dbPort"] 有設置
13647
		if(isset($conf["dbPort"])){
13648
 
13649
			$conf["db"]["sendQueryDataToVariabele"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的port 3306
13650
 
13651
			}#if end
13652
 
13653
		$conf["db"]["sendQueryDataToVariabele"]["valueName"]=array("count");#陣列,爲該資料表列項目的每一項所要對應的變數名稱,預設為欄位的名稱($conf["tableValueName"]).
13654
		#參考資料:
13655
		#http://www.w3school.com.cn/php/func_mysql_fetch_array.asp => 解析取得的資料表欄位時,能夠選擇回傳含有欄位名稱與數字代表的key.
13656
		$getCountResult=db::sendQueryDataToVariabele($conf["db"]["sendQueryDataToVariabele"]);
13657
		unset($conf["db"]["sendQueryDataToVariabele"]);
13658
 
13659
		#如果 $getCountResult["status"] 等於 "false"
13660
		if($getCountResult["status"]=="false"){
13661
 
13662
			#設置錯誤識別
13663
			$result["status"]="false";
13664
 
13665
			#設置錯誤訊息
13666
			$result["error"]=$getCountResult;
13667
 
13668
			#回傳結果
13669
			return $result;
13670
 
13671
			}#if end
13672
 
13673
		#取得資料筆數
13674
		$result["dataCount"]=$getCountResult["dataContent"]["count"][0];
13675
 
13676
		#執行到這邊代表執行正常
13677
		$result["status"]="true";
13678
 
13679
		#回傳查詢的結果;	
13680
		return $result;	
13681
 
13682
		}#function getDataCountsInTable end
13683
 
13684
	/*
43 liveuser 13685
	#函式說明:
1 liveuser 13686
	#插入資料到指定的資料表裡面,插入資料完畢可以選擇是否要進行轉址。
43 liveuser 13687
	#回傳結果:	
1 liveuser 13688
	#$result["status"],爲查詢是否成功,若爲"true"則成功,若爲"false"則表示失敗了.
13689
	#$result["error"],錯誤訊息.
13690
	#$result["sql"],執行的sql語法.
13691
	#$result["lastInsertId"],新增的資料id.
13692
	#$result["function"],當前執行的涵式
43 liveuser 13693
	#必填參數:
1 liveuser 13694
	#$conf["dbAddress"],字串,爲mysql-Server的位置
13695
	$conf["dbAddress"]=$dbAddress;
13696
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
13697
	$conf["dbAccount"]=$dbAccount;
13698
	#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱
13699
	$conf["selectedDataBaseName"]=$dbName;
13700
	#$conf["tableName"],字串,爲要插入資料的資料表名稱
13701
	$conf["tableName"]="";
43 liveuser 13702
	#$conf["columnName"],字串陣列,爲資料表的項目名稱.例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
1 liveuser 13703
	$conf["columnName"]=array();
43 liveuser 13704
	#$conf["insertValue"],字串陣列,爲要插入度數值.#例如:$conf["insertValue"]=array("insertValue1","insertValue2","insertValue3",...);
1 liveuser 13705
	$conf["insertValue"]=array();
43 liveuser 13706
	#可省略參數:
1 liveuser 13707
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
13708
	#$conf["dbPassword"]=$dbPassword;
13709
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表用預設的 3306 port.
13710
	#$conf["dbPort"]=$dbPort;
185 liveuser 13711
	#參考資料:
1 liveuser 13712
	#http://www.javaworld.com.tw/jute/post/view?bid=21&id=173738&sty=1
43 liveuser 13713
	#備註:
13714
	#無.
1 liveuser 13715
	*/	
13716
	public static function insertData($conf){
13717
 
13718
		#初始化要回傳的內容
13719
		$result=array();
13720
 
13721
		#取得當前執行的函數名稱
13722
		$result["function"]=__FUNCTION__;
13723
 
13724
		#如果 $conf 不為陣列
13725
		if(gettype($conf)!="array"){
13726
 
13727
			#設置執行失敗
13728
			$result["status"]="false";
13729
 
13730
			#設置執行錯誤訊息
13731
			$result["error"][]="\$conf變數須為陣列形態";
13732
 
13733
			#如果傳入的參數為 null
13734
			if($conf==null){
13735
 
13736
				#設置執行錯誤訊息
13737
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
13738
 
13739
				}#if end
13740
 
13741
			#回傳結果
13742
			return $result;
13743
 
13744
			}#if end
13745
 
43 liveuser 13746
		#函式說明:
1 liveuser 13747
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 13748
		#回傳結果:
1 liveuser 13749
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
13750
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
13751
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 13752
		#必填參數:
1 liveuser 13753
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
13754
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","tableName","columnName","insertValue");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 13755
		#可省略參數:
1 liveuser 13756
		$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string","string","string","array","array");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
13757
		#$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
13758
		#備註:
13759
		#功能與checkExistAndType函式相同
13760
		$variableCheck=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
13761
		unset($conf["variableCheck"]["isexistMuti"]);
13762
 
13763
		#如果 $variableCheck["status"] 等於 "false"
13764
		if($variableCheck["status"]=="false"){
13765
 
13766
			#設置執行錯誤的識別
13767
			$result["status"]="false";
13768
 
13769
			#設置執行錯誤的訊息
13770
			$result["error"]=$variableCheck;
13771
 
13772
			#回傳結果
13773
			return $result;
13774
 
13775
			}#if end
13776
 
13777
		#如果 $variableCheck["passed"] 等於 "false"
13778
		if($variableCheck["passed"]=="false"){
13779
 
13780
			#設置執行錯誤的識別
13781
			$result["status"]="false";
13782
 
13783
			#設置執行錯誤的訊息
13784
			$result["error"]=$variableCheck;
13785
 
13786
			#回傳結果
13787
			return $result;
13788
 
13789
			}#if end
13790
 
343 liveuser 13791
		#連線到資料庫
13792
		#函式說明:
13793
		#連線到資料庫,結果會回傳一個陣列
13794
		#$result["status"],若連線成功則爲"true",連線失敗則爲"false".
13795
		#$result["connectInformation"],爲回傳的mysql連線資訊.
13796
		#$result["error"],錯誤訊息	.
13797
		#$result["function"],當前執行的函數名稱.	
13798
		#必填參數:
13799
		$conf["db"]["dbConnect"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
13800
		$conf["db"]["dbConnect"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
13801
		#$conf["dbName"],字串,爲要連的資料庫名稱
13802
		$conf["db"]["dbConnect"]["dbName"]=$conf["selectedDataBaseName"];
13803
		#可省略參數:
13804
 
13805
		#如果 $conf["dbPassword"] 有設定
13806
		if(isset($conf["dbPassword"])){
13807
 
13808
			$conf["db"]["dbConnect"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
13809
 
13810
			}#if end
13811
 
13812
		#如果 $conf["dbPort"] 有設定
13813
		if(isset($conf["dbPort"])){
13814
 
13815
			$conf["db"]["dbConnect"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
13816
 
13817
			}#if end
13818
 
13819
		$con=db::dbConnect($conf["db"]["dbConnect"]);
13820
		unset($conf["db"]);
13821
 
13822
		#如果連線到資料庫失敗
13823
		if($con["status"]==="false"){
13824
 
13825
			#設置執行失敗
13826
			$result["status"]="false";
13827
 
13828
			#設置執行錯誤訊息
13829
			$result["error"]=$con;
13830
 
13831
			#回傳結果
13832
			return $result;
13833
 
13834
			}#if end
13835
 
13836
		#var_dump($con);	
13837
 
13838
		#取得mysqli物件
13839
		$mysqli=$con["connectInformation"];
13840
 
1 liveuser 13841
		#輸入資料到 資料表 board 的語法
13842
		$str1="insert into `".$conf["selectedDataBaseName"]."`.`".$conf["tableName"]."`(";
13843
 
13844
		#取得一筆資料有幾個項目
13845
		$count=count($conf["columnName"]);
13846
 
13847
		#跑 $count-1 次,插入第一筆到最倒數第二筆
13848
		for($i=0;$i<=($count-2);$i++){
13849
 
13850
			#放入欲插入的項目名稱			
13851
			$str1=$str1."`".$conf["columnName"][$i]."`".",";
13852
 
13853
			}#for end
13854
 
13855
		#插入最後一筆項目名稱
13856
		$lastItem = ($count-1);
13857
		$str1=$str1."`".$conf["columnName"][$lastItem]."`)";  
13858
 
13859
		#要插入的數值語法開始
13860
		$str2=" values (";
13861
 
13862
		#跑 $count-1 次
13863
		for($i=0;$i<=($count-2);$i++){
13864
 
13865
			#插入第一筆到最倒數第二筆的資料內容	
343 liveuser 13866
			$str2=$str2."'".mysqli_real_escape_string($mysqli,$conf["insertValue"][$i])."',";
1 liveuser 13867
 
13868
			}#for end
13869
 
13870
		#插入最後一筆的資料內容
13871
		$lastItem = ($count-1);
343 liveuser 13872
		$str2=$str2."'".mysqli_real_escape_string($mysqli,$conf["insertValue"][$lastItem])."');";  
1 liveuser 13873
 
13874
		#合併要執行的sql語法
13875
		$sqlString=$str1.$str2;
13876
 
13877
		#執行sql語法
43 liveuser 13878
		#函式說明:
1 liveuser 13879
		#執行mysql指令
43 liveuser 13880
		#回傳結果::
1 liveuser 13881
		#$result["status"],"true"為執行成功;"false"為執行失敗。
13882
		#$result["error"],錯誤訊息的陣列
13883
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
13884
		#$result["queryConn"],用於資料庫操作的變數.
13885
		#$result["queryString"],mysql查詢的語言
13886
		#查詢號的解果,需要解析。
43 liveuser 13887
		#必填參數:
343 liveuser 13888
		$conf["db::execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
13889
		$conf["db::execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
13890
		$conf["db::execMysqlQuery"]["dbSql"]=$sqlString;#要執行sql語法
43 liveuser 13891
		#可省略參數: 
1 liveuser 13892
 
13893
		#如果 $conf["dbPassword"] 有設置
13894
		if(isset($conf["dbPassword"])){
13895
 
343 liveuser 13896
			$conf["db::execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
1 liveuser 13897
 
13898
			}#if end
13899
 
13900
		#如果 $conf["dbPort"] 有設置
13901
		if(isset($conf["dbPort"])){
13902
 
343 liveuser 13903
			$conf["db::execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的3306 port.
1 liveuser 13904
 
13905
			}#if end
13906
 
343 liveuser 13907
		#$conf["dbLink"],物件,mysqli物件,由mysqli_connect()回傳的物件內容,若為數值則改用賬號密碼等資訊進行連線,反之則沿用連線物件.
13908
		$conf["db::execMysqlQuery"]["dbLink"]=$mysqli;
345 liveuser 13909
		#$conf["autoClose],字串,"true"代表要自動斷線,預設為"true"會自動斷線
13910
		$conf["db::execMysqlQuery"]["autoClose"]="false";
343 liveuser 13911
		$mysqlQueryResult=db::execMysqlQuery($conf["db::execMysqlQuery"]);
13912
		unset($conf["db::execMysqlQuery"]);
1 liveuser 13913
 
13914
		#若執行 query 語法失敗
13915
		if($mysqlQueryResult["status"]=="false"){
13916
 
13917
			#設置執行錯誤識別
13918
			$result["status"]="false";
13919
 
13920
			#設置錯誤訊息
13921
			$result["error"]=$mysqlQueryResult;				
13922
 
13923
			#回傳結果
13924
			return $result;
13925
 
13926
			}#else end
13927
 
13928
		#取得新增的該筆記錄id
13929
		$result["lastInsertId"]=mysqli_insert_id($mysqlQueryResult["queryConn"]);
13930
 
13931
		#取得執行的sql字串
13932
		$result["sql"]=$mysqlQueryResult["queryString"];
13933
 
13934
		#執行到這邊代表執行成功
13935
		$result["status"]="true";
13936
 
13937
		#回傳結果
13938
		return $result;
13939
 
13940
		}#function insertData end
13941
 
13942
	/*
13943
	#函式說明:	
13944
	#更新資料表裏面的資料
43 liveuser 13945
	#回傳結果:	
1 liveuser 13946
	#$result["status"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了
13947
	#$result["error"],錯誤訊息
13948
	#$result["function"],當前執行的函數名稱
13949
	#$result["sql"],執行的sql語法.
443 liveuser 13950
	#$result["argu"],使用的參數.
1 liveuser 13951
	#必填參數:
13952
	#$conf["fileArgu"],字串,變數__FILE__的內容.
13953
	$conf["fileArgu"]=__FILE__;
13954
	#$conf["dbAddress"],字串,爲mysql-Server的位置
13955
	$conf["dbAddress"]=$dbAddress;
13956
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
13957
	$conf["dbAccount"]=$dbAccount;
13958
	#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱
13959
	$conf["selectedDataBaseName"]=$dbName;
13960
	#$conf["tableName"],字串,要修改的資料表名稱
13961
	$conf["tableName"]="";
13962
	#$conf["whereColumn"],字串陣列,爲用來判斷要更新的哪筆資料的欄位名稱,須爲陣列值
13963
	$conf["whereColumn"]=array("");
13964
	#$conf["whereValue"],字串陣列,為用來判斷是要更新哪筆資料的欄位對應數值,須爲陣列值
13965
	$conf["whereValue"]=array("");
13966
	#$conf["tableColumnName"],字串陣列,資料表項目的名稱陣列
13967
	$conf["tableColumnName"]=array("");
13968
	#$conf["updateDataValue"],字串陣列,要更改成對應資料表項目的內容,須為陣列值
13969
	$conf["updateDataValue"]=array("");
13970
	#可省略參數:
13971
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
13972
	#$conf["dbPassword"]=$dbPassword;
13973
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
13974
	#$conf["dbPort"]=$dbPort;
185 liveuser 13975
	#參考資料:
13976
	#無.
43 liveuser 13977
	#備註:
13978
	#無.
1 liveuser 13979
	*/
13980
	public static function updateDataTableContent($conf){
13981
 
13982
		#初始化要回傳的內容
13983
		$result=array();
13984
 
13985
		#取得當前執行的函數名稱
13986
		$result["function"]=__FUNCTION__;
13987
 
13988
		#如果 $conf 不為陣列
317 liveuser 13989
		if(gettype($conf)!=="array"){
1 liveuser 13990
 
13991
			#設置執行失敗
13992
			$result["status"]="false";
13993
 
13994
			#設置執行錯誤訊息
13995
			$result["error"][]="\$conf變數須為陣列形態";
13996
 
13997
			#如果傳入的參數為 null
13998
			if($conf==null){
13999
 
14000
				#設置執行錯誤訊息
14001
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
14002
 
14003
				}#if end
14004
 
14005
			#回傳結果
14006
			return $result;
14007
 
14008
			}#if end
14009
 
443 liveuser 14010
		#儲存使用的參數
14011
		$result["argu"]=$conf;
14012
 
43 liveuser 14013
		#函式說明:
1 liveuser 14014
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 14015
		#回傳結果:
1 liveuser 14016
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14017
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14018
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14019
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 14020
		#必填參數:
1 liveuser 14021
		$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
14022
		$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("fileArgu","dbAddress","dbAccount","selectedDataBaseName","tableName","whereColumn","whereValue","tableColumnName","updateDataValue");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 14023
		#可省略參數:
1 liveuser 14024
		$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string","string","string","string","array","array","array","array");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
14025
		#$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
14026
		$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
14027
		unset($conf["variableCheck"]["isexistMuti"]);
14028
 
14029
		#如果檢查參數作業出錯
317 liveuser 14030
		if($checkResult["status"]==="false"){
1 liveuser 14031
 
14032
			#設置執行錯誤識別
14033
			$result["status"]="false";
14034
 
14035
			#設置錯誤訊息
14036
			$result["error"]=$checkResult;
14037
 
14038
			#回傳結果
14039
			return $result;
14040
 
14041
			}#if end
14042
 
14043
		#如果檢查沒通過
317 liveuser 14044
		if($checkResult["passed"]==="false"){
1 liveuser 14045
 
14046
			#設置執行錯誤識別
14047
			$result["status"]="false";
14048
 
14049
			#設置錯誤訊息
14050
			$result["error"]=$checkResult;
14051
 
14052
			#回傳結果
14053
			return $result;
14054
 
14055
			}#if end
14056
 
14057
		#將陣列變數 $conf["whereColumn"] 與 $conf["whereValue"] 對應的變數中不存在的 $conf["whereValue"][$i] 元素去掉,並同時調整 $conf["whereColumn"] 使兩者變數的元素數量均相同。
43 liveuser 14058
		#函式說明:
1 liveuser 14059
		#比對兩個陣列變數,如果其中一個陣列變數的元素不存在,則將之消去,然後進行替補。另一個陣列變數則也要做同步的動作。
43 liveuser 14060
		#回傳結果::
1 liveuser 14061
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常。
14062
		#$result["error"],錯誤訊息。
14063
		#$result["content"],組合成新值的一維陣列。
14064
		#$result["function"],當前執行的函數名稱。
43 liveuser 14065
		#必填參數:
1 liveuser 14066
		$conf_compareAndModify2Arrays["arraysA"]=$conf["tableColumnName"];#用來跟陣列變數B比較的陣列變數A
14067
		$conf_compareAndModify2Arrays["arraysB"]=$conf["updateDataValue"];#用來跟陣列變數A比較的陣列變數B
315 liveuser 14068
		$compareAndModifyTwoArrays=arrays::compareAndModifyTwoArrays($conf_compareAndModify2Arrays);
1 liveuser 14069
		unset($conf_compareAndModify2Arrays);
14070
 
14071
		#如果 arrays::compareAndModifyTwoArrays 執行失敗
317 liveuser 14072
		if($compareAndModifyTwoArrays["status"]==="false"){
1 liveuser 14073
 
14074
			#設置執行錯誤識別
14075
			$result["status"]="false";
14076
 
14077
			#設置錯誤訊息
315 liveuser 14078
			$result["error"]=$compareAndModifyTwoArrays;
1 liveuser 14079
 
14080
			#回傳結果
14081
			return $result;
14082
 
14083
			}#if end
14084
 
14085
		#將整理好的 $result["compareAndModify2Arrays"]["A"] 放到 $conf["whereColumn"] ; $result["compareAndModify2Arrays"]["B"] 放到 $conf["whereValue"]
315 liveuser 14086
		$conf["tableColumnName"]=$compareAndModifyTwoArrays["newArraysA"];
14087
		$conf["updateDataValue"]=$compareAndModifyTwoArrays["newArraysB"];
1 liveuser 14088
 
14089
		#更新 $conf["selectedDatabaseName"].$tableName 資料表
14090
		$selectUpdateTableSql="UPDATE `".$conf["selectedDataBaseName"]."`.`".$conf["tableName"]."` "; 
14091
 
14092
		#更新資料表資料語法的一部分
14093
		$chooseColumnSql="SET ";
14094
 
14095
		#取得一筆資料有幾個項目
14096
		$counts=count($conf["tableColumnName"]);
14097
 
293 liveuser 14098
		#儲存宣告shell變數的指令陣列
1 liveuser 14099
		$shellVarDefined=array();
14100
 
14101
		#儲存要宣告的變數
14102
		$varDefined=array();
14103
 
14104
		#有$count欄項目,
14105
		for($i=0;$i<$counts;$i++){
14106
 
14107
			#如果是最後一項要更新的資料
14108
			if($i==($counts-1)){
14109
 
272 liveuser 14110
				#如果內容不為字串
279 liveuser 14111
				if(gettype($conf["updateDataValue"][$i])!=="string"){
272 liveuser 14112
 
273 liveuser 14113
					#設置執行錯誤識別
14114
					$result["status"]="false";
14115
 
14116
					#設置錯誤訊息
14117
					$result["error"][]="欲使用的變數不為字串";
14118
 
14119
					#設置錯誤訊息
14120
					$result["error"][]=$conf["updateDataValue"][$i];
14121
 
14122
					#回傳結果
14123
					return $result;
272 liveuser 14124
 
14125
					}#if end
14126
 
1 liveuser 14127
				#定義 shell script 變數
308 liveuser 14128
				$shellVarDefined[]=array("cmd"=>"x".$i."=","param"=>array($conf["updateDataValue"][$i]));
293 liveuser 14129
 
1 liveuser 14130
				#定義變數
443 liveuser 14131
				#$varDefined[]="select @x".$i." := '\${x".$i."}';";
14132
				$varDefined[]="select @x".$i." := \${x".$i."};";
1 liveuser 14133
 
5 liveuser 14134
				#將要更新的內容字串串接,結尾無逗號                             
14135
				$chooseColumnSql = $chooseColumnSql."`".$conf["tableColumnName"][$i]."`= @x".$i." ";
1 liveuser 14136
 
14137
				}#判斷式結束
14138
 
14139
			#如果不是最後一項要更新的資料
14140
			if($i!=($counts-1)){
14141
 
14142
				#定義 shell script 變數
308 liveuser 14143
				$shellVarDefined[]=array("cmd"=>"x".$i."=","param"=>array($conf["updateDataValue"][$i]));
293 liveuser 14144
 
14145
				#sql定義變數
443 liveuser 14146
				#$varDefined[]="select @x".$i." := '\${x".$i."}';";
14147
				$varDefined[]="select @x".$i." := \${x".$i."};";
1 liveuser 14148
 
14149
				#將要更新的內容字串串接,結尾有逗號
14150
				$chooseColumnSql = $chooseColumnSql."`".$conf["tableColumnName"][$i]."`= @x".$i." ,";
14151
 
14152
				}#判斷式結束
14153
 
14154
			}#回圈結束
14155
 
14156
		#取得條件有幾項
14157
		$conditionArrayCounts=count($conf["whereColumn"]);				
14158
 
14159
		#構成條件式
14160
		for($i=0;$i<$conditionArrayCounts;$i++){
14161
 
14162
			#如果是第一筆
14163
			if($i==0){
14164
 
14165
				#尋找的條件式
14166
				$condition="WHERE `".$conf["whereColumn"][$i]."` = '".$conf["whereValue"][$i]."'";
14167
 
14168
				#測試有無抓到第一個條件
14169
				#var_dump($condition);
14170
 
14171
				}#判斷式結束
14172
 
14173
			#如果不是第一筆
14174
			if($i!=0){
14175
 
14176
				#其它條件
14177
				$condition=$condition." AND `".$conf["whereColumn"][$i]."` = '".$conf["whereValue"][$i]."'";
14178
 
14179
				#測試有無抓到其它條件
14180
				#var_dump($condition);
14181
 
14182
				}#判斷式結束
14183
 
14184
			}#迴圈結束
14185
 
14186
		#初始化定義變數的sql
14187
		$varDefineStr="";
14188
 
14189
		#針對每個要使用的數值
14190
		foreach($varDefined as $index=>$var){
14191
 
14192
			#累加定義變數的sql
14193
			$varDefineStr=$varDefineStr.$var;
14194
 
14195
			}#foreach end
14196
 
14197
		#合併所有的語法成一句完整的語法 
14198
		$sqlString = $varDefineStr.$selectUpdateTableSql.$chooseColumnSql.$condition;
14199
 
5 liveuser 14200
		#設置取得執行的sql語法
14201
		$result["sql"]=$sqlString;
14202
 
43 liveuser 14203
		#函式說明:
1 liveuser 14204
		#用shell執行mysql指令.
43 liveuser 14205
		#回傳結果::
1 liveuser 14206
		#$result["status"],"true"為執行成功;"false"為執行失敗。
14207
		#$result["error"],錯誤訊息的陣列
14208
		#$result["function"],當前執行的涵式
14209
		#$result["queryString"],mysql查詢的語言.
14210
		#必填參數:
14211
		#$conf["fileArgu"],字串,變數__FILE__的內容.
14212
		$conf["db::shell"]["fileArgu"]=$conf["fileArgu"];
14213
		#$conf["dbSql"],字串,要執行sql語法
14214
		$conf["db::shell"]["dbSql"]=$sqlString;
14215
		#$conf["dbAddress"],字串,爲mysql-Server的位置。
14216
		$conf["db::shell"]["dbAddress"]=$conf["dbAddress"];
14217
		#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號。
14218
		$conf["db::shell"]["dbAccount"]=$conf["dbAccount"]; 
43 liveuser 14219
		#可省略參數:
299 liveuser 14220
		$conf["db::shell"]["pre"]=$shellVarDefined;
1 liveuser 14221
 
14222
		#如果有設定密碼
14223
		if(isset($conf["dbPassword"])){
14224
 
14225
			#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
14226
			$conf["db::shell"]["dbPassword"]=$conf["dbPassword"];
14227
 
14228
			}#if end
14229
 
14230
		#$conf["dbName"],字串,爲要連的資料庫名稱
14231
		$conf["db::shell"]["dbName"]=$conf["selectedDataBaseName"];
14232
 
14233
		#如果有設定port
14234
		if(isset($conf["dbPort"])){
14235
 
14236
			#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
14237
			$conf["db::shell"]["dbPort"]=$conf["dbPort"];
14238
 
14239
			}#if end
14240
 
14241
		$shell=db::shell($conf["db::shell"]);
14242
		unset($conf["db::shell"]);
14243
 
327 liveuser 14244
		/* debug
297 liveuser 14245
		$fsock=fopen("/var/www/html/log/log.txt","a");
309 liveuser 14246
		fwrite($fsock,"func:".__CLASS__." line:".__LINE__.":".print_r($shell,true).PHP_EOL.PHP_EOL);
297 liveuser 14247
		fclose($fsock);
327 liveuser 14248
		*/
297 liveuser 14249
 
1 liveuser 14250
		#如果執行sql失敗
317 liveuser 14251
		if($shell["status"]==="false"){
1 liveuser 14252
 
293 liveuser 14253
			#設置執行不正常
14254
			$result["status"]="false";	
317 liveuser 14255
 
14256
			#設置錯誤訊息
14257
			$result["error"]=$shell;
293 liveuser 14258
 
14259
			#回傳結果
14260
			return $result;
14261
 
1 liveuser 14262
			}#if end
14263
 
14264
		#設置執行正常
14265
		$result["status"]="true";
14266
 
14267
		#回傳結果
14268
		return $result;
14269
 
293 liveuser 14270
		}#function updateDataTableContent end
1 liveuser 14271
 
14272
	/*
43 liveuser 14273
	#函式說明:
1 liveuser 14274
	#將滿足條件的資料從資料表中刪除
43 liveuser 14275
	#回傳結果:	
1 liveuser 14276
	#$result["status"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了
14277
	#$result["function"],當前執行的函數名稱.
14278
	#$result["error"],錯誤訊息
14279
	#$result["sql"],執行的語法
43 liveuser 14280
	#必填參數:
1 liveuser 14281
	#$conf["dbAddress"],字串,爲mysql-Server的位置
14282
	$conf["dbAddress"]=$dbAddress;
14283
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
14284
	$conf["dbAccount"]=$dbAccount;
14285
	#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱
14286
	$conf["selectedDataBaseName"]=$dbName;
14287
	#$conf["selectedDataTableName"],字串,要選取的資料表的名稱
14288
	$conf["selectedDataTableName"]="";
14289
	#$conf["whereColumn"],字串陣列,爲用來判斷要刪除的哪筆資料的欄位名稱,須爲陣列值
14290
	$conf["whereColumn"]=array("");
14291
	#$conf["whereValue"]=,字串陣列,為用來判斷是要刪除哪筆資料的欄位對應數值,須爲陣列值
14292
	$conf["whereValue"]=array("");	
43 liveuser 14293
	#可省略參數:
1 liveuser 14294
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
14295
	#$conf["dbPassword"]=$dbPassword;
14296
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
14297
	#$conf["dbPort"]=$dbPort;
14298
	#$conf["WhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
14299
	#$conf["WhereColumnOperator"]=array("");
14300
	#$conf["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值,預設皆爲AND。其數量應爲要判斷的欄位數量減一。
14301
	#$conf["WhereColumnAndOr"]=array("");
185 liveuser 14302
	#參考資料:
14303
	#無.
43 liveuser 14304
	#備註:
14305
	#無.
1 liveuser 14306
	*/	
14307
	public static function deleteDataFromTable(&$conf){
14308
 
14309
		#初始化要回傳的內容
14310
		$result=array();
14311
 
14312
		#取得當前執行的函數名稱
14313
		$result["function"]=__FUNCTION__;
14314
 
14315
		#如果 $conf 不為陣列
14316
		if(gettype($conf)!="array"){
14317
 
14318
			#設置執行失敗
14319
			$result["status"]="false";
14320
 
14321
			#設置執行錯誤訊息
14322
			$result["error"][]="\$conf變數須為陣列形態";
14323
 
14324
			#如果傳入的參數為 null
14325
			if($conf==null){
14326
 
14327
				#設置執行錯誤訊息
14328
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
14329
 
14330
				}#if end
14331
 
14332
			#回傳結果
14333
			return $result;
14334
 
14335
			}#if end
14336
 
14337
		#檢查參數
43 liveuser 14338
		#函式說明:
1 liveuser 14339
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14340
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14341
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14342
		#$result["function"],當前執行的函式名稱.
14343
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14344
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14345
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14346
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
43 liveuser 14347
		#必填參數:
1 liveuser 14348
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
14349
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
14350
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14351
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName","whereColumn","whereValue");
14352
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
14353
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","array","array");
14354
		#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14355
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
43 liveuser 14356
		#可省略參數:
1 liveuser 14357
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
14358
		#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
14359
		#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14360
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort","WhereColumnOperator","WhereColumnAndOr");
14361
		#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
14362
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","array");
14363
		#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14364
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null);
14365
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14366
		#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("WhereColumnOperator","WhereColumnAndOr");
14367
		#var_dump($conf["variableCheck::checkArguments"]);
14368
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14369
		unset($conf["variableCheck::checkArguments"]);
14370
 
14371
		#如果檢查作業出出錯
14372
		if($checkResult["status"]=="false"){
14373
 
14374
			#設置錯誤識別
14375
			$result["status"]="false";
14376
 
14377
			#設置錯誤訊息
14378
			$result["error"]=$checkResult;
14379
 
14380
			#回傳結果
14381
			return $result;
14382
 
14383
			}#if end
14384
 
14385
		#如果檢查作業出出錯
14386
		if($checkResult["passed"]=="false"){
14387
 
14388
			#設置錯誤識別
14389
			$result["status"]="false";
14390
 
14391
			#設置錯誤訊息
14392
			$result["error"]=$checkResult;
14393
 
14394
			#回傳結果
14395
			return $result;
14396
 
14397
			}#if end
14398
 
14399
		#刪除資料的語法開始,指定了表格的名稱
14400
		$sql="DELETE FROM `".$conf["selectedDataBaseName"]."`.`".$conf["selectedDataTableName"]."` ";
14401
 
14402
		#取得有幾個條件
14403
		$counts=count($conf["whereColumn"]);
14404
 
343 liveuser 14405
		#連線到資料庫
14406
		#函式說明:
14407
		#連線到資料庫,結果會回傳一個陣列
14408
		#$result["status"],若連線成功則爲"true",連線失敗則爲"false".
14409
		#$result["connectInformation"],爲回傳的mysql連線資訊.
14410
		#$result["error"],錯誤訊息	.
14411
		#$result["function"],當前執行的函數名稱.	
14412
		#必填參數:
14413
		$conf["db"]["dbConnect"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
14414
		$conf["db"]["dbConnect"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
14415
		#$conf["dbName"],字串,爲要連的資料庫名稱
14416
		$conf["db"]["dbConnect"]["dbName"]=$conf["selectedDataBaseName"];
14417
		#可省略參數:
14418
 
14419
		#如果 $conf["dbPassword"] 有設定
14420
		if(isset($conf["dbPassword"])){
14421
 
14422
			$conf["db"]["dbConnect"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
14423
 
14424
			}#if end
14425
 
14426
		#如果 $conf["dbPort"] 有設定
14427
		if(isset($conf["dbPort"])){
14428
 
14429
			$conf["db"]["dbConnect"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
14430
 
14431
			}#if end
14432
 
14433
		$con=db::dbConnect($conf["db"]["dbConnect"]);
14434
		unset($conf["db"]);
14435
 
14436
		#如果連線到資料庫失敗
14437
		if($con["status"]==="false"){
14438
 
14439
			#設置執行失敗
14440
			$result["status"]="false";
14441
 
14442
			#設置執行錯誤訊息
14443
			$result["error"]=$con;
14444
 
14445
			#回傳結果
14446
			return $result;
14447
 
14448
			}#if end
14449
 
14450
		#var_dump($con);	
14451
 
14452
		#取得mysqli物件
14453
		$mysqli=$con["connectInformation"];
14454
 
1 liveuser 14455
		#條件語句
14456
		for($i=0;$i<$counts;$i++){
14457
 
14458
			#如果 $conf["WhereColumnOperator"] 不存在
14459
			if(!isset($conf["WhereColumnOperator"])){
14460
 
14461
				#如果 $conf["WhereColumnOperator"][$i] 不存在
14462
				if(!isset($conf["WhereColumnOperator"][$i])){
14463
 
14464
					#設置為 "="
14465
					$conf["WhereColumnOperator"][$i]="=";
14466
 
14467
					}#if end
14468
 
14469
				}#if end
14470
 
14471
			#反之若 $conf["WhereColumnOperator"][$i] 不存在
14472
			else if(!isset($conf["WhereColumnOperator"][$i])){
14473
 
14474
				#設置為 "="
14475
				$conf["WhereColumnOperator"][$i]="=";
14476
 
14477
				}#if end
14478
 
14479
			#以下變數應該要為字串
14480
			$checkedVar["whereColumn"]=$conf["whereColumn"][$i];
14481
			$checkedVar["WhereColumnOperator"]=$conf["WhereColumnOperator"][$i];
14482
			$checkedVar["whereValue"]=$conf["whereValue"][$i];
14483
 
43 liveuser 14484
			#函式說明:
1 liveuser 14485
			#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14486
			#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14487
			#$reuslt["error"],執行不正常結束的錯訊息陣列.
14488
			#$result["function"],當前執行的函式名稱.
14489
			#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14490
			#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14491
			#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14492
			#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
43 liveuser 14493
			#必填參數:
1 liveuser 14494
			#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
14495
			$conf["variableCheck::checkArguments"]["varInput"]=&$checkedVar;
14496
			#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14497
			$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("whereColumn","WhereColumnOperator","whereValue");
14498
			#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
14499
			$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
14500
			#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14501
			$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
43 liveuser 14502
			#可省略參數:
1 liveuser 14503
			#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
14504
			#$conf["canBeEmptyString"]="false";
14505
			#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14506
			#$conf["skipableVariableName"]=array();
14507
			#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
14508
			#$conf["skipableVariableType"]=array();
14509
			#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14510
			#$conf["skipableVarDefaultValue"]=array("");
14511
			#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14512
			#$conf["arrayCountEqualCheck"][]=array();
14513
			$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14514
			unset($conf["variableCheck::checkArguments"]);
14515
 
14516
			#如果檢查失敗
14517
			if($checkResult["status"]=="false"){
14518
 
14519
				#設置執行錯誤
14520
				$result["status"]="false";
14521
 
14522
				#設置執行錯誤訊息
14523
				$result["error"]=$checkResult;
14524
 
14525
				#回傳結果
14526
				return $result;
14527
 
14528
				}#if end
14529
 
14530
			#如果檢查失敗
14531
			if($checkResult["passed"]=="false"){
14532
 
14533
				#設置執行錯誤
14534
				$result["status"]="false";
14535
 
14536
				#設置執行錯誤訊息
14537
				$result["error"]=$checkResult;
14538
 
14539
				#回傳結果
14540
				return $result;
14541
 
14542
				}#if end
14543
 
14544
			#如果是第一筆
14545
			if($i==0){
14546
 
14547
				#如果 $conf["WhereColumnOperator"] 存在
14548
				if(isset($conf["WhereColumnOperator"])){
14549
 
14550
					#設定第一個條件
343 liveuser 14551
					$sql = $sql." WHERE `".$conf["whereColumn"][$i]. "` ".$conf["WhereColumnOperator"][$i]." '". mysqli_real_escape_string($mysqli,$conf["whereValue"][$i])."'";
1 liveuser 14552
 
14553
					}#if end
14554
 
14555
				#反之 $conf["WhereColumnOperator"] 不存在
14556
				else{
14557
 
14558
					#設定第一個條件
343 liveuser 14559
					$sql = $sql." WHERE `".$conf["whereColumn"][$i]. "` = '". mysqli_real_escape_string($mysqli,$conf["whereValue"][$i])."'"; 
1 liveuser 14560
 
14561
					}#else end
14562
 
14563
				}#判斷式
14564
 
14565
			#如果不是第一個條件
14566
			if($i!=0){
14567
 
14568
				#如果 $conf["WhereColumnAndOr"] 不存在 
14569
				if(!isset($conf["WhereColumnAndOr"])){
14570
 
14571
					#將 $conf["WhereColumnAndOr"] 裏面的元素置換爲 AND
14572
					#函式說明:
14573
					#建立一個陣列,可以指派陣列的內容,然後回傳
43 liveuser 14574
					#回傳結果::
1 liveuser 14575
					#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14576
					#$result["function"],當前執行的函數名稱.
14577
					#$result["error"],錯誤訊息陣列.
14578
					#$result["content"],爲陣列變數內容
43 liveuser 14579
					#必填參數:
1 liveuser 14580
					$conf_arrays_create["arrayContent"]=array("AND");#陣列元素的內容,須爲陣列值。
43 liveuser 14581
					#可省略參數:
1 liveuser 14582
					$conf_arrays_create["arrayCounts"]=$counts-1;#爲陣列的元素有幾個,若沒設定,則數量爲$conf["arrayContent"]裏的元素數量
14583
					$conf_arrays_create["theSameAs"]="true";#若設爲"true",則所有元素內容都跟第一個元素內容相同
14584
					$create=arrays::create($conf_arrays_create);
14585
					unset($conf_arrays_create);
14586
 
14587
					#如果建立陣列失敗
14588
					if($create["status"]=="false"){
14589
 
14590
						#設置執行錯誤
14591
						$result["status"]="false";
14592
 
14593
						#設置執行錯誤訊息
14594
						$result["error"]=$create;
14595
 
14596
						#回傳結果
14597
						return $result;
14598
 
14599
						}#if end
14600
 
14601
					#取得 $conf["WhereColumnAndOr"] 參數內容
14602
					$conf["WhereColumnAndOr"]=$create["content"];
14603
 
14604
					}#if end
14605
 
14606
				#如果 $conf["WhereColumnOperator"] 存在
14607
				if(isset($conf["WhereColumnOperator"])){
14608
 
14609
					#設定其它條件
343 liveuser 14610
					$sql=$sql." ".$conf["WhereColumnAndOr"][$i-1]." `".$conf["whereColumn"][$i]. "` ".$conf["WhereColumnOperator"][$i]." '".mysqli_real_escape_string($mysqli,$conf["whereValue"][$i])."'";			
1 liveuser 14611
 
14612
					}#if end			
14613
 
14614
				#反之 $conf["WhereColumnOperator"] 不存在
14615
				else{
14616
 
14617
					#設定其它條件
343 liveuser 14618
					$sql=$sql." ".$conf["WhereColumnAndOr"][$i-1]." `".$conf["whereColumn"][$i]. "` = '".mysqli_real_escape_string($mysqli,$conf["whereValue"][$i])."'";			
1 liveuser 14619
 
14620
					}#else end
14621
 
14622
				}#判斷式
14623
 
14624
			}#迴圈結束
14625
 
14626
		#sql語法結束
14627
		$sqlString=$sql.";";			
14628
 
14629
		#執行sql語法
43 liveuser 14630
		#函式說明:
1 liveuser 14631
		#執行mysql指令
43 liveuser 14632
		#回傳結果::
1 liveuser 14633
		#$result["status"],"true"為執行成功;"false"為執行失敗。
14634
		#$result["error"],錯誤訊息的陣列
14635
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
14636
		#$result["queryString"],mysql查詢的語言
14637
		#查詢號的解果,需要解析。
43 liveuser 14638
		#必填參數:
1 liveuser 14639
		$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
14640
		$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
14641
		$conf["db"]["execMysqlQuery"]["dbSql"]=$sqlString;#要執行sql語法
43 liveuser 14642
		#可省略參數: 
1 liveuser 14643
 
14644
		#如果 $conf["dbPassword"] 有設置
14645
		if(isset($conf["dbPassword"])){
14646
 
14647
			$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
14648
 
14649
			}#if end
14650
 
14651
		#如果 $conf["dbPort"] 有設置
14652
		if(isset($conf["dbPort"])){
14653
 
14654
			$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的 3306 port.
14655
 
14656
			}#if end
343 liveuser 14657
 
14658
		#$conf["dbLink"],物件,mysqli物件,由mysqli_connect()回傳的物件內容,若為數值則改用賬號密碼等資訊進行連線,反之則沿用連線物件.
14659
		$conf["db"]["execMysqlQuery"]["dbLink"]=$mysqli;
1 liveuser 14660
 
14661
		$db["execMysqlQuery"]=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
14662
		unset($conf["db"]["execMysqlQuery"]);
14663
 
14664
		#如果sql執行有誤
14665
		if($db["execMysqlQuery"]["status"]=="false"){
14666
 
14667
			#設置錯誤識別
14668
			$result["status"]="false";
14669
 
14670
			#設置錯誤訊息
14671
			$result["error"]=$db["execMysqlQuery"];
14672
 
14673
			#回傳結果
14674
			return $result;
14675
 
14676
			}#if end
14677
 
14678
		#取得執行的sql語法
14679
		$result["sql"]=$db["execMysqlQuery"]["queryString"];
14680
 
14681
		#執行到這邊表執行成功
14682
		$result["status"]="true";
14683
 
14684
		#回傳結果
14685
		return $result;
14686
 
14687
		}#函式結束
14688
 
14689
	/*
43 liveuser 14690
	#函式說明:
1 liveuser 14691
	#取得目標資料庫底下所有資料表的索引鍵,可作為foreign key的可用欄位,欄位必須為index key或primary key.
43 liveuser 14692
	#回傳結果::
1 liveuser 14693
	#$result["status"],執行是否成功"true"為執行成功,"false"為執行失敗。
14694
	#$result["error"],執行的錯誤訊息.
14695
	#$result["function"],當前執行函式名稱.
14696
	#$result["content"][$i]["tableName"],欄位所屬的資料表名稱.
14697
	#$result["content"][$i]["columnKey"],是"primary key"還是"index key".
14698
	#$result["content"][$i]["columnName"],欄位名稱.
14699
	#$result["content"][$i]["typeAndLength"],欄位儲存形態與長度限制.
14700
	#$result["content"][$i]["tableDotColumnName"],欄位的「鍵所屬資料表名稱.鍵欄位名稱」.
14701
	#$result["content"][$i]["tableDotColumnVarType"],「資料索引鍵所屬資料表名稱.索引鍵欄位名稱 儲存變數型別與長度」.
14702
	#$result["indexKey"]["tableName"],index key欄位所屬的資料表陣列
14703
	#$result["indexKey"]["columnName"],index key的欄位名稱陣列
14704
	#$result["indexKey"]["typeAndLength"],index key的欄位儲存型態與長度限制陣列
14705
	#$result["indexKey"]["tableDotColumnName"],index key的 「資料索引鍵所屬資料表名稱.索引鍵欄位名稱」 陣列
14706
	#$result["indexKey"]["tableDotColumnVarType"],index key的 「資料索引鍵所屬資料表名稱.索引鍵欄位名稱 儲存變數型別與長度」 陣列
14707
	#$result["primaryKey"][$tableCount]["dtName"],主鍵所屬的資料表名稱,若沒有主鍵則為null.
14708
	#$result["primaryKey"][$tableCount]["columnName"],資料表的主鍵欄位名稱,若沒有主鍵則為null.
14709
	#$result["primaryKey"][$tableCount]["columnVarType"],資料表的主鍵欄位的儲存形態,若沒有主鍵則為null..
14710
	#$result["primaryKey"][$tableCount]["columnVarLengthLimit"],資料表的主鍵欄位的儲存長度限制,若沒有主鍵則為null.
14711
	#$result["primaryKey"][$tableCount]["columnVarTypeAndLengthLimit"],儲存當前資料表的主鍵欄位的儲存形態與長度限制,若沒有主鍵則為null.
43 liveuser 14712
	#必填參數:
1 liveuser 14713
	#$conf["dbAddress"],字串,爲mysql-Server的位置
14714
	$conf["dbAddress"]=$dbAddress;
14715
	#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
14716
	$conf["dbAccount"]=$dbAccount;
14717
	#$conf["selectedDataBaseName"],字串,爲目標資料表所屬的資料庫
14718
	$conf["selectedDataBaseName"]="";#
43 liveuser 14719
	#可省略參數:
1 liveuser 14720
	#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
14721
	#$conf["dbPassword"]=$dbPassword;#
14722
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
14723
	#$conf["dbPort"]=$dbPort;
185 liveuser 14724
	#參考資料:
14725
	#無.
1 liveuser 14726
	#備註:
14727
	#目前只能取得一個資料庫的所有索引鍵.
14728
	*/
14729
	public static function getAllIndexKeyInAllDataBase(&$conf){
14730
 
14731
		#初始化要回傳的內容
14732
		$result=array();
14733
 
14734
		#取得當前執行的函數名稱
14735
		$result["function"]=__FUNCTION__;
14736
 
14737
		#如果 $conf 不為陣列
14738
		if(gettype($conf)!="array"){
14739
 
14740
			#設置執行失敗
14741
			$result["status"]="false";
14742
 
14743
			#設置執行錯誤訊息
14744
			$result["error"][]="\$conf變數須為陣列形態";
14745
 
14746
			#如果傳入的參數為 null
14747
			if($conf==null){
14748
 
14749
				#設置執行錯誤訊息
14750
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
14751
 
14752
				}#if end
14753
 
14754
			#回傳結果
14755
			return $result;
14756
 
14757
			}#if end
14758
 
14759
		#檢查參數
43 liveuser 14760
		#函式說明:
1 liveuser 14761
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
14762
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
14763
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
14764
		#$result["function"],當前執行的函式名稱.
14765
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
14766
		#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
14767
		#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
14768
		#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
14769
		#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
14770
		#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
14771
		#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
14772
		#$result["notNeedVar"],字串陣列,多餘的參數名稱.
43 liveuser 14773
		#必填參數:
1 liveuser 14774
		#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
14775
		$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
14776
		#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
14777
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","selectedDataBaseName");
14778
		#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
14779
		$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
14780
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
14781
		$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
43 liveuser 14782
		#可省略參數:
1 liveuser 14783
		#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
14784
		#$conf["canBeEmptyString"]="false";
14785
		#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
14786
		$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("dbPassword","dbPort");
14787
		#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
14788
		$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort");
14789
		#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
14790
		$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
14791
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
14792
		$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null);
14793
		#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
14794
		#$conf["arrayCountEqualCheck"][]=array();
43 liveuser 14795
		#參考資料:
1 liveuser 14796
		#array_keys=>http://php.net/manual/en/function.array-keys.php
14797
		$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
14798
		unset($conf["variableCheck::checkArguments"]);
14799
 
14800
		#如果檢查有誤
14801
		if($checkResult["status"]=="false"){
14802
 
14803
			#設置執行錯誤的識別
14804
			$result["status"]="false";
14805
 
14806
			#設置錯誤訊息
14807
			$result["error"]=$checkResult;
14808
 
14809
			#回傳結果
14810
			return $result;
14811
 
14812
			}#if end
14813
 
14814
		#如果檢查不通過
14815
		if($checkResult["passed"]=="false"){
14816
 
14817
			#設置執行錯誤的識別
14818
			$result["status"]="false";
14819
 
14820
			#設置錯誤訊息
14821
			$result["error"]=$checkResult;
14822
 
14823
			#回傳結果
14824
			return $result;
14825
 
14826
			}#if end
14827
 
14828
		#取得資料表列表
14829
		#查詢特定資料庫裡的資料表列表,會回傳查詢的結果
14830
		#$result["connectStatus"],若成功則爲0,失敗則爲1。
14831
		#$result["connectInformation"],爲回傳的mysql連線資訊。
14832
		#$result["tableName"] 爲查詢的資料庫名稱陣列,
14833
			#第一筆資料庫名稱爲$result["tableName"][0],
14834
			#第二筆資料庫名稱爲$result["tableName"][1],
14835
			#其餘以此類推。
14836
		#$result["dataCounts"] 爲資料庫的總筆數
43 liveuser 14837
		#必填參數:
1 liveuser 14838
		$conf["db"]["getDataTableList"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
14839
		$conf["db"]["getDataTableList"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
14840
		$conf["db"]["getDataTableList"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲指定的資料庫名稱
43 liveuser 14841
		#可省略參數:
1 liveuser 14842
 
14843
		#如果有設定 $conf["dbPassword"]
14844
		if(isset($conf["dbPassword"])){
14845
 
14846
			#則套用設定
14847
			$conf["db"]["getDataTableList"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
14848
 
14849
			}#if end
14850
 
14851
		#如果有設定 $conf["dbPort"]
14852
		if(isset($conf["dbPort"])){
14853
 
14854
			#則套用設定
14855
			$conf["db"]["getDataTableList"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,預設為3306.
14856
 
14857
			}#if end
14858
 
14859
		#原始語法:
14860
		#show tables FROM databaseName,代表檢視databaseName裡面的資料表清單。
14861
		$tableList=db::getDataTableList($conf["db"]["getDataTableList"]);
14862
		unset($conf["db"]);
14863
 
14864
		#debug
14865
		#var_dump($tableList);
14866
 
14867
		#如果 資料表清單 取得失敗
14868
		if($tableList["status"]=="false"){
14869
 
14870
			#設置執行錯誤的識別
14871
			$result["status"]="fasle";
14872
 
14873
			#設置錯誤訊息
14874
			$result["error"]="取得資料表清單失敗";
14875
 
14876
			#回傳結果
14877
			return $result;
14878
 
14879
			}#if end
14880
 
14881
		#初始化資料表的計數變數
14882
		$tableCount=0;
14883
 
14884
		#初始化儲存 index key
14885
		$result["indexKey"]=array();
14886
 
14887
		#初始化儲存index key所屬的表格 
14888
		$result["indexKey"]["tableName"]=array();
14889
 
14890
		#根據每個資料表
14891
		foreach($tableList["tableName"] as $tableName){
14892
 
14893
			#取得該資料表的欄位資訊
43 liveuser 14894
			#函式說明:
1 liveuser 14895
			#取得資料表所有欄位的詳細資訊
14896
			#回傳的內容:
14897
			#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
14898
			#$result["error"],錯誤訊息陣列
14899
			#$result["sql"],執行的sql語法
14900
			#$result["oriInput"],原始的資料表欄位資訊
14901
			#$result["everyLine"],逐行的欄位資訊
14902
			#$result["tableName"],當前查詢的資料表名稱
14903
			#$result["engine"],資料表使用的儲存引擎
14904
			#$result["charset"],資料表預設的編碼
14905
			#$result["columnName"][$i],各欄位的名稱陣列,$i爲0開始的數字,也可以使用欄位的名稱。
14906
			#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲0開始的數字,也可以使用欄位的名稱。
14907
			#$result["columnVarType"][$i],各欄位變數儲存的型態,$i爲1開始的數字,也可以使用欄位的名稱.
14908
			#$result["columnVarLengthLimit"][$i],個欄位變數的長度限制,若不存在其限制,則為"",$i爲1開始的數字,也可以使用欄位的名稱.
14909
			#$result["columnNotNull"][$i],各欄位是否可以不爲null,"true"爲可以不爲null;"false"爲可以爲"null",$i爲0開始的數字,也可以使用欄位的名稱。
14910
			#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲0開始的數字,也可以使用欄位的名稱。
14911
			#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲0開始的數字,也可以使用欄位的名稱。
14912
			#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲0開始的數字,也可以使用欄位的名稱。
14913
			#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲0開始的數字,也可以使用欄位的名稱。
14914
			#$result["columnCollate"][$i],各欄位使用的Collate,$i爲0開始的數字,也可以使用欄位的名稱。
14915
			#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
14916
			#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
14917
			#$result["keyConstraintName"][$j],該資料表用於識別索引鍵的CONSTRAINT名稱陣列,$j爲0開始的數字,也可以使用欄位的名稱。
14918
			#$result["primaryKey"],該資料表的主鍵
14919
			#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
14920
			#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲0開始的數字,也可以使用欄位的名稱。
14921
			#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列,$k爲0開始的數字,也可以使用欄位的名稱。
14922
			#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲0開始的數字
14923
			#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲0開始的數字
14924
			#$result["foreignKey"]["OnUpdateAction"][$l],當參照的欄位資料更新時,會怎麼同步,$l爲0開始的數字
14925
			#$result["foreignKey"]["OnDeleteAction"][$m],當參照的欄位資料移除時,會怎麼同步,$m爲0開始的數字
43 liveuser 14926
			#必填參數:
1 liveuser 14927
			$conf["db"]["getTableColumnDetailInfo"]["dbAddress"]=$conf["dbAddress"];#資料庫的網路位置
14928
			$conf["db"]["getTableColumnDetailInfo"]["dbAccount"]=$conf["dbAccount"];#連線到資料庫要用的帳號
14929
			$conf["db"]["getTableColumnDetailInfo"]["selectedDataBase"]=$conf["selectedDataBaseName"];#連線到資料庫要選擇的資料庫
14930
			$conf["db"]["getTableColumnDetailInfo"]["selectedDataTable"]=$tableName;#連線到資料庫要檢視的資料表
43 liveuser 14931
			#可省略參數:
1 liveuser 14932
 
14933
			#如果有設定 $conf["dbPassword"]
14934
			if(isset($conf["dbPassword"])){
14935
 
14936
				#則套用設定
14937
				$conf["db"]["getTableColumnDetailInfo"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
14938
 
14939
				}#if end
14940
 
14941
			#如果有設定 $conf["dbPort"]
14942
			if(isset($conf["dbPort"])){
14943
 
14944
				#則套用設定
14945
				$conf["db"]["getTableColumnDetailInfo"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,預設為3306.
14946
 
14947
				}#if end
14948
 
14949
			$columnData=db::getTableColumnDetailInfo($conf["db"]["getTableColumnDetailInfo"]);
14950
			unset($conf["db"]["getTableColumnDetailInfo"]);
14951
 
14952
			#如果取得資料表結構詳細資訊失敗
14953
			if($columnData["status"]=="false"){
14954
 
14955
				#設置執行錯誤的識別
14956
				$result["status"]="fasle";
14957
 
14958
				#設置錯誤訊息
14959
				$result["error"]=$columnData;
14960
 
14961
				#回傳結果
14962
				return $result;
14963
 
14964
				}#if end
14965
 
14966
			#儲存當前資料表的主鍵所屬資料表名稱
14967
			$result["primaryKey"][$tableCount]["dtName"]=$tableName;
14968
 
14969
			#如果該資料表沒有主鍵
14970
			if(!isset($columnData["primaryKey"])){
14971
 
14972
				#將數值設為null
14973
 
14974
				#儲存當前資料表的主鍵欄位名稱
14975
				$result["primaryKey"][$tableCount]["columnName"]=null;
14976
 
14977
				#儲存當前資料表的主鍵欄位的儲存形態
14978
				$result["primaryKey"][$tableCount]["columnVarType"]=null;
14979
 
14980
				#儲存當前資料表的主鍵欄位的儲存長度限制
14981
				$result["primaryKey"][$tableCount]["columnVarLengthLimit"]=null;
14982
 
14983
				#儲存當前資料表的主鍵欄位的儲存形態與長度限制
14984
				$result["primaryKey"][$tableCount]["columnVarTypeAndLengthLimit"]=null;
14985
 
14986
				}#if end
14987
 
14988
			#反之有主鍵
14989
			else{
14990
 
14991
				#儲存當前資料表的主鍵欄位名稱
14992
				$result["primaryKey"][$tableCount]["columnName"]=$columnData["primaryKey"];
14993
 
14994
				#儲存當前資料表的主鍵欄位的儲存形態
14995
				$result["primaryKey"][$tableCount]["columnVarType"]=$columnData["columnVarType"][$columnData["primaryKey"]];
14996
 
14997
				#儲存當前資料表的主鍵欄位的儲存長度限制
14998
				$result["primaryKey"][$tableCount]["columnVarLengthLimit"]=$columnData["columnVarLengthLimit"][$columnData["primaryKey"]];
14999
 
15000
				#儲存當前資料表的主鍵欄位的儲存形態與長度限制
15001
				$result["primaryKey"][$tableCount]["columnVarTypeAndLengthLimit"]=$columnData["columnVarTypeAndLengthLimit"][$columnData["primaryKey"]];
15002
 
15003
				}#else end
15004
 
15005
			#資料表計數加1
15006
			$tableCount++;			
15007
 
15008
			#如果有index key
15009
			if($columnData["key"]["exist"]=="true"){
15010
 
15011
				#依據每個index key
15012
				for($i=0;$i<count($columnData["key"]);$i++){
15013
 
15014
					#如果該元素不存在
15015
					if(!isset($columnData["key"][$i])){
15016
 
15017
						#中斷迴圈
15018
						break;
15019
 
15020
						}#if end
15021
 
15022
					#取得其index key欄位
15023
					$tempColumnName=$result["indexKey"]["columnName"][]=$columnData["key"][$i];
15024
 
15025
					#如果 $columnData["columnVarTypeAndLengthLimit"][$i] 有設置
15026
					if(isset($columnData["columnVarTypeAndLengthLimit"][$tempColumnName])){
15027
 
15028
						#取得該欄位的儲存變數型別與長度限制
15029
						$result["indexKey"]["typeAndLength"][]=$columnData["columnVarTypeAndLengthLimit"][$tempColumnName];
15030
 
15031
						}#if end
15032
 
15033
					#反之
15034
					else{
15035
 
15036
						#將 得該欄位的儲存變數型別與長度限制 設為 ""
15037
						$result["indexKey"]["typeAndLength"][]="";
15038
 
15039
						}#else end	
15040
 
15041
					#取得其index key的所屬資料表
15042
					$result["indexKey"]["tableName"][]=$tableName;
15043
 
15044
					}#for end
15045
 
15046
				}#if end
15047
 
15048
			}#foreach end
15049
 
15050
		#根據每個索引鍵欄位與其所屬的資料表來建立 「索引鍵所屬資料表名稱.索引鍵欄位名稱 儲存變數型別與長度」 格式的陣列
15051
		for($i=0;$i<count($result["indexKey"]["tableName"]);$i++){
15052
 
15053
			#設置 索引鍵所屬資料表名稱.索引鍵欄位名稱 格式的陣列
15054
			$result["indexKey"]["tableDotColumnName"][]=$result["indexKey"]["tableName"][$i].".".$result["indexKey"]["columnName"][$i];
15055
 
15056
			#設置 索引鍵所屬資料表名稱.索引鍵欄位名稱 欄位儲存型態與長度限制 格式的陣列
15057
			$result["indexKey"]["tableDotColumnVarType"][]=$result["indexKey"]["tableName"][$i].".".$result["indexKey"]["columnName"][$i]." ".$result["indexKey"]["typeAndLength"][$i];
15058
 
15059
			}#for end
15060
 
15061
		#組裝主鍵與索引鍵的資訊
15062
		#$result["content"][$i]["tableName"],欄位所屬的資料表名稱.
15063
		#$result["content"][$i]["columnKey"],是"primary key"還是"index key".
15064
		#$result["content"][$i]["columnName"],欄位名稱.
15065
		#$result["content"][$i]["typeAndLength"],欄位儲存形態與長度限制.
15066
		#$result["content"][$i]["tableDotColumnName"],欄位的「鍵所屬資料表名稱.鍵欄位名稱」.
15067
		#$result["content"][$i]["tableDotColumnVarType"],「資料索引鍵所屬資料表名稱.索引鍵欄位名稱 儲存變數型別與長度」.
15068
		#$result["indexKey"]["tableName"],index key欄位所屬的資料表陣列
15069
		#$result["indexKey"]["columnName"],index key的欄位名稱陣列
15070
		#$result["indexKey"]["typeAndLength"],index key的欄位儲存型態與長度限制陣列
15071
		#$result["indexKey"]["tableDotColumnName"],index key的 「資料索引鍵所屬資料表名稱.索引鍵欄位名稱」 陣列
15072
		#$result["indexKey"]["tableDotColumnVarType"],index key的 「資料索引鍵所屬資料表名稱.索引鍵欄位名稱 儲存變數型別與長度」 陣列
15073
		#$result["primaryKey"][$tableCount]["dtName"],主鍵所屬的資料表名稱,若沒有主鍵則為null.
15074
		#$result["primaryKey"][$tableCount]["columnName"],資料表的主鍵欄位名稱,若沒有主鍵則為null.
15075
		#$result["primaryKey"][$tableCount]["columnVarType"],資料表的主鍵欄位的儲存形態,若沒有主鍵則為null..
15076
		#$result["primaryKey"][$tableCount]["columnVarLengthLimit"],資料表的主鍵欄位的儲存長度限制,若沒有主鍵則為null.
15077
		#$result["primaryKey"][$tableCount]["columnVarTypeAndLengthLimit"],儲存當前資料表的主鍵欄位的儲存形態與長度限制,若沒有主鍵則為null.
15078
 
15079
		#能夠被外鍵參照的欄位計數
15080
		$referenceColumnCount=0;
15081
 
15082
		#有幾個主鍵就執行幾次
15083
		for($i=0;$i<count($result["primaryKey"]);$i++){
15084
 
15085
			#暫存當前資料表的名稱
15086
			$dtName=$result["primaryKey"][$i]["dtName"];
15087
 
15088
			#如果主鍵欄位名稱不為 null,亦即有主鍵
15089
			if($result["primaryKey"][$i]["columnName"]!=null){
15090
 
15091
				#儲存欄位所屬的資料表名稱.
15092
				$result["content"][$referenceColumnCount]["tableName"]=$dtName;
15093
 
15094
				#儲存是"primary key"還是"index key".
15095
				$result["content"][$referenceColumnCount]["columnKey"]="primary key";
15096
 
15097
				#儲存欄位名稱
15098
				$result["content"][$referenceColumnCount]["columnName"]=$result["primaryKey"][$i]["columnName"];
15099
 
15100
				#儲存欄位儲存形態與長度限制.
15101
				$result["content"][$referenceColumnCount]["typeAndLength"]=$result["primaryKey"][$i]["columnVarLengthLimit"];
15102
 
15103
				#儲存欄位的「鍵所屬資料表名稱.鍵欄位名稱」.
15104
				$result["content"][$referenceColumnCount]["tableDotColumnName"]=$dtName.".".$result["primaryKey"][$i]["columnName"];
15105
 
15106
				#儲存欄位的「資料索引鍵所屬資料表名稱.索引鍵欄位名稱 儲存變數型別與長度」.
15107
				$result["content"][$referenceColumnCount]["tableDotColumnVarType"]=$dtName.".".$result["primaryKey"][$i]["columnName"]." ".$result["primaryKey"][$i]["columnVarTypeAndLengthLimit"];
15108
 
15109
				#能夠被外鍵參照的欄位計數加1
15110
				$referenceColumnCount++;	
15111
 
15112
				}#if end
15113
 
15114
			#用當前資料表的名稱取得索引鍵的資訊
15115
 
15116
			#所有資料表有幾個索引鍵就執行幾次
15117
			for($j=0;$j<count($result["indexKey"]["tableName"]);$j++){
15118
 
15119
				#如果是當前資料表的索引鍵
15120
				if($result["indexKey"]["tableName"][$j]==$dtName){
15121
 
15122
					#儲存欄位所屬的資料表名稱.
15123
					$result["content"][$referenceColumnCount]["tableName"]=$dtName;
15124
 
15125
					#儲存是"primary key"還是"index key".
15126
					$result["content"][$referenceColumnCount]["columnKey"]="index key";
15127
 
15128
					#儲存欄位名稱
15129
					$result["content"][$referenceColumnCount]["columnName"]=$result["indexKey"]["columnName"][$j];
15130
 
15131
					#儲存欄位儲存形態與長度限制.
15132
					$result["content"][$referenceColumnCount]["typeAndLength"]=$result["indexKey"]["typeAndLength"][$j];
15133
 
15134
					#儲存欄位的「鍵所屬資料表名稱.鍵欄位名稱」.
15135
					$result["content"][$referenceColumnCount]["tableDotColumnName"]=$result["indexKey"]["tableDotColumnName"][$j];
15136
 
15137
					#儲存欄位的「資料索引鍵所屬資料表名稱.索引鍵欄位名稱 儲存變數型別與長度」.
15138
					$result["content"][$referenceColumnCount]["tableDotColumnVarType"]=$result["indexKey"]["tableDotColumnVarType"][$j];
15139
 
15140
					#能夠被外鍵參照的欄位計數加1
15141
					$referenceColumnCount++;	
15142
 
15143
					}#if end
15144
 
15145
				}#for end
15146
 
15147
			}#for end
15148
 
15149
		#執行到這邊代表執行成功
15150
		$result["status"]="true";
15151
 
15152
		#回傳結果
15153
		return $result;
15154
 
15155
		}#function getAllIndexKeyInAllDataBase end 
15156
 
15157
	/*
15158
	#函式說明:
15159
	#將資料表輸出成csv檔案
43 liveuser 15160
	#回傳結果:
1 liveuser 15161
	#$result["status"],執行是否正常,"true"代表執行正常,"false"代表執行失敗.
15162
	#$result["error"],錯誤訊息
15163
	#$result["function"],當前執行的涵式
15164
	#$result["csvFile"],輸出的csv檔案位置與名稱.
43 liveuser 15165
	#必填參數:
1 liveuser 15166
	#$conf["dbAddress"],字串,欲連線的mariadb/mysql伺服器IP/domainName位置.
15167
	$conf["dbAddress"]=$dbAddress;
15168
	#$conf["dbAccount"],字串,連線到mariadb/mysql所用的帳戶.
15169
	$conf["dbAccount"]=$dbAccount;
15170
	#$conf["dbName"],字串,目標資料表位於哪個資庫底下.
15171
	$conf["dbName"]=$dbName;
15172
	#$conf["dtName"],字串,目標資料表的名稱.
15173
	$conf["dtName"]="";
43 liveuser 15174
	#可省略參數:
1 liveuser 15175
	#$conf["dbPassword"],字串,連線到mariadb/mysql伺服器時所使用的密碼,若未設置則代表不使用密碼來連線.
15176
	#$conf["dbPassword"]=$dbPassword;
15177
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
15178
	#$conf["dbPort"]=$dbPort;
15179
	#$conf["column"],陣列,要的欄位名稱,預設為「array(*)」代表所有欄位都要, 
15180
	#$conf["column"]=array("*");
15181
	#$conf["WhereColumnName"],陣列,篩選用的特定欄位
15182
	#$conf["WhereColumnName"]=array("");
15183
	#$conf["WhereColumnValue"],陣列,篩選用特定欄位的數值要等於多少才是我們要的.
15184
	#$conf["WhereColumnValue"]=array("");
15185
	#$conf["groupBy"],陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆).
15186
	#$conf["groupBy"]=array("");
15187
	#$conf["orderItem"],字串,爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
15188
	#$conf["orderItem"]="";#
15189
	#$conf["ascORdesc"],字串,爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
15190
	#$conf["ascORdesc"]="asc";
15191
	#$conf["outPutPathAndName"],字串,輸出的csv檔案要存放在哪裡.
15192
	#$conf["outPutPathAndName"]="";
15193
	#$conf["noDownload"],字串,如果爲"true"則代表不要讓使用者下載,但會回傳檔案的相對位置
15194
	#$conf["noDownload"]="true";
185 liveuser 15195
	#參考資料:
15196
	#無.
43 liveuser 15197
	#備註:
15198
	#無.
1 liveuser 15199
	*/
15200
	public static function exportTableToCsv($conf){
15201
 
15202
		#初始化要回傳的內容
15203
		$result=array();
15204
 
15205
		#取得當前執行的函數名稱
15206
		$result["function"]=__FUNCTION__;
15207
 
15208
		#如果 $conf 不為陣列
15209
		if(gettype($conf)!="array"){
15210
 
15211
			#設置執行失敗
15212
			$result["status"]="false";
15213
 
15214
			#設置執行錯誤訊息
15215
			$result["error"][]="\$conf變數須為陣列形態";
15216
 
15217
			#如果傳入的參數為 null
15218
			if($conf==null){
15219
 
15220
				#設置執行錯誤訊息
15221
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
15222
 
15223
				}#if end
15224
 
15225
			#回傳結果
15226
			return $result;
15227
 
15228
			}#if end
15229
 
15230
		#檢查參數
43 liveuser 15231
		#函式說明:
1 liveuser 15232
		#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
43 liveuser 15233
		#回傳結果:
1 liveuser 15234
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15235
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
15236
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
15237
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
43 liveuser 15238
		#必填參數:
1 liveuser 15239
		$conf["db"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
15240
		$conf["db"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","dbName","dtName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
43 liveuser 15241
		#可省略參數:
1 liveuser 15242
		$conf["db"]["isexistMuti"]["variableType"]=array("string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double"); 
15243
		$conf["db"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
15244
		$checkResult=variableCheck::isexistMulti($conf["db"]["isexistMuti"]);
15245
		unset($conf["db"]["isexistMuti"]);
15246
 
15247
		#如果 $checkResult["status"] 等於 "false"
15248
		if($checkResult["status"]=="false"){
15249
 
15250
			#設置錯誤識別
15251
			$result["status"]="false";
15252
 
15253
			#設置錯誤訊息
15254
			$result["error"]=$checkResult;
15255
 
15256
			#回傳結果
15257
			return $result;
15258
 
15259
			}#if end
15260
 
15261
		#如果 $checkResult["passed"] 等於 "false"
15262
		if($checkResult["passed"]=="false"){
15263
 
15264
			#設置錯誤識別
15265
			$result["status"]="false";
15266
 
15267
			#設置錯誤訊息
15268
			$result["error"]=$checkResult;
15269
 
15270
			#回傳結果
15271
			return $result;
15272
 
15273
			}#if end
15274
 
15275
		#如果 $conf["column"] 沒有設置
15276
		if(!isset($conf["column"])){
15277
 
15278
			#則代表要全部的欄位
15279
			$conf["column"]=array("*");
15280
 
15281
			}#if end
15282
 
15283
		#抓取資料表資料
43 liveuser 15284
		#函式說明:
1 liveuser 15285
		#一次取得資料庫、表的資料
43 liveuser 15286
		#回傳結果:
1 liveuser 15287
		#$result["status"],執行結果"true"為成功;"false"為執行失敗。
15288
		#$result["error"],錯誤訊息陣列。
15289
		#$result["dataColumnName"],抓取的資料欄位名稱陣列.
15290
		#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
15291
		#$result["dataContent"],爲資料的內容。
15292
		#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
15293
			#$dataSetNum 爲第$dataSetNum+1筆資料
15294
			#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
15295
		#$result["dataCount"],爲取得的資料筆數。
15296
		#$result["sql"],執行的sql字串.
43 liveuser 15297
		#必填參數:
1 liveuser 15298
		$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"];#爲dbServer的位置。
15299
		$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"];#爲登入dbServer的帳號。
15300
		$conf["db"]["fastGetDbData"]["dbName"]=$conf["dbName"];#爲要存取的資料庫名稱
15301
		$conf["db"]["fastGetDbData"]["tableName"]=$conf["dtName"];#爲要存取的資料表名稱
15302
		$conf["db"]["fastGetDbData"]["columnYouWant"]=$conf["column"];#你想要的欄位!
43 liveuser 15303
		#可省略參數:
1 liveuser 15304
 
15305
		#如果 $conf["dbPassword"] 有設置 
15306
		if(isset($conf["dbPassword"])){
15307
 
15308
			#則設定進行連線密碼
15309
			$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"];#爲要存取dbServer的密碼
15310
 
15311
			}#if end
15312
 
15313
		#如果 $conf["dbPort"] 有設置 
15314
		if(isset($conf["dbPort"])){
15315
 
15316
			#則設定進行連線的 port
15317
			$conf["db"]["fastGetDbData"]["dbPort"]=$conf["dbPort"];#爲要存取dbServer的port
15318
 
15319
			}#if end
15320
 
15321
		#如果 $conf["WhereColumnName"] 有設置
15322
		if(isset($conf["WhereColumnName"])){
15323
 
15324
			$conf["db"]["fastGetDbData"]["WhereColumnName"]=$conf["WhereColumnName"];#用於判斷語句的欄位項目陣列。
15325
 
15326
			}#if end
15327
 
15328
		#如果 $conf["WhereColumnValue"] 有設置
15329
		if(isset($conf["WhereColumnValue"])){
15330
 
15331
			$conf["db"]["fastGetDbData"]["WhereColumnValue"]=$conf["WhereColumnValue"];#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
15332
 
15333
			}#if end
15334
 
15335
		#$conf["db"]["fastGetDbData"]["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
15336
		#$conf["db"]["fastGetDbData"]["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
15337
		#$conf["db"]["fastGetDbData"]["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
15338
 
15339
		#如果 $conf["orderItem"] 有設定
15340
		if(isset($conf["orderItem"])){
15341
 
15342
			$conf["db"]["fastGetDbData"]["orderItem"]=$conf["orderItem"];#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
15343
 
15344
			}#if end
15345
 
15346
		#如果 $conf["ascORdesc"] 有設定
15347
		if(isset($conf["ascORdesc"])){
15348
 
15349
 
15350
			$conf["db"]["fastGetDbData"]["ascORdesc"]=$conf["ascORdesc"];#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
15351
 
15352
			}#if end
15353
 
15354
		#$conf["db"]["fastGetDbData"]["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
15355
		#$conf["db"]["fastGetDbData"]["numLimit"]="30";#為要取幾筆資料,可以省略,省略則表示不限制數目。
15356
 
15357
		#如果 $conf["groupBy"] 有設定
15358
		if(isset($conf["groupBy"])){
15359
 
15360
			$conf["db"]["fastGetDbData"]["groupBy"]=$conf["groupBy"];#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆).
15361
 
15362
			}#if end
15363
 
15364
		$db["fastGetDbData"]=db::fastGetDbData($conf["db"]["fastGetDbData"]);
15365
		unset($conf["db"]["fastGetDbData"]);
15366
 
15367
		#var_dump($db["fastGetDbData"]);
15368
 
15369
		#如果 $db["fastGetDbData"]["status"] 等於 "false"
15370
		if($db["fastGetDbData"]["status"]=="false"){
15371
 
15372
			#設置錯誤識別
15373
			$result["status"]="false";
15374
 
15375
			#設置錯誤訊息
15376
			$result["error"]=$db["fastGetDbData"];
15377
 
15378
			#回傳結果
15379
			return $result;
15380
 
15381
			}#if end
15382
 
15383
		#初始化要寫入的內容
15384
		$writedData[0]=$db["fastGetDbData"]["dataColumnName"];
15385
 
15386
		#var_dump($writedData);
15387
 
15388
		#取得要寫入的欄位數值
15389
 
15390
		#針對每筆資料
15391
		for($i=0;$i<$db["fastGetDbData"]["dataCount"];$i++){
15392
 
15393
			#依據每個欄位
15394
			for($j=0;$j<count($db["fastGetDbData"]["dataColumnName"]);$j++){
15395
 
15396
				#儲存到列裡面
15397
				$writedData[$i+1][]=$db["fastGetDbData"]["dataContent"][$db["fastGetDbData"]["dataColumnName"][$j]][$i];
15398
 
15399
				}#foreach end
15400
 
15401
			}#for end
15402
 
15403
		#var_dump($writedData);
15404
 
15405
		#輸出成csv檔
43 liveuser 15406
		#函式說明:
1 liveuser 15407
		#快速建立一個csv檔案,並且要求使用者下載。
43 liveuser 15408
		#回傳結果::
1 liveuser 15409
		#如果有設置$conf["noDownload"]爲"true"的話,則會回傳檔案的位置
43 liveuser 15410
		#必填參數:
1 liveuser 15411
		$conf["db"]["create"]["dataArray"]=$writedData;#要寫入的文字,$conf["dataArray"][$i],代表第 $i 行的內容。
43 liveuser 15412
		#可省略參數:
1 liveuser 15413
 
15414
		#如果有設置 $conf["outPutPathAndName"]
15415
		if(isset($conf["outPutPathAndName"])){
15416
 
15417
			$conf["db"]["create"]["csvFilePathAndName"]=$conf["outPutPathAndName"];#csv檔案的名稱,預設爲系統時間
15418
 
15419
			}#if end
15420
 
15421
		#如果 $conf["noDownload"] 有設置
15422
		if(isset($conf["noDownload"])){
15423
 
15424
			#且$conf["noDownload"]等於"true"
15425
			if($conf["noDownload"]=="true"){
15426
 
15427
				$conf["db"]["create"]["noDownload"]="true";#如果爲"true"則代表不要讓使用者下載,但會回傳檔案的相對位置
15428
 
15429
				}#if end	
15430
 
15431
			}#if end
15432
 
15433
		#參考資料來源:
15434
		#http://php.net/manual/en/function.str-split.php
15435
		return csv::create($conf["db"]["create"]);
15436
		unset($conf["db"]["create"]);
15437
 
15438
		}#funciton exportTableToCsv end
15439
 
15440
	/*
43 liveuser 15441
	#函式說明:
1 liveuser 15442
	#透過一筆筆將資料表刪除後,重設識別欄位的自動增量欄位起始值為1
43 liveuser 15443
	#回傳結果:
1 liveuser 15444
	#$result["status"],執行是否正常,"true"代表執行正常,"false"代表執行失敗.
15445
	#$result["error"],錯誤訊息.
15446
	#$result["function"],當前執行的函數名稱.
15447
	#$result["sql"],執行的sql語法陣列.
15448
	#必填參數:
15449
	#$conf["dbAddress"],字串,連線到資料庫的位置.
15450
	$conf["dbAddress"]=$dbAddress;
15451
	#$conf["dbAccount"],字串,連線到資料庫的帳號.
15452
	$conf["dbAccount"]=$dbAccount;
15453
	#$conf["dbName"],字串,要連線到哪個資料庫.
15454
	$conf["dbName"]=$dbName;
15455
	#$conf["dtName"],字串,要重設重設識別欄位的自動增量為0的資料表名稱.
15456
	$conf["dtName"]="";
15457
	#可省略參數:
15458
	#$conf["dbPassword"],字串,連線到資料庫的密碼.
15459
	#$conf["dbPassword"]=$dbPassword;
15460
	#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
15461
	#$conf["dbPort"]=$dbPort;
15462
	#參考資料:
15463
	#http://dev.mysql.com/doc/refman/5.0/en/alter-table.html
43 liveuser 15464
	#備註:
15465
	#參考語法,ALTER TABLE dbName.dtName AUTO_INCREMENT = 1;
1 liveuser 15466
	*/
15467
	public static function eraseDataInTableThenResetAutoIncrement(&$conf){
15468
 
15469
		#初始化要回傳的內容
15470
		$result=array();
15471
 
15472
		#取得當前執行的函數名稱
15473
		$result["function"]=__FUNCTION__;
15474
 
15475
		#如果 $conf 不為陣列
15476
		if(gettype($conf)!="array"){
15477
 
15478
			#設置執行失敗
15479
			$result["status"]="false";
15480
 
15481
			#設置執行錯誤訊息
15482
			$result["error"][]="\$conf變數須為陣列形態";
15483
 
15484
			#如果傳入的參數為 null
15485
			if($conf==null){
15486
 
15487
				#設置執行錯誤訊息
15488
				$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
15489
 
15490
				}#if end
15491
 
15492
			#回傳結果
15493
			return $result;
15494
 
15495
			}#if end
15496
 
15497
		#檢查參數
43 liveuser 15498
		#函式說明:
1 liveuser 15499
		#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
15500
		#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
15501
		#$reuslt["error"],執行不正常結束的錯訊息陣列.
15502
		#$result["function"],當前執行的函式名稱.
15503
		#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
15504
		#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
15505
		#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
15506
		#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
43 liveuser 15507
		#必填參數:
1 liveuser 15508
		#$conf["variableCheck.checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
15509
		$conf["variableCheck.checkArguments"]["varInput"]=&$conf;
15510
		#$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
15511
		$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","dbName","dtName");
15512
		#$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double"); 
15513
		$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string");
15514
		#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
15515
		$conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
43 liveuser 15516
		#可省略參數:
1 liveuser 15517
		#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
15518
		#$conf["canBeEmptyString"]="false";
15519
		#$conf["variableCheck.checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
15520
		$conf["variableCheck.checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort");
15521
		#$conf["variableCheck.checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double"); 
15522
		$conf["variableCheck.checkArguments"]["skipableVariableType"]=array("string","string");
15523
		#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
15524
		#$conf["skipableVarDefaultValue"]=array("");
15525
		$checkResult=variableCheck::checkArguments($conf["variableCheck.checkArguments"]);
15526
		unset($conf["variableCheck.checkArguments"]);
15527
 
15528
		#如果 檢查參數 失敗
15529
		if($checkResult["status"]=="false"){
15530
 
15531
			#設置執行不正常
15532
			$result["status"]="false";
15533
 
15534
			#設置執行錯誤
15535
			$result["error"]=$checkResult;
15536
 
15537
			#回傳節果
15538
			return $result;
15539
 
15540
			}#if end
15541
 
15542
		#如果 檢查參數 不通過
15543
		if($checkResult["passed"]=="false"){
15544
 
15545
			#設置執行不正常
15546
			$result["status"]="false";
15547
 
15548
			#設置執行錯誤
15549
			$result["error"]=$checkResult;
15550
 
15551
			#回傳節果
15552
			return $result;
15553
 
15554
			}#if end
15555
 
15556
		#執行一筆筆移除資料的sql語法
43 liveuser 15557
		#函式說明:
1 liveuser 15558
		#執行mysql指令
43 liveuser 15559
		#回傳結果::
1 liveuser 15560
		#$result["status"],"true"為執行成功;"false"為執行失敗。
15561
		#$result["error"],錯誤訊息的陣列
15562
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
15563
		#$result["queryString"],mysql查詢的語言
15564
		#查詢號的解果,需要解析。
43 liveuser 15565
		#必填參數:
1 liveuser 15566
		$conf["db.execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
15567
		$conf["db.execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
15568
		$conf["db.execMysqlQuery"]["dbSql"]="DELETE FROM `".$conf["dbName"]."`.`".$conf["dtName"]."` ";#要執行sql語法
43 liveuser 15569
		#可省略參數: 
1 liveuser 15570
 
15571
		#如果有設置 $conf["dbPassword"]
15572
		if(isset($conf["dbPassword"])){
15573
 
15574
			$conf["db.execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
15575
 
15576
			}#if end
15577
 
15578
		#如果有設置 $conf["dbPort"]
15579
		if(isset($conf["dbPort"])){
15580
 
15581
			$conf["db.execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的3306 port.
15582
 
15583
			}#if end
15584
 
15585
		$queryResult=db::execMysqlQuery($conf["db.execMysqlQuery"]);
15586
		unset($conf["db.execMysqlQuery"]);
15587
 
15588
		#如果執行 sql 語法失敗
15589
		if($queryResult["status"]=="false"){
15590
 
15591
			#設置執行不正常
15592
			$result["status"]="false";
15593
 
15594
			#設置執行錯誤
15595
			$result["error"]=$queryResult;
15596
 
15597
			#回傳節果
15598
			return $result;
15599
 
15600
			}#if end
15601
 
15602
		#取得所執行的sql語法
15603
		$result["sql"][]=$queryResult["queryString"];		
15604
 
15605
		#執行重設增量的sql語法
43 liveuser 15606
		#函式說明:
1 liveuser 15607
		#執行mysql指令
43 liveuser 15608
		#回傳結果::
1 liveuser 15609
		#$result["status"],"true"為執行成功;"false"為執行失敗。
15610
		#$result["error"],錯誤訊息的陣列
15611
		#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
15612
		#$result["queryString"],mysql查詢的語言
15613
		#查詢號的解果,需要解析。
43 liveuser 15614
		#必填參數:
1 liveuser 15615
		$conf["db.execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
15616
		$conf["db.execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
15617
		$conf["db.execMysqlQuery"]["dbSql"]="ALTER TABLE ".$conf["dbName"].".".$conf["dtName"]." AUTO_INCREMENT = 1";#要執行sql語法
15618
		#如果有設置 $conf["dbPassword"]
15619
		if(isset($conf["dbPassword"])){
15620
 
15621
			$conf["db.execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
15622
 
15623
			}#if end
15624
 
15625
		#如果有設置 $conf["dbPort"]
15626
		if(isset($conf["dbPort"])){
15627
 
15628
			$conf["db.execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的3306 port.
15629
 
15630
			}#if end
15631
 
15632
		$queryResult=db::execMysqlQuery($conf["db.execMysqlQuery"]);
15633
		unset($conf["db.execMysqlQuery"]);
15634
 
15635
		#如果執行 sql 語法失敗
15636
		if($queryResult["status"]=="false"){
15637
 
15638
			#設置執行不正常
15639
			$result["status"]="false";
15640
 
15641
			#設置執行錯誤
15642
			$result["error"]=$queryResult;
15643
 
15644
			#回傳節果
15645
			return $result;
15646
 
15647
			}#if end
15648
 
15649
		#取得所執行的sql語法
15650
		$result["sql"][]=$queryResult["queryString"];
15651
 
15652
		#設置執行正常
15653
		$result["status"]="true";
15654
 
15655
		#回傳結果
15656
		return $result;
15657
 
15658
		}#function eraseDataInTableThenResetAutoIncrement end
15659
 
15660
	}#db class end
15661
 
15662
?>