| 3 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
|
|
|
5 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 239 |
liveuser |
6 |
Copyright (C) 2014~2026 MIN ZHI, CHEN
|
| 3 |
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 |
/*
|
|
|
27 |
類別說明:
|
|
|
28 |
跟mysql/mariadb操作有關的類別
|
|
|
29 |
備註:
|
|
|
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/
|
|
|
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){
|
| 226 |
liveuser |
51 |
|
| 3 |
liveuser |
52 |
#取得當前執行的函式
|
|
|
53 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
54 |
|
| 3 |
liveuser |
55 |
#設置執行不正常
|
|
|
56 |
$result["status"]="false";
|
| 226 |
liveuser |
57 |
|
| 3 |
liveuser |
58 |
#設置執行錯誤
|
|
|
59 |
$result["error"][]=__NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
60 |
|
| 3 |
liveuser |
61 |
#設置所丟入的參數
|
|
|
62 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
63 |
|
| 3 |
liveuser |
64 |
#回傳結果
|
|
|
65 |
return $result;
|
| 226 |
liveuser |
66 |
|
| 3 |
liveuser |
67 |
}#function __call end
|
| 226 |
liveuser |
68 |
|
| 3 |
liveuser |
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){
|
| 226 |
liveuser |
83 |
|
| 3 |
liveuser |
84 |
#取得當前執行的函式
|
|
|
85 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
86 |
|
| 3 |
liveuser |
87 |
#設置執行不正常
|
|
|
88 |
$result["status"]="false";
|
| 226 |
liveuser |
89 |
|
| 3 |
liveuser |
90 |
#設置執行錯誤
|
|
|
91 |
$result["error"][]="欲呼叫的". __NAMESPACE__ ."/".$method."() 不存在!";
|
| 226 |
liveuser |
92 |
|
| 3 |
liveuser |
93 |
#設置所丟入的參數
|
|
|
94 |
$result["error"][]=$arguments;
|
| 226 |
liveuser |
95 |
|
| 3 |
liveuser |
96 |
#回傳結果
|
|
|
97 |
return $result;
|
| 226 |
liveuser |
98 |
|
| 3 |
liveuser |
99 |
}#function __callStatic end
|
|
|
100 |
|
|
|
101 |
/*
|
|
|
102 |
#函式說明:
|
|
|
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;
|
|
|
114 |
#可省略參數:
|
|
|
115 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
|
|
|
116 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
117 |
#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,預設不使用
|
|
|
118 |
#$conf["dbPort"]="3306";
|
|
|
119 |
#參考資料:
|
|
|
120 |
#無.
|
|
|
121 |
#備註:
|
|
|
122 |
#無.
|
| 226 |
liveuser |
123 |
*/
|
| 3 |
liveuser |
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"){
|
| 226 |
liveuser |
134 |
|
| 3 |
liveuser |
135 |
#設置執行失敗
|
|
|
136 |
$result["status"]="false";
|
| 226 |
liveuser |
137 |
|
| 3 |
liveuser |
138 |
#設置執行錯誤訊息
|
|
|
139 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
140 |
|
|
|
141 |
#如果傳入的參數為 null
|
|
|
142 |
if($conf==null){
|
| 226 |
liveuser |
143 |
|
| 3 |
liveuser |
144 |
#設置執行錯誤訊息
|
|
|
145 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
146 |
|
| 3 |
liveuser |
147 |
}#if end
|
|
|
148 |
|
|
|
149 |
#回傳結果
|
|
|
150 |
return $result;
|
| 226 |
liveuser |
151 |
|
| 3 |
liveuser |
152 |
}#if end
|
|
|
153 |
|
|
|
154 |
#檢查參數
|
|
|
155 |
#函式說明:
|
|
|
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"],字串陣列,多餘的參數名稱.
|
|
|
167 |
#必填參數:
|
|
|
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");
|
| 226 |
liveuser |
172 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
173 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
174 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
175 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
176 |
#可省略參數:
|
|
|
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");
|
| 226 |
liveuser |
181 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
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();
|
|
|
187 |
#參考資料:
|
|
|
188 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
189 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
190 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
191 |
|
| 3 |
liveuser |
192 |
#如果檢查失敗
|
|
|
193 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
194 |
|
| 3 |
liveuser |
195 |
#設置錯誤識別
|
| 170 |
liveuser |
196 |
$result["status"]="false";
|
| 226 |
liveuser |
197 |
|
| 3 |
liveuser |
198 |
#設置錯誤訊息
|
|
|
199 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
200 |
|
| 3 |
liveuser |
201 |
#回傳解果
|
|
|
202 |
return $result;
|
| 226 |
liveuser |
203 |
|
| 3 |
liveuser |
204 |
}#if end
|
|
|
205 |
|
|
|
206 |
#如果 $checkResult["status"]等於"false";
|
|
|
207 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
208 |
|
| 3 |
liveuser |
209 |
#設置錯誤識別
|
| 170 |
liveuser |
210 |
$result["status"]="false";
|
| 226 |
liveuser |
211 |
|
| 3 |
liveuser |
212 |
#設置錯誤訊息
|
|
|
213 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
214 |
|
| 3 |
liveuser |
215 |
#回傳解果
|
|
|
216 |
return $result;
|
| 226 |
liveuser |
217 |
|
| 3 |
liveuser |
218 |
}#if end
|
|
|
219 |
|
|
|
220 |
#如果是 localhost
|
|
|
221 |
if($conf["dbAddress"]==="localhost"){
|
| 226 |
liveuser |
222 |
|
| 3 |
liveuser |
223 |
#卸除dbPort變數
|
|
|
224 |
unset($conf["dbPort"]);
|
| 226 |
liveuser |
225 |
|
| 3 |
liveuser |
226 |
}#if end
|
|
|
227 |
|
| 170 |
liveuser |
228 |
#如果密碼爲空,則爲不使用密碼進行連綫
|
| 3 |
liveuser |
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"]))){
|
| 226 |
liveuser |
237 |
|
| 3 |
liveuser |
238 |
#設置連線失敗的提示
|
|
|
239 |
$result["error"][]="連線失敗,請檢查帳號是否正確.";
|
| 226 |
liveuser |
240 |
|
| 3 |
liveuser |
241 |
#取得連線時的錯誤編號
|
|
|
242 |
$result["error"][]=mysqli_connect_errno();
|
| 226 |
liveuser |
243 |
|
| 3 |
liveuser |
244 |
#取得連線時的錯誤訊息
|
|
|
245 |
$result["error"][]=mysqli_connect_error();
|
| 226 |
liveuser |
246 |
|
| 3 |
liveuser |
247 |
#設置執行失敗
|
|
|
248 |
$result["status"]="false";
|
| 226 |
liveuser |
249 |
|
| 3 |
liveuser |
250 |
#回傳結果
|
|
|
251 |
return $result;
|
| 226 |
liveuser |
252 |
|
| 3 |
liveuser |
253 |
}#if end
|
| 226 |
liveuser |
254 |
|
| 3 |
liveuser |
255 |
}#if end
|
| 226 |
liveuser |
256 |
|
| 3 |
liveuser |
257 |
#反之
|
|
|
258 |
else{
|
| 226 |
liveuser |
259 |
|
| 3 |
liveuser |
260 |
#設定資料庫位置與port與帳號,並連線
|
|
|
261 |
#若連線失敗
|
|
|
262 |
if(!($result["connectInformation"]=@mysqli_connect($conf["dbAddress"].":".$conf["dbPort"],$conf["dbAccount"]))){
|
| 226 |
liveuser |
263 |
|
| 3 |
liveuser |
264 |
#設置連線失敗的提示
|
|
|
265 |
$result["error"][]="連線失敗,請檢查帳號是否正確.";
|
| 226 |
liveuser |
266 |
|
| 3 |
liveuser |
267 |
#取得連線時的錯誤編號
|
|
|
268 |
$result["error"][]=mysqli_connect_errno();
|
| 226 |
liveuser |
269 |
|
| 3 |
liveuser |
270 |
#取得連線時的錯誤訊息
|
|
|
271 |
$result["error"][]=mysqli_connect_error();
|
| 226 |
liveuser |
272 |
|
| 3 |
liveuser |
273 |
#設置執行失敗
|
|
|
274 |
$result["status"]="false";
|
| 226 |
liveuser |
275 |
|
| 3 |
liveuser |
276 |
#回傳結果
|
|
|
277 |
return $result;
|
| 226 |
liveuser |
278 |
|
| 3 |
liveuser |
279 |
}#if end
|
| 226 |
liveuser |
280 |
|
| 3 |
liveuser |
281 |
}#else end
|
| 226 |
liveuser |
282 |
|
| 3 |
liveuser |
283 |
}#if end
|
| 226 |
liveuser |
284 |
|
| 3 |
liveuser |
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"]))){
|
| 226 |
liveuser |
293 |
|
| 3 |
liveuser |
294 |
#設置連線失敗的提示
|
|
|
295 |
$result["error"][]="連線失敗,請檢查帳號密碼是否正確.";
|
| 226 |
liveuser |
296 |
|
| 3 |
liveuser |
297 |
#取得連線時的錯誤編號
|
|
|
298 |
$result["error"][]=mysqli_connect_errno();
|
| 226 |
liveuser |
299 |
|
| 3 |
liveuser |
300 |
#取得連線時的錯誤訊息
|
|
|
301 |
$result["error"][]=mysqli_connect_error();
|
| 226 |
liveuser |
302 |
|
| 3 |
liveuser |
303 |
#設置執行失敗
|
|
|
304 |
$result["status"]="false";
|
| 226 |
liveuser |
305 |
|
| 3 |
liveuser |
306 |
#回傳結果
|
|
|
307 |
return $result;
|
| 226 |
liveuser |
308 |
|
| 3 |
liveuser |
309 |
}#if end
|
|
|
310 |
|
|
|
311 |
}#if end
|
| 226 |
liveuser |
312 |
|
|
|
313 |
#反之
|
| 3 |
liveuser |
314 |
else{
|
| 226 |
liveuser |
315 |
|
| 3 |
liveuser |
316 |
#設定資料庫位置、帳號、密碼,並連綫
|
|
|
317 |
if(!($result["connectInformation"]=@mysqli_connect($conf["dbAddress"].":".$conf["dbPort"],$conf["dbAccount"],$conf["dbPassword"]))){
|
| 226 |
liveuser |
318 |
|
| 3 |
liveuser |
319 |
#設置連線失敗的提示
|
|
|
320 |
$result["error"][]="連線失敗,請檢查帳號密碼是否正確.";
|
| 226 |
liveuser |
321 |
|
| 3 |
liveuser |
322 |
#取得連線時的錯誤編號
|
|
|
323 |
$result["error"][]=mysqli_connect_errno();
|
| 226 |
liveuser |
324 |
|
| 3 |
liveuser |
325 |
#取得連線時的錯誤訊息
|
|
|
326 |
$result["error"][]=mysqli_connect_error();
|
| 226 |
liveuser |
327 |
|
| 3 |
liveuser |
328 |
#設置執行失敗
|
|
|
329 |
$result["status"]="false";
|
| 226 |
liveuser |
330 |
|
| 3 |
liveuser |
331 |
#回傳結果
|
|
|
332 |
return $result;
|
| 226 |
liveuser |
333 |
|
| 3 |
liveuser |
334 |
}#if end
|
| 226 |
liveuser |
335 |
|
| 3 |
liveuser |
336 |
}#else end
|
|
|
337 |
|
|
|
338 |
}#else end
|
| 226 |
liveuser |
339 |
|
| 3 |
liveuser |
340 |
#使編碼為utf8
|
|
|
341 |
if(!(mysqli_query($result["connectInformation"],'SET NAMES UTF8'))){
|
| 226 |
liveuser |
342 |
|
| 3 |
liveuser |
343 |
#設置連線編碼失敗的提示
|
|
|
344 |
$result["error"][]="設置連線編碼失敗.";
|
| 226 |
liveuser |
345 |
|
| 3 |
liveuser |
346 |
#取得連線時的錯誤編號
|
|
|
347 |
$result["error"][]=mysqli_connect_errno();
|
| 226 |
liveuser |
348 |
|
| 3 |
liveuser |
349 |
#取得連線時的錯誤訊息
|
|
|
350 |
$result["error"][]=mysqli_connect_error();
|
| 226 |
liveuser |
351 |
|
| 3 |
liveuser |
352 |
#設置執行失敗
|
|
|
353 |
$result["status"]="false";
|
| 226 |
liveuser |
354 |
|
| 3 |
liveuser |
355 |
#回傳結果
|
|
|
356 |
return $result;
|
| 226 |
liveuser |
357 |
|
| 3 |
liveuser |
358 |
}#if end
|
| 226 |
liveuser |
359 |
|
| 3 |
liveuser |
360 |
#設定 CHARACTER_SET_CLIENT 為 utf8
|
|
|
361 |
if(!(mysqli_query($result["connectInformation"],'SET CHARACTER_SET_CLIENT=utf8'))){
|
| 226 |
liveuser |
362 |
|
| 3 |
liveuser |
363 |
#設置連線編碼失敗的提示
|
|
|
364 |
$result["error"][]="設置連線編碼失敗.";
|
| 226 |
liveuser |
365 |
|
| 3 |
liveuser |
366 |
#取得連線時的錯誤編號
|
|
|
367 |
$result["error"][]=mysqli_connect_errno();
|
| 226 |
liveuser |
368 |
|
| 3 |
liveuser |
369 |
#取得連線時的錯誤訊息
|
|
|
370 |
$result["error"][]=mysqli_connect_error();
|
| 226 |
liveuser |
371 |
|
| 3 |
liveuser |
372 |
#設置執行失敗
|
|
|
373 |
$result["status"]="false";
|
| 226 |
liveuser |
374 |
|
| 3 |
liveuser |
375 |
#回傳結果
|
|
|
376 |
return $result;
|
| 226 |
liveuser |
377 |
|
| 3 |
liveuser |
378 |
}#if end
|
| 226 |
liveuser |
379 |
|
| 3 |
liveuser |
380 |
#設定 CHARACTER_SET_RESULTS 為 utf8
|
|
|
381 |
if(!(mysqli_query($result["connectInformation"],'SET CHARACTER_SET_RESULTS=utf8'))){
|
| 226 |
liveuser |
382 |
|
| 3 |
liveuser |
383 |
#設置連線編碼失敗的提示
|
|
|
384 |
$result["error"][]="設置連線編碼失敗.";
|
| 226 |
liveuser |
385 |
|
| 3 |
liveuser |
386 |
#取得連線時的錯誤編號
|
|
|
387 |
$result["error"][]=mysqli_connect_errno();
|
| 226 |
liveuser |
388 |
|
| 3 |
liveuser |
389 |
#取得連線時的錯誤訊息
|
|
|
390 |
$result["error"][]=mysqli_connect_error();
|
| 226 |
liveuser |
391 |
|
| 3 |
liveuser |
392 |
#設置執行失敗
|
|
|
393 |
$result["status"]="false";
|
| 226 |
liveuser |
394 |
|
| 3 |
liveuser |
395 |
#回傳結果
|
|
|
396 |
return $result;
|
| 226 |
liveuser |
397 |
|
| 3 |
liveuser |
398 |
}#if end
|
| 226 |
liveuser |
399 |
|
| 3 |
liveuser |
400 |
#執行正常
|
|
|
401 |
$result["status"]="true";
|
|
|
402 |
|
|
|
403 |
#回傳結果
|
| 226 |
liveuser |
404 |
return $result;
|
| 3 |
liveuser |
405 |
|
|
|
406 |
}#function mysqlConnect end
|
|
|
407 |
|
|
|
408 |
/*
|
|
|
409 |
#函式說明:
|
|
|
410 |
#關閉與mysql的連線,會回傳一個陣列。
|
|
|
411 |
#回傳結果::
|
|
|
412 |
#$result["status"],若連線成功則爲"true",連線失敗則爲"false".
|
|
|
413 |
#$result["connectInformation"],爲回傳的mysql連線資訊。
|
| 226 |
liveuser |
414 |
#$result["error"],爲錯誤訊息陣列.
|
| 3 |
liveuser |
415 |
#必填參數:
|
|
|
416 |
#$conf["mysqli"],字串,mysqli物件.
|
|
|
417 |
$conf["mysqli"]=$mysqli;
|
|
|
418 |
#可省略參數:
|
|
|
419 |
#無.
|
|
|
420 |
#參考資料:
|
|
|
421 |
#無.
|
|
|
422 |
#備註:
|
|
|
423 |
#無.
|
| 226 |
liveuser |
424 |
*/
|
| 3 |
liveuser |
425 |
public static function mysqlClose(&$conf){
|
| 226 |
liveuser |
426 |
|
| 3 |
liveuser |
427 |
#初始化要回傳的內容
|
|
|
428 |
$result=array();
|
|
|
429 |
|
|
|
430 |
#取得當前執行的函數名稱
|
|
|
431 |
$result["function"]=__FUNCTION__;
|
|
|
432 |
|
|
|
433 |
#如果 $conf 不為陣列
|
|
|
434 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
435 |
|
| 3 |
liveuser |
436 |
#設置執行失敗
|
|
|
437 |
$result["status"]="false";
|
| 226 |
liveuser |
438 |
|
| 3 |
liveuser |
439 |
#設置執行錯誤訊息
|
|
|
440 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
441 |
|
|
|
442 |
#如果傳入的參數為 null
|
|
|
443 |
if($conf==null){
|
| 226 |
liveuser |
444 |
|
| 3 |
liveuser |
445 |
#設置執行錯誤訊息
|
|
|
446 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
447 |
|
| 3 |
liveuser |
448 |
}#if end
|
|
|
449 |
|
|
|
450 |
#回傳結果
|
|
|
451 |
return $result;
|
| 226 |
liveuser |
452 |
|
| 3 |
liveuser |
453 |
}#if end
|
| 226 |
liveuser |
454 |
|
| 3 |
liveuser |
455 |
#檢查參數
|
|
|
456 |
#函式說明:
|
|
|
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"],字串陣列,多餘的參數名稱.
|
|
|
468 |
#必填參數:
|
|
|
469 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
470 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
471 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
472 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("mysqli");
|
| 226 |
liveuser |
473 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
474 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array(null);
|
|
|
475 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
476 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
477 |
#可省略參數:
|
|
|
478 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
479 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
480 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
481 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort");
|
| 226 |
liveuser |
482 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
483 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
484 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
485 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null);
|
|
|
486 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
487 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
488 |
#參考資料:
|
|
|
489 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
490 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
491 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
492 |
|
| 3 |
liveuser |
493 |
#如果檢查失敗
|
|
|
494 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
495 |
|
| 3 |
liveuser |
496 |
#設置錯誤識別
|
|
|
497 |
$result["status"]="false";
|
| 226 |
liveuser |
498 |
|
| 3 |
liveuser |
499 |
#設置錯誤訊息
|
|
|
500 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
501 |
|
| 3 |
liveuser |
502 |
#回傳解果
|
|
|
503 |
return $result;
|
| 226 |
liveuser |
504 |
|
| 3 |
liveuser |
505 |
}#if end
|
|
|
506 |
|
|
|
507 |
#如果 $checkResult["status"]等於"false";
|
|
|
508 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
509 |
|
| 3 |
liveuser |
510 |
#設置錯誤識別
|
|
|
511 |
$result["status"]="false";
|
| 226 |
liveuser |
512 |
|
| 3 |
liveuser |
513 |
#設置錯誤訊息
|
|
|
514 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
515 |
|
| 3 |
liveuser |
516 |
#回傳解果
|
|
|
517 |
return $result;
|
| 226 |
liveuser |
518 |
|
| 3 |
liveuser |
519 |
}#if end
|
|
|
520 |
|
|
|
521 |
#關閉與資料庫的連線如果成功
|
|
|
522 |
if(@mysqli_close($conf["mysqli"])){
|
| 226 |
liveuser |
523 |
|
| 3 |
liveuser |
524 |
#則回傳"true"
|
|
|
525 |
$result["status"]="true";
|
|
|
526 |
|
|
|
527 |
}#if end
|
|
|
528 |
|
|
|
529 |
#連線失敗回傳"false"
|
|
|
530 |
else{
|
| 226 |
liveuser |
531 |
|
| 3 |
liveuser |
532 |
#設置連線編碼失敗的提示
|
|
|
533 |
$result["error"][]="關閉連線失敗.";
|
| 226 |
liveuser |
534 |
|
| 3 |
liveuser |
535 |
#取得連線時的錯誤編號
|
|
|
536 |
$result["error"][]=mysqli_connect_errno();
|
| 226 |
liveuser |
537 |
|
| 3 |
liveuser |
538 |
#取得連線時的錯誤訊息
|
|
|
539 |
$result["error"][]=mysqli_connect_error();
|
| 226 |
liveuser |
540 |
|
| 3 |
liveuser |
541 |
#設置執行失敗
|
|
|
542 |
$result["status"]="false";
|
|
|
543 |
|
|
|
544 |
}#else end
|
|
|
545 |
|
|
|
546 |
#儲存mysqli物件
|
|
|
547 |
$result["connectInformation"]=$conf["mysqli"];
|
|
|
548 |
|
|
|
549 |
#設置執行正常
|
|
|
550 |
$result["status"]="true";
|
|
|
551 |
|
|
|
552 |
#回傳結果
|
| 226 |
liveuser |
553 |
return $result;
|
| 3 |
liveuser |
554 |
|
|
|
555 |
}#funciton mysqlClose end
|
|
|
556 |
|
|
|
557 |
/*
|
|
|
558 |
#函式說明:
|
|
|
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"]="";
|
|
|
571 |
#可省略參數:
|
|
|
572 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
|
|
|
573 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
574 |
#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
|
|
|
575 |
#$conf["dbPort"]="3306";
|
|
|
576 |
#參考資料:
|
|
|
577 |
#無.
|
|
|
578 |
#備註:
|
|
|
579 |
#無.
|
|
|
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"){
|
| 226 |
liveuser |
591 |
|
| 3 |
liveuser |
592 |
#設置執行失敗
|
|
|
593 |
$result["status"]="false";
|
| 226 |
liveuser |
594 |
|
| 3 |
liveuser |
595 |
#設置執行錯誤訊息
|
|
|
596 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
597 |
|
|
|
598 |
#如果傳入的參數為 null
|
|
|
599 |
if($conf==null){
|
| 226 |
liveuser |
600 |
|
| 3 |
liveuser |
601 |
#設置執行錯誤訊息
|
|
|
602 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
603 |
|
| 3 |
liveuser |
604 |
}#if end
|
|
|
605 |
|
|
|
606 |
#回傳結果
|
|
|
607 |
return $result;
|
| 226 |
liveuser |
608 |
|
| 3 |
liveuser |
609 |
}#if end
|
|
|
610 |
|
|
|
611 |
#檢查參數
|
|
|
612 |
#函式說明:
|
|
|
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"],字串陣列,多餘的參數名稱.
|
|
|
624 |
#必填參數:
|
|
|
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");
|
| 226 |
liveuser |
629 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
630 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
631 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
632 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
633 |
#可省略參數:
|
|
|
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");
|
| 226 |
liveuser |
638 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
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();
|
|
|
644 |
#參考資料:
|
|
|
645 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
646 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
647 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
648 |
|
| 3 |
liveuser |
649 |
#如果檢查失敗
|
| 177 |
liveuser |
650 |
if($checkResult["status"]==="false"){
|
| 226 |
liveuser |
651 |
|
| 3 |
liveuser |
652 |
#設置錯誤識別
|
|
|
653 |
$result["status"]="false";
|
| 226 |
liveuser |
654 |
|
| 3 |
liveuser |
655 |
#設置錯誤訊息
|
|
|
656 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
657 |
|
| 3 |
liveuser |
658 |
#回傳解果
|
|
|
659 |
return $result;
|
| 226 |
liveuser |
660 |
|
| 3 |
liveuser |
661 |
}#if end
|
|
|
662 |
|
|
|
663 |
#如果 $checkResult["status"]等於"false";
|
| 177 |
liveuser |
664 |
if($checkResult["passed"]==="false"){
|
| 226 |
liveuser |
665 |
|
| 3 |
liveuser |
666 |
#設置錯誤識別
|
|
|
667 |
$result["status"]="false";
|
| 226 |
liveuser |
668 |
|
| 3 |
liveuser |
669 |
#設置錯誤訊息
|
|
|
670 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
671 |
|
| 3 |
liveuser |
672 |
#回傳解果
|
|
|
673 |
return $result;
|
| 226 |
liveuser |
674 |
|
| 3 |
liveuser |
675 |
}#if end
|
|
|
676 |
|
|
|
677 |
#函式說明:
|
|
|
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時要使用的帳號。
|
|
|
687 |
#可省略參數:
|
| 226 |
liveuser |
688 |
|
| 3 |
liveuser |
689 |
#如果 $conf["dbPassword"] 有設定
|
|
|
690 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
691 |
|
| 3 |
liveuser |
692 |
$conf["db"]["mysqlConnect"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
|
| 226 |
liveuser |
693 |
|
| 3 |
liveuser |
694 |
}#if end
|
| 226 |
liveuser |
695 |
|
| 3 |
liveuser |
696 |
#如果有設置 $conf["dbPort"]
|
|
|
697 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
698 |
|
| 3 |
liveuser |
699 |
$conf["db"]["mysqlConnect"]["dbPort"]=$conf["dbPort"];#字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
|
| 226 |
liveuser |
700 |
|
| 177 |
liveuser |
701 |
}#if end
|
| 226 |
liveuser |
702 |
|
| 3 |
liveuser |
703 |
$con=db::mysqlConnect($conf["db"]["mysqlConnect"]);
|
|
|
704 |
unset($conf["db"]["mysqlConnect"]);
|
|
|
705 |
|
|
|
706 |
#如果連線失敗
|
| 177 |
liveuser |
707 |
if($con["status"]==="false"){
|
| 226 |
liveuser |
708 |
|
| 3 |
liveuser |
709 |
#提示訊息
|
|
|
710 |
$result["error"]=$con;
|
|
|
711 |
|
|
|
712 |
#設置執行失敗
|
|
|
713 |
$result["status"]="false";
|
| 226 |
liveuser |
714 |
|
| 3 |
liveuser |
715 |
#回傳結果
|
|
|
716 |
return $result;
|
| 226 |
liveuser |
717 |
|
| 3 |
liveuser |
718 |
}#if end
|
|
|
719 |
|
| 177 |
liveuser |
720 |
#確認資料庫存在或可以被存取
|
|
|
721 |
#函式說明:
|
|
|
722 |
#執行mysql指令
|
|
|
723 |
#回傳結果::
|
|
|
724 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
725 |
#$result["error"],錯誤訊息的陣列
|
|
|
726 |
#$result["function"],當前執行的涵式
|
|
|
727 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
| 226 |
liveuser |
728 |
#$result["queryConn"],mysql用來查尋的連資源.
|
| 177 |
liveuser |
729 |
#$result["queryString"],要執行的sql內容.
|
|
|
730 |
#必填參數:
|
|
|
731 |
#$conf["dbSql"],字串,要執行sql語法
|
|
|
732 |
$conf["db::execMysqlQuery"]["dbSql"]="show databases;";
|
|
|
733 |
#可省略參數:
|
|
|
734 |
#$conf["dbLink"],物件,mysqli物件,由mysqli_connect()回傳的物件內容,若為數值則改用賬號密碼等資訊進行連線,反之則沿用連線物件.
|
|
|
735 |
#$conf["db::execMysqlQuery"]["dbLink"]=$conf["dbName"];
|
|
|
736 |
#$conf["dbAddress"],字串,爲mysql-Server的位置。
|
|
|
737 |
$conf["db::execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];
|
|
|
738 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號。
|
| 226 |
liveuser |
739 |
$conf["db::execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];
|
|
|
740 |
|
| 177 |
liveuser |
741 |
#如果存在 $dbPassword
|
|
|
742 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
743 |
|
| 177 |
liveuser |
744 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
|
|
|
745 |
$conf["db::execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];
|
| 226 |
liveuser |
746 |
|
| 177 |
liveuser |
747 |
}#if end
|
| 226 |
liveuser |
748 |
|
| 177 |
liveuser |
749 |
#$conf["dbName"],字串,爲要連的資料庫名稱
|
|
|
750 |
#$conf["dbName"]="";
|
| 226 |
liveuser |
751 |
|
| 177 |
liveuser |
752 |
#如果存在 $dbPort
|
|
|
753 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
754 |
|
| 177 |
liveuser |
755 |
#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
|
|
|
756 |
$conf["db::execMysqlQuery"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
757 |
|
| 177 |
liveuser |
758 |
}#if end
|
| 226 |
liveuser |
759 |
|
| 177 |
liveuser |
760 |
#$conf["autoClose"],字串,"true"代表要自動斷線,預設為"true"會自動斷線
|
|
|
761 |
#$conf["autoClose"]="true";
|
|
|
762 |
#參考資料:
|
|
|
763 |
#無.
|
|
|
764 |
#備註:
|
|
|
765 |
#無.
|
|
|
766 |
$execMysqlQuery=db::execMysqlQuery($conf["db::execMysqlQuery"]);
|
|
|
767 |
unset($conf["db::execMysqlQuery"]);
|
|
|
768 |
|
|
|
769 |
#如果執行失敗
|
|
|
770 |
if($execMysqlQuery["status"]==="false"){
|
| 226 |
liveuser |
771 |
|
| 177 |
liveuser |
772 |
#設置連線失敗的提示
|
|
|
773 |
$result["error"][]="檢查資料庫可否存取出錯";
|
| 226 |
liveuser |
774 |
|
| 177 |
liveuser |
775 |
#設置錯誤訊息
|
|
|
776 |
$result["error"][]=$execMysqlQuery["error"];
|
| 226 |
liveuser |
777 |
|
| 177 |
liveuser |
778 |
#設置執行失敗
|
|
|
779 |
$result["status"]="false";
|
| 226 |
liveuser |
780 |
|
| 177 |
liveuser |
781 |
#回傳結果
|
|
|
782 |
return $result;
|
| 226 |
liveuser |
783 |
|
| 177 |
liveuser |
784 |
}#if end
|
| 226 |
liveuser |
785 |
|
| 177 |
liveuser |
786 |
#解析 $execMysqlQuery["queryResource"] 看是否存在要存取的資料庫
|
|
|
787 |
#函式說明:
|
|
|
788 |
#解析 dataTableSelect($conf) 後的結果,亦即將執行sql語法後所得到的結果解析放進變數裏面
|
|
|
789 |
#回傳結果:
|
|
|
790 |
#$result["status"],執行結果"true"為成功;"false"為失敗
|
|
|
791 |
#$result["error"],錯誤訊息
|
|
|
792 |
#$result["function"],儲存當前函數名稱
|
|
|
793 |
#$result["dataColumnName"],為資料欄位的名稱陣列.
|
|
|
794 |
#$result["dataColumnName"][$i]代表第一個欄位名稱.
|
|
|
795 |
#$result["dataContent"],爲資料的內容陣列,第1維度的key為$conf["tableValueName"][$i],亦即第 $i+1 個欄位的名稱,若該欄位不存在,則其value為空字串;第2維度的key為第$i+1筆資料的索引.
|
|
|
796 |
#$result["dataCount"],爲取得的資料筆數.
|
|
|
797 |
#必填參數:
|
|
|
798 |
#$conf["sqlQueryResult"],object,爲執行sql語法所獲得的查詢結果。
|
|
|
799 |
$conf["db::sendQueryDataToVariabele"]["sqlQueryResult"]=$execMysqlQuery["queryResource"];
|
|
|
800 |
#$conf["tableValueName"],字串陣列,爲該資料表列項目的每一項名稱,須爲陣列值,若為「array("*")」則代表所有欄位.
|
|
|
801 |
$conf["db::sendQueryDataToVariabele"]["tableValueName"]=array("Database");
|
|
|
802 |
#可省略參數:
|
|
|
803 |
#$conf["dbAddress"],字串,爲mysql-Server的位置,目前沒有用途.
|
|
|
804 |
#$conf["dbAddress"]=$dbAddress;
|
|
|
805 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號,目前沒有用途.
|
|
|
806 |
#$conf["dbAccount"]=$dbAccount;
|
|
|
807 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼,目前沒有用途.
|
|
|
808 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
809 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port,目前沒有用途.
|
|
|
810 |
#$conf["dbPort"]="";
|
|
|
811 |
#$conf["valueName"],字串陣列,爲該資料表列項目的每一項所要對應的變數名稱,預設為欄位的名稱($conf["tableValueName"]).
|
|
|
812 |
#$conf["valueName"]=$conf["tableValueName"];
|
|
|
813 |
#參考資料:
|
|
|
814 |
#http://www.w3school.com.cn/php/func_mysql_fetch_array.asp => 解析取得的資料表欄位時,能夠選擇回傳含有欄位名稱與數字代表的key.
|
|
|
815 |
#備註:
|
|
|
816 |
#無.
|
|
|
817 |
$sendQueryDataToVariabele=db::sendQueryDataToVariabele($conf["db::sendQueryDataToVariabele"]);
|
|
|
818 |
unset($conf["db::sendQueryDataToVariabele"]);
|
|
|
819 |
|
|
|
820 |
#如果執行異常
|
|
|
821 |
if($sendQueryDataToVariabele["status"]==="false"){
|
| 226 |
liveuser |
822 |
|
| 177 |
liveuser |
823 |
#設置連線失敗的提示
|
|
|
824 |
$result["error"][]="檢查資料庫可否存取出錯";
|
| 226 |
liveuser |
825 |
|
| 177 |
liveuser |
826 |
#設置錯誤訊息
|
|
|
827 |
$result["error"][]=$sendQueryDataToVariabele["error"];
|
| 226 |
liveuser |
828 |
|
| 177 |
liveuser |
829 |
#設置執行失敗
|
|
|
830 |
$result["status"]="false";
|
| 226 |
liveuser |
831 |
|
| 177 |
liveuser |
832 |
#回傳結果
|
|
|
833 |
return $result;
|
| 226 |
liveuser |
834 |
|
| 177 |
liveuser |
835 |
}#if end
|
| 226 |
liveuser |
836 |
|
| 177 |
liveuser |
837 |
#檢查資料庫是否可以存取
|
|
|
838 |
#函式說明:
|
|
|
839 |
#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
|
|
|
840 |
#回傳結果:
|
|
|
841 |
#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
|
|
|
842 |
#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
|
|
|
843 |
#$result["error"],錯誤訊息
|
|
|
844 |
#$result["function"],當前執行的函數名稱
|
|
|
845 |
#$result["argv"],使用的參數
|
|
|
846 |
#$result["equalVarName"],相等的變數名稱或key.
|
|
|
847 |
#$result["equalVarValue"],相等的變數數值內容.
|
|
|
848 |
#必填參數:
|
|
|
849 |
#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
|
|
|
850 |
$conf["search::getEqualVar"]["conditionElement"]=$conf["dbName"];
|
|
|
851 |
#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
|
|
|
852 |
$conf["search::getEqualVar"]["compareElements"]=$sendQueryDataToVariabele["dataContent"]["Database"];
|
|
|
853 |
#可省略參數:
|
|
|
854 |
#無.
|
|
|
855 |
#參考資料:
|
|
|
856 |
#無.
|
|
|
857 |
#備註:
|
|
|
858 |
#無.
|
|
|
859 |
$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
|
|
|
860 |
unset($conf["search::getEqualVar"]);
|
| 226 |
liveuser |
861 |
|
| 177 |
liveuser |
862 |
#如果執行失敗
|
|
|
863 |
if($getEqualVar["status"]==="false"){
|
| 226 |
liveuser |
864 |
|
| 177 |
liveuser |
865 |
#設置錯誤的提示
|
|
|
866 |
$result["error"][]="檢查資料庫可否存取出錯";
|
| 226 |
liveuser |
867 |
|
| 177 |
liveuser |
868 |
#設置錯誤訊息
|
|
|
869 |
$result["error"][]=$sendQueryDataToVariabele["error"];
|
| 226 |
liveuser |
870 |
|
| 177 |
liveuser |
871 |
#設置執行失敗
|
|
|
872 |
$result["status"]="false";
|
| 226 |
liveuser |
873 |
|
| 177 |
liveuser |
874 |
#回傳結果
|
|
|
875 |
return $result;
|
| 226 |
liveuser |
876 |
|
| 177 |
liveuser |
877 |
}#if end
|
| 226 |
liveuser |
878 |
|
| 177 |
liveuser |
879 |
#如果無法存取資料庫
|
|
|
880 |
if($getEqualVar["founded"]==="false"){
|
| 226 |
liveuser |
881 |
|
| 177 |
liveuser |
882 |
#設置錯誤的提示
|
|
|
883 |
$result["error"][]="資料庫(".$conf["dbName"].")無法存取";
|
| 226 |
liveuser |
884 |
|
| 177 |
liveuser |
885 |
#設置錯誤訊息
|
|
|
886 |
$result["error"][]=$sendQueryDataToVariabele;
|
| 226 |
liveuser |
887 |
|
| 177 |
liveuser |
888 |
#設置執行失敗
|
|
|
889 |
$result["status"]="false";
|
| 226 |
liveuser |
890 |
|
| 177 |
liveuser |
891 |
#回傳結果
|
|
|
892 |
return $result;
|
| 226 |
liveuser |
893 |
|
| 177 |
liveuser |
894 |
}#if end
|
|
|
895 |
|
| 3 |
liveuser |
896 |
#選取資料庫
|
|
|
897 |
#如果連線失敗
|
|
|
898 |
if(!(mysqli_select_db($con["connectInformation"],$conf["dbName"]))){
|
|
|
899 |
|
|
|
900 |
#設置連線失敗的提示
|
|
|
901 |
$result["error"][]="選取資料庫失敗";
|
| 226 |
liveuser |
902 |
|
| 3 |
liveuser |
903 |
#取得連線時的錯誤編號
|
|
|
904 |
$result["error"][]=mysqli_connect_errno();
|
| 226 |
liveuser |
905 |
|
| 3 |
liveuser |
906 |
#取得連線時的錯誤訊息
|
|
|
907 |
$result["error"][]=mysqli_connect_error();
|
| 226 |
liveuser |
908 |
|
| 3 |
liveuser |
909 |
#設置執行失敗
|
|
|
910 |
$result["status"]="false";
|
| 226 |
liveuser |
911 |
|
| 3 |
liveuser |
912 |
#回傳結果
|
| 177 |
liveuser |
913 |
return $result;
|
| 3 |
liveuser |
914 |
|
|
|
915 |
}#if end
|
|
|
916 |
|
|
|
917 |
#取得mysqli物件
|
|
|
918 |
$result["connectInformation"]=$con["connectInformation"];
|
|
|
919 |
|
|
|
920 |
#設置執行正常
|
|
|
921 |
$result["status"]="true";
|
|
|
922 |
|
|
|
923 |
#回傳結果
|
| 226 |
liveuser |
924 |
return $result;
|
| 3 |
liveuser |
925 |
|
|
|
926 |
}#function dbConnect end
|
|
|
927 |
|
|
|
928 |
/*
|
|
|
929 |
#函式說明:
|
|
|
930 |
#執行mysql指令
|
|
|
931 |
#回傳結果::
|
|
|
932 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
933 |
#$result["error"],錯誤訊息的陣列
|
|
|
934 |
#$result["function"],當前執行的涵式
|
|
|
935 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
| 226 |
liveuser |
936 |
#$result["queryConn"],mysql用來查尋的連資源.
|
| 3 |
liveuser |
937 |
#$result["queryString"],要執行的sql內容.
|
|
|
938 |
#必填參數:
|
|
|
939 |
#$conf["dbSql"],字串,要執行sql語法
|
|
|
940 |
$conf["dbSql"]="";
|
|
|
941 |
#可省略參數:
|
|
|
942 |
#$conf["dbLink"],物件,mysqli物件,由mysqli_connect()回傳的物件內容,若為數值則改用賬號密碼等資訊進行連線,反之則沿用連線物件.
|
|
|
943 |
$conf["dbLink"]="";
|
|
|
944 |
#$conf["dbAddress"],字串,爲mysql-Server的位置。
|
|
|
945 |
$conf["dbAddress"]=$dbAddress;
|
|
|
946 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號。
|
| 226 |
liveuser |
947 |
$conf["dbAccount"]=$dbAccount;
|
| 3 |
liveuser |
948 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
|
|
|
949 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
950 |
#$conf["dbName"],字串,爲要連的資料庫名稱
|
|
|
951 |
#$conf["dbName"]="";
|
|
|
952 |
#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
|
|
|
953 |
#$conf["dbPort"]="3306";
|
|
|
954 |
#$conf["autoClose"],字串,"true"代表要自動斷線,預設為"true"會自動斷線
|
|
|
955 |
#$conf["autoClose"]="true";
|
|
|
956 |
#參考資料:
|
|
|
957 |
#無.
|
|
|
958 |
#備註:
|
|
|
959 |
#無.
|
|
|
960 |
*/
|
|
|
961 |
public static function execMysqlQuery(&$conf){
|
| 226 |
liveuser |
962 |
|
| 3 |
liveuser |
963 |
#初始化要回傳的內容
|
|
|
964 |
$result=array();
|
|
|
965 |
|
|
|
966 |
#取得當前執行的函數名稱
|
|
|
967 |
$result["function"]=__FUNCTION__;
|
|
|
968 |
|
|
|
969 |
#如果 $conf 不為陣列
|
|
|
970 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
971 |
|
| 3 |
liveuser |
972 |
#設置執行失敗
|
|
|
973 |
$result["status"]="false";
|
| 226 |
liveuser |
974 |
|
| 3 |
liveuser |
975 |
#設置執行錯誤訊息
|
|
|
976 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
977 |
|
|
|
978 |
#如果傳入的參數為 null
|
|
|
979 |
if($conf===null){
|
| 226 |
liveuser |
980 |
|
| 3 |
liveuser |
981 |
#設置執行錯誤訊息
|
|
|
982 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
983 |
|
| 3 |
liveuser |
984 |
}#if end
|
|
|
985 |
|
|
|
986 |
#回傳結果
|
|
|
987 |
return $result;
|
| 226 |
liveuser |
988 |
|
| 3 |
liveuser |
989 |
}#if end
|
|
|
990 |
|
|
|
991 |
#檢查參數
|
|
|
992 |
#函式說明:
|
|
|
993 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
994 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
995 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
996 |
#$result["function"],當前執行的函式名稱.
|
|
|
997 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
998 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
999 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1000 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1001 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1002 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1003 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1004 |
#必填參數:
|
|
|
1005 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1006 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1007 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1008 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbSql");
|
| 226 |
liveuser |
1009 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1010 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
1011 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1012 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1013 |
#可省略參數:
|
|
|
1014 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
1015 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1016 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1017 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbLink","dbAddress","dbAccount","dbPassword","dbName","dbPort","autoClose","mysqli");
|
| 226 |
liveuser |
1018 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1019 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("object","string","string","string","string","string","string",null);
|
|
|
1020 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
1021 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null,null,null,"true",null);
|
|
|
1022 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1023 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1024 |
#參考資料:
|
|
|
1025 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1026 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1027 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1028 |
|
| 3 |
liveuser |
1029 |
#如果檢查失敗
|
|
|
1030 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1031 |
|
| 3 |
liveuser |
1032 |
#設置錯誤識別
|
|
|
1033 |
$result["status"]="fasle";
|
| 226 |
liveuser |
1034 |
|
| 3 |
liveuser |
1035 |
#設置錯誤訊息
|
|
|
1036 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1037 |
|
| 3 |
liveuser |
1038 |
#回傳解果
|
|
|
1039 |
return $result;
|
| 226 |
liveuser |
1040 |
|
| 3 |
liveuser |
1041 |
}#if end
|
|
|
1042 |
|
|
|
1043 |
#如果 $checkResult["status"]等於"false";
|
|
|
1044 |
if($checkResult["passed"]==="false"){
|
| 226 |
liveuser |
1045 |
|
| 3 |
liveuser |
1046 |
#設置錯誤識別
|
| 177 |
liveuser |
1047 |
$result["status"]="false";
|
| 226 |
liveuser |
1048 |
|
| 3 |
liveuser |
1049 |
#設置錯誤訊息
|
|
|
1050 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1051 |
|
| 3 |
liveuser |
1052 |
#回傳解果
|
|
|
1053 |
return $result;
|
| 226 |
liveuser |
1054 |
|
| 3 |
liveuser |
1055 |
}#if end
|
| 226 |
liveuser |
1056 |
|
| 3 |
liveuser |
1057 |
#如果沒有 dbLink
|
|
|
1058 |
if(!isset($conf["dbLink"])){
|
| 226 |
liveuser |
1059 |
|
| 3 |
liveuser |
1060 |
#初始化儲存mysqli物件的變數
|
|
|
1061 |
$con="";
|
| 226 |
liveuser |
1062 |
|
| 3 |
liveuser |
1063 |
#如果有指定資料庫
|
|
|
1064 |
if(isset($conf["dbName"])){
|
| 226 |
liveuser |
1065 |
|
| 3 |
liveuser |
1066 |
#函式說明:
|
|
|
1067 |
#連線到資料庫,結果會回傳一個陣列.
|
|
|
1068 |
#$result["status"],若連線成功則爲"true",連線失敗則爲"false".
|
|
|
1069 |
#$result["connectInformation"],爲回傳的mysql連線資訊.
|
|
|
1070 |
#$result["error"],錯誤訊息 .
|
|
|
1071 |
#$result["function"],當前執行的函數名稱.
|
|
|
1072 |
#必填參數:
|
|
|
1073 |
$conf["db::dbConnect"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
1074 |
$conf["db::dbConnect"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
1075 |
$conf["db::dbConnect"]["dbName"]=$conf["dbName"];#爲要連的資料庫名稱
|
|
|
1076 |
#可省略參數:
|
| 226 |
liveuser |
1077 |
|
| 3 |
liveuser |
1078 |
#如果 $conf["dbPassword"] 有設置
|
|
|
1079 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
1080 |
|
| 3 |
liveuser |
1081 |
$conf["db::dbConnect"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
|
| 226 |
liveuser |
1082 |
|
| 3 |
liveuser |
1083 |
}#if end
|
| 226 |
liveuser |
1084 |
|
|
|
1085 |
#如果有設置 $conf["dbPort"]
|
| 3 |
liveuser |
1086 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
1087 |
|
| 3 |
liveuser |
1088 |
#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
|
|
|
1089 |
$conf["db::dbConnect"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
1090 |
|
| 3 |
liveuser |
1091 |
}#if end
|
| 226 |
liveuser |
1092 |
|
| 3 |
liveuser |
1093 |
$con=db::dbConnect($conf["db::dbConnect"]);
|
|
|
1094 |
unset($conf["db::dbConnect"]);
|
| 226 |
liveuser |
1095 |
|
| 3 |
liveuser |
1096 |
#如果連線失敗
|
|
|
1097 |
if($con["status"]=="false"){
|
| 226 |
liveuser |
1098 |
|
| 3 |
liveuser |
1099 |
#設置執行失敗的訊息
|
|
|
1100 |
$result["status"]="false";
|
| 226 |
liveuser |
1101 |
|
| 3 |
liveuser |
1102 |
#紀錄錯誤訊息
|
|
|
1103 |
$result["error"]=$con;
|
| 226 |
liveuser |
1104 |
|
| 3 |
liveuser |
1105 |
#回傳結果
|
|
|
1106 |
return $result;
|
| 226 |
liveuser |
1107 |
|
| 3 |
liveuser |
1108 |
}#if end
|
| 226 |
liveuser |
1109 |
|
| 3 |
liveuser |
1110 |
#儲存mysqli物件
|
|
|
1111 |
$result["queryConn"]=$con["connectInformation"];
|
| 226 |
liveuser |
1112 |
|
| 177 |
liveuser |
1113 |
#解析可以取得的資料庫清單
|
|
|
1114 |
#函式說明:
|
|
|
1115 |
#解析 dataTableSelect($conf) 後的結果,亦即將執行sql語法後所得到的結果解析放進變數裏面
|
|
|
1116 |
#回傳結果:
|
|
|
1117 |
#$result["status"],執行結果"true"為成功;"false"為失敗
|
|
|
1118 |
#$result["error"],錯誤訊息
|
|
|
1119 |
#$result["function"],儲存當前函數名稱
|
|
|
1120 |
#$result["dataColumnName"],為資料欄位的名稱陣列.
|
|
|
1121 |
#$result["dataColumnName"][$i]代表第一個欄位名稱.
|
|
|
1122 |
#$result["dataContent"],爲資料的內容陣列,第1維度的key為$conf["tableValueName"][$i],亦即第 $i+1 個欄位的名稱,若該欄位不存在,則其value為空字串;第2維度的key為第$i+1筆資料的索引.
|
|
|
1123 |
#$result["dataCount"],爲取得的資料筆數.
|
|
|
1124 |
#必填參數:
|
|
|
1125 |
#$conf["sqlQueryResult"],object,爲執行sql語法所獲得的查詢結果。
|
|
|
1126 |
$conf["db::sendQueryDataToVariabele"]["sqlQueryResult"]=$result["queryConn"];
|
|
|
1127 |
#$conf["tableValueName"],字串陣列,爲該資料表列項目的每一項名稱,須爲陣列值,若為「array("*")」則代表所有欄位.
|
|
|
1128 |
$conf["db::sendQueryDataToVariabele"]["tableValueName"]=array("Database");
|
|
|
1129 |
#可省略參數:
|
|
|
1130 |
#$conf["dbAddress"],字串,爲mysql-Server的位置,目前沒有用途.
|
|
|
1131 |
$conf["db::sendQueryDataToVariabele"]["dbAddress"]=$dbAddress;
|
|
|
1132 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號,目前沒有用途.
|
|
|
1133 |
$conf["db::sendQueryDataToVariabele"]["dbAccount"]=$dbAccount;
|
| 226 |
liveuser |
1134 |
|
| 177 |
liveuser |
1135 |
#如果有設置 $conf["dbPassword"]
|
|
|
1136 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
1137 |
|
| 177 |
liveuser |
1138 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼,目前沒有用途.
|
|
|
1139 |
$conf["db::sendQueryDataToVariabele"]["dbPassword"]=$dbPassword;
|
| 226 |
liveuser |
1140 |
|
| 177 |
liveuser |
1141 |
}#if end
|
| 226 |
liveuser |
1142 |
|
| 177 |
liveuser |
1143 |
#如果有設置 $conf["dbPort"]
|
|
|
1144 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
1145 |
|
| 177 |
liveuser |
1146 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port,目前沒有用途.
|
|
|
1147 |
$conf["db::sendQueryDataToVariabele"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
1148 |
|
| 177 |
liveuser |
1149 |
}#if end
|
| 226 |
liveuser |
1150 |
|
| 177 |
liveuser |
1151 |
#$conf["valueName"],字串陣列,爲該資料表列項目的每一項所要對應的變數名稱,預設為欄位的名稱($conf["tableValueName"]).
|
|
|
1152 |
#$conf["valueName"]=$conf["tableValueName"];
|
|
|
1153 |
#參考資料:
|
|
|
1154 |
#http://www.w3school.com.cn/php/func_mysql_fetch_array.asp => 解析取得的資料表欄位時,能夠選擇回傳含有欄位名稱與數字代表的key.
|
|
|
1155 |
#備註:
|
|
|
1156 |
#無.
|
|
|
1157 |
$sendQueryDataToVariabele=db::sendQueryDataToVariabele($conf["db::sendQueryDataToVariabele"]);
|
|
|
1158 |
unset($conf["db::sendQueryDataToVariabele"]);
|
| 226 |
liveuser |
1159 |
|
| 177 |
liveuser |
1160 |
#如果連線失敗
|
|
|
1161 |
if($sendQueryDataToVariabele["status"]==="false"){
|
| 226 |
liveuser |
1162 |
|
| 177 |
liveuser |
1163 |
#設置執行失敗的訊息
|
|
|
1164 |
$result["status"]="false";
|
| 226 |
liveuser |
1165 |
|
| 177 |
liveuser |
1166 |
#紀錄錯誤訊息
|
|
|
1167 |
$result["error"]=$sendQueryDataToVariabele;
|
| 226 |
liveuser |
1168 |
|
| 177 |
liveuser |
1169 |
#回傳結果
|
|
|
1170 |
return $result;
|
| 226 |
liveuser |
1171 |
|
| 177 |
liveuser |
1172 |
}#if end
|
| 226 |
liveuser |
1173 |
|
| 177 |
liveuser |
1174 |
#尋找目標資料庫是否存在
|
|
|
1175 |
#函式說明:
|
|
|
1176 |
#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
|
|
|
1177 |
#回傳結果:
|
|
|
1178 |
#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
|
|
|
1179 |
#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
|
|
|
1180 |
#$result["error"],錯誤訊息
|
|
|
1181 |
#$result["function"],當前執行的函數名稱
|
|
|
1182 |
#$result["argv"],使用的參數
|
|
|
1183 |
#$result["equalVarName"],相等的變數名稱或key.
|
|
|
1184 |
#$result["equalVarValue"],相等的變數數值內容.
|
|
|
1185 |
#必填參數:
|
|
|
1186 |
#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
|
|
|
1187 |
$conf["search::getEqualVar"]["conditionElement"]=$conf["dbName"];
|
|
|
1188 |
#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
|
|
|
1189 |
$conf["search::getEqualVar"]["compareElements"]=$result["dataContent"]["Database"];
|
|
|
1190 |
#可省略參數:
|
|
|
1191 |
#無.
|
|
|
1192 |
#參考資料:
|
|
|
1193 |
#無.
|
|
|
1194 |
#備註:
|
|
|
1195 |
#無.
|
|
|
1196 |
$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
|
|
|
1197 |
unset($conf["search::getEqualVar"]);
|
| 226 |
liveuser |
1198 |
|
| 177 |
liveuser |
1199 |
#如果連線失敗
|
|
|
1200 |
if($getEqualVar["status"]==="false"){
|
| 226 |
liveuser |
1201 |
|
| 177 |
liveuser |
1202 |
#設置執行失敗的訊息
|
|
|
1203 |
$result["status"]="false";
|
| 226 |
liveuser |
1204 |
|
| 177 |
liveuser |
1205 |
#紀錄錯誤訊息
|
|
|
1206 |
$result["error"]=$getEqualVar;
|
| 226 |
liveuser |
1207 |
|
| 177 |
liveuser |
1208 |
#回傳結果
|
|
|
1209 |
return $result;
|
| 226 |
liveuser |
1210 |
|
| 177 |
liveuser |
1211 |
}#if end
|
| 226 |
liveuser |
1212 |
|
| 177 |
liveuser |
1213 |
#如果不存在
|
|
|
1214 |
if($getEqualVar["founded"]==="false"){
|
| 226 |
liveuser |
1215 |
|
| 177 |
liveuser |
1216 |
#設置執行失敗的訊息
|
|
|
1217 |
$result["status"]="false";
|
| 226 |
liveuser |
1218 |
|
| 177 |
liveuser |
1219 |
#紀錄錯誤訊息
|
|
|
1220 |
$result["error"][]="目標資料庫 ".$conf["dbName"]." 不存在";
|
| 226 |
liveuser |
1221 |
|
| 177 |
liveuser |
1222 |
#紀錄錯誤訊息
|
|
|
1223 |
$result["error"][]=$getEqualVar;
|
| 226 |
liveuser |
1224 |
|
| 177 |
liveuser |
1225 |
#回傳結果
|
|
|
1226 |
return $result;
|
| 226 |
liveuser |
1227 |
|
| 177 |
liveuser |
1228 |
}#if end
|
| 226 |
liveuser |
1229 |
|
| 3 |
liveuser |
1230 |
}#if end
|
| 226 |
liveuser |
1231 |
|
| 177 |
liveuser |
1232 |
#反之沒有指定資料庫
|
| 3 |
liveuser |
1233 |
else{
|
| 226 |
liveuser |
1234 |
|
| 3 |
liveuser |
1235 |
#連線到mysql
|
|
|
1236 |
#函式說明:
|
|
|
1237 |
#連線到mysql-server,會回傳一個陣列
|
|
|
1238 |
#回傳結果:
|
|
|
1239 |
#$result["connectStatus"],若連線成功則爲0,連線失敗則爲1。
|
|
|
1240 |
#$result["connectInformation"],爲回傳的mysql連線資訊。
|
|
|
1241 |
#$result["error"],爲錯誤訊息
|
|
|
1242 |
#必填參數:
|
|
|
1243 |
$conf["db"]["mysqlConnect"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置。
|
|
|
1244 |
$conf["db"]["mysqlConnect"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號。
|
|
|
1245 |
#可省略參數:
|
| 226 |
liveuser |
1246 |
|
| 3 |
liveuser |
1247 |
#如果 $conf["dbPassword"] 有設置
|
|
|
1248 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
1249 |
|
| 3 |
liveuser |
1250 |
$conf["db"]["mysqlConnect"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
|
| 226 |
liveuser |
1251 |
|
| 3 |
liveuser |
1252 |
}#if end
|
| 226 |
liveuser |
1253 |
|
|
|
1254 |
#如果有設置 $conf["dbPort"]
|
| 3 |
liveuser |
1255 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
1256 |
|
| 3 |
liveuser |
1257 |
#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
|
|
|
1258 |
$conf["db::dbConnect"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
1259 |
|
| 3 |
liveuser |
1260 |
}#if end
|
| 226 |
liveuser |
1261 |
|
| 3 |
liveuser |
1262 |
$con=db::mysqlConnect($conf["db"]["mysqlConnect"]);
|
|
|
1263 |
unset($conf["db"]);
|
| 226 |
liveuser |
1264 |
|
| 3 |
liveuser |
1265 |
#如果連線失敗
|
| 170 |
liveuser |
1266 |
if($con["status"]==="false"){
|
| 226 |
liveuser |
1267 |
|
| 3 |
liveuser |
1268 |
#設置執行失敗的訊息
|
|
|
1269 |
$result["status"]="false";
|
| 226 |
liveuser |
1270 |
|
| 3 |
liveuser |
1271 |
#紀錄錯誤訊息
|
|
|
1272 |
$result["error"]=$con;
|
| 226 |
liveuser |
1273 |
|
| 3 |
liveuser |
1274 |
#回傳結果
|
|
|
1275 |
return $result;
|
| 226 |
liveuser |
1276 |
|
| 3 |
liveuser |
1277 |
}#if end
|
| 226 |
liveuser |
1278 |
|
| 170 |
liveuser |
1279 |
#debug
|
| 177 |
liveuser |
1280 |
#var_dump(__LINE__,$con);
|
| 226 |
liveuser |
1281 |
|
| 3 |
liveuser |
1282 |
#儲存mysqli物件
|
| 170 |
liveuser |
1283 |
$result["queryConn"]=$con["connectInformation"];
|
| 226 |
liveuser |
1284 |
|
| 3 |
liveuser |
1285 |
}#else end
|
| 226 |
liveuser |
1286 |
|
| 3 |
liveuser |
1287 |
}#if end
|
| 226 |
liveuser |
1288 |
|
| 3 |
liveuser |
1289 |
#反之存在 $conf["dbLink"]
|
|
|
1290 |
else{
|
| 226 |
liveuser |
1291 |
|
| 3 |
liveuser |
1292 |
#取得db物件
|
|
|
1293 |
$result["queryConn"]=$conf["dbLink"];
|
| 226 |
liveuser |
1294 |
|
| 3 |
liveuser |
1295 |
}#else end
|
| 226 |
liveuser |
1296 |
|
| 3 |
liveuser |
1297 |
#設置sql的查詢語言
|
|
|
1298 |
$result["queryStringOri"]=$conf["dbSql"];
|
| 226 |
liveuser |
1299 |
|
| 3 |
liveuser |
1300 |
#設置sql的查詢語言
|
|
|
1301 |
$result["queryString"]=$conf["dbSql"];
|
| 226 |
liveuser |
1302 |
|
| 177 |
liveuser |
1303 |
#debug
|
|
|
1304 |
#var_dump(__LINE__,$result["queryString"]);
|
| 226 |
liveuser |
1305 |
|
| 3 |
liveuser |
1306 |
#進行查詢
|
|
|
1307 |
#如果有錯誤訊息
|
|
|
1308 |
if(!($mysqli_query=mysqli_query($result["queryConn"],$result["queryString"]))){
|
| 226 |
liveuser |
1309 |
|
| 3 |
liveuser |
1310 |
#設置執行失敗的訊息
|
|
|
1311 |
$result["status"]="false";
|
| 226 |
liveuser |
1312 |
|
| 3 |
liveuser |
1313 |
#設置提示執行mysql語法失敗
|
|
|
1314 |
$result["error"][]="執行mysql語法失敗";
|
| 226 |
liveuser |
1315 |
|
| 3 |
liveuser |
1316 |
#取得錯誤訊息
|
|
|
1317 |
$result["error"]["mysqlErrorNo"]=mysqli_errno($result["queryConn"]);
|
|
|
1318 |
$result["error"]["mysqlErrorDetail"]=mysqli_error($result["queryConn"]);
|
| 226 |
liveuser |
1319 |
|
| 3 |
liveuser |
1320 |
#回傳結果
|
|
|
1321 |
return $result;
|
| 226 |
liveuser |
1322 |
|
| 3 |
liveuser |
1323 |
}#if end
|
| 226 |
liveuser |
1324 |
|
| 3 |
liveuser |
1325 |
#取得正確的mysqli_resource
|
|
|
1326 |
$result["queryResource"]=$mysqli_query;
|
| 226 |
liveuser |
1327 |
|
| 3 |
liveuser |
1328 |
#如果要自動斷線
|
|
|
1329 |
if($conf["autoClose"]==="true"){
|
| 226 |
liveuser |
1330 |
|
| 3 |
liveuser |
1331 |
#連線結束
|
|
|
1332 |
#函式說明:
|
|
|
1333 |
#關閉與mysql的連線,會回傳一個陣列。
|
|
|
1334 |
#回傳結果::
|
|
|
1335 |
#$result["status"],若連線成功則爲"true",連線失敗則爲"false".
|
|
|
1336 |
#$result["connectInformation"],爲回傳的mysql連線資訊。
|
| 226 |
liveuser |
1337 |
#$result["error"],爲錯誤訊息陣列.
|
| 3 |
liveuser |
1338 |
#必填參數:
|
|
|
1339 |
#$conf["mysqli"],字串,mysqli物件.
|
|
|
1340 |
$conf["db::mysqlClose"]["mysqli"]=$result["queryConn"];
|
|
|
1341 |
$mysqlClose=db::mysqlClose($conf["db::mysqlClose"]);
|
|
|
1342 |
unset($conf["db::mysqlClose"]);
|
| 226 |
liveuser |
1343 |
|
| 3 |
liveuser |
1344 |
#如果關閉mysql連線失敗
|
|
|
1345 |
if($mysqlClose["status"]=="false"){
|
| 226 |
liveuser |
1346 |
|
| 3 |
liveuser |
1347 |
#設置執行失敗的訊息
|
|
|
1348 |
$result["status"]="false";
|
| 226 |
liveuser |
1349 |
|
| 3 |
liveuser |
1350 |
#紀錄錯誤訊息
|
|
|
1351 |
$result["error"]=$mysqlClose;
|
| 226 |
liveuser |
1352 |
|
| 3 |
liveuser |
1353 |
#回傳結果
|
|
|
1354 |
return $result;
|
| 226 |
liveuser |
1355 |
|
| 3 |
liveuser |
1356 |
}#if end
|
| 226 |
liveuser |
1357 |
|
| 3 |
liveuser |
1358 |
}#if end
|
| 226 |
liveuser |
1359 |
|
| 3 |
liveuser |
1360 |
#設置執行成功的訊息
|
| 177 |
liveuser |
1361 |
$result["status"]="true";
|
| 226 |
liveuser |
1362 |
|
| 3 |
liveuser |
1363 |
#回傳查詢後的結果
|
|
|
1364 |
return $result;
|
| 226 |
liveuser |
1365 |
|
| 3 |
liveuser |
1366 |
}#function execMysqlQuery end
|
|
|
1367 |
|
|
|
1368 |
/*
|
|
|
1369 |
#函式說明:
|
|
|
1370 |
#用shell執行mysql指令.
|
|
|
1371 |
#回傳結果::
|
|
|
1372 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
1373 |
#$result["error"],錯誤訊息的陣列
|
|
|
1374 |
#$result["function"],當前執行的涵式
|
|
|
1375 |
#$result["queryString"],mysql查詢的語言.
|
|
|
1376 |
#必填參數:
|
|
|
1377 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
1378 |
$conf["fileArgu"]=__FILE__;
|
|
|
1379 |
#$conf["dbSql"],字串,要執行sql語法
|
| 226 |
liveuser |
1380 |
$conf["dbSql"]="";
|
| 3 |
liveuser |
1381 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號。
|
| 226 |
liveuser |
1382 |
$conf["dbAccount"]=$dbAccount;
|
| 3 |
liveuser |
1383 |
#可省略參數:
|
| 183 |
liveuser |
1384 |
#$conf["dbAddress"],字串,爲mysql-Server的位置,若設置為"localhost",則會忽略,預設為不指定,會嘗試透過unix domain socket來存取資料庫.
|
|
|
1385 |
#$conf["dbAddress"]=$dbAddress;
|
| 3 |
liveuser |
1386 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
1387 |
#$conf["pre"]=array();
|
|
|
1388 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
|
|
|
1389 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
1390 |
#$conf["dbName"],字串,爲要連的資料庫名稱
|
|
|
1391 |
#$conf["dbName"]="";
|
|
|
1392 |
#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
|
|
|
1393 |
#$conf["dbPort"]="3306";
|
|
|
1394 |
#參考資料:
|
|
|
1395 |
#無.
|
|
|
1396 |
#備註:
|
|
|
1397 |
#無.
|
|
|
1398 |
*/
|
|
|
1399 |
public static function shell(&$conf){
|
| 226 |
liveuser |
1400 |
|
| 3 |
liveuser |
1401 |
#初始化要回傳的內容
|
|
|
1402 |
$result=array();
|
|
|
1403 |
|
|
|
1404 |
#取得當前執行的函數名稱
|
|
|
1405 |
$result["function"]=__FUNCTION__;
|
|
|
1406 |
|
|
|
1407 |
#如果 $conf 不為陣列
|
|
|
1408 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1409 |
|
| 3 |
liveuser |
1410 |
#設置執行失敗
|
|
|
1411 |
$result["status"]="false";
|
| 226 |
liveuser |
1412 |
|
| 3 |
liveuser |
1413 |
#設置執行錯誤訊息
|
|
|
1414 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1415 |
|
|
|
1416 |
#如果傳入的參數為 null
|
|
|
1417 |
if($conf===null){
|
| 226 |
liveuser |
1418 |
|
| 3 |
liveuser |
1419 |
#設置執行錯誤訊息
|
|
|
1420 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1421 |
|
| 3 |
liveuser |
1422 |
}#if end
|
|
|
1423 |
|
|
|
1424 |
#回傳結果
|
|
|
1425 |
return $result;
|
| 226 |
liveuser |
1426 |
|
| 3 |
liveuser |
1427 |
}#if end
|
|
|
1428 |
|
|
|
1429 |
#檢查參數
|
|
|
1430 |
#函式說明:
|
|
|
1431 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
1432 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1433 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
1434 |
#$result["function"],當前執行的函式名稱.
|
|
|
1435 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1436 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1437 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1438 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
1439 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
1440 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
1441 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
1442 |
#必填參數:
|
|
|
1443 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
1444 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
1445 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
1446 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("fileArgu","dbSql","dbAccount");
|
| 226 |
liveuser |
1447 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1448 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
1449 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
1450 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
1451 |
#可省略參數:
|
|
|
1452 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
1453 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
1454 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
1455 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("pre","dbAddress","dbPassword","dbName","dbPort");
|
| 226 |
liveuser |
1456 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
1457 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("array","string","string","string","string");
|
|
|
1458 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 183 |
liveuser |
1459 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null,"3306");
|
| 3 |
liveuser |
1460 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
1461 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
1462 |
#參考資料:
|
|
|
1463 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
1464 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
1465 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
1466 |
|
| 3 |
liveuser |
1467 |
#如果檢查失敗
|
|
|
1468 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1469 |
|
| 3 |
liveuser |
1470 |
#設置錯誤識別
|
|
|
1471 |
$result["status"]="false";
|
| 226 |
liveuser |
1472 |
|
| 3 |
liveuser |
1473 |
#設置錯誤訊息
|
|
|
1474 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1475 |
|
| 3 |
liveuser |
1476 |
#回傳解果
|
|
|
1477 |
return $result;
|
| 226 |
liveuser |
1478 |
|
| 3 |
liveuser |
1479 |
}#if end
|
|
|
1480 |
|
|
|
1481 |
#如果 $checkResult["status"]等於"false";
|
|
|
1482 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1483 |
|
| 3 |
liveuser |
1484 |
#設置錯誤識別
|
|
|
1485 |
$result["status"]="false";
|
| 226 |
liveuser |
1486 |
|
| 3 |
liveuser |
1487 |
#設置錯誤訊息
|
|
|
1488 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1489 |
|
| 3 |
liveuser |
1490 |
#回傳解果
|
|
|
1491 |
return $result;
|
| 226 |
liveuser |
1492 |
|
| 3 |
liveuser |
1493 |
}#if end
|
| 226 |
liveuser |
1494 |
|
| 3 |
liveuser |
1495 |
#避免亂碼
|
| 183 |
liveuser |
1496 |
$sql="SET NAMES UTF8;"."SET CHARACTER_SET_CLIENT=utf8;"."SET CHARACTER_SET_RESULTS=utf8;".$conf["dbSql"];
|
| 226 |
liveuser |
1497 |
|
| 3 |
liveuser |
1498 |
#初始化參數
|
|
|
1499 |
$argu=array();
|
| 226 |
liveuser |
1500 |
|
| 3 |
liveuser |
1501 |
#精簡的參數
|
|
|
1502 |
$argu[]=$sql;
|
|
|
1503 |
$argu[]="|";
|
|
|
1504 |
$argu[]="mysql";
|
|
|
1505 |
$argu[]="-u";
|
| 183 |
liveuser |
1506 |
$argu[]=$conf["dbAccount"];
|
| 226 |
liveuser |
1507 |
|
| 3 |
liveuser |
1508 |
#如果有設置 $conf["dbPassword"]
|
|
|
1509 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
1510 |
|
| 3 |
liveuser |
1511 |
#加上密碼參數
|
|
|
1512 |
$argu[]="-p".$conf["dbPassword"];
|
| 226 |
liveuser |
1513 |
|
| 3 |
liveuser |
1514 |
}#if end
|
| 226 |
liveuser |
1515 |
|
| 183 |
liveuser |
1516 |
#如果有指定 dbAddress
|
|
|
1517 |
if(isset($conf["dbAddress"])){
|
| 226 |
liveuser |
1518 |
|
| 183 |
liveuser |
1519 |
#如果不為 localhost
|
|
|
1520 |
if($conf["dbAddress"]!=="localhost"){
|
| 226 |
liveuser |
1521 |
|
| 183 |
liveuser |
1522 |
#加上 位置參數
|
|
|
1523 |
$argu[]="-h".$conf["dbAddress"];
|
| 226 |
liveuser |
1524 |
|
| 183 |
liveuser |
1525 |
}#if end
|
| 226 |
liveuser |
1526 |
|
| 183 |
liveuser |
1527 |
}#if end
|
| 226 |
liveuser |
1528 |
|
| 3 |
liveuser |
1529 |
#如果有設置 $conf["dbName"]
|
|
|
1530 |
if(isset($conf["dbName"])){
|
| 226 |
liveuser |
1531 |
|
| 3 |
liveuser |
1532 |
#加上資料庫名稱參數
|
|
|
1533 |
$argu[]=$conf["dbName"];
|
| 226 |
liveuser |
1534 |
|
| 3 |
liveuser |
1535 |
}#if end
|
| 226 |
liveuser |
1536 |
|
| 3 |
liveuser |
1537 |
#函式說明:
|
|
|
1538 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
1539 |
#回傳結果:
|
|
|
1540 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
1541 |
#$result["error"],錯誤訊息陣列.
|
|
|
1542 |
#$result["function"],當前執行的函數名稱.
|
|
|
1543 |
#$result["argu"],使用的參數.
|
|
|
1544 |
#$result["cmd"],執行的指令內容.
|
|
|
1545 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
1546 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
1547 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
1548 |
#$result["running"],是否還在執行.
|
|
|
1549 |
#$result["pid"],pid.
|
|
|
1550 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
1551 |
#必填的參數
|
|
|
1552 |
#$conf["command"],字串,要執行的指令與.
|
|
|
1553 |
$conf["external::callShell"]["command"]="echo";
|
|
|
1554 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
| 183 |
liveuser |
1555 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
| 3 |
liveuser |
1556 |
#可省略參數:
|
|
|
1557 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
1558 |
$conf["external::callShell"]["argu"]=$argu;
|
|
|
1559 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
| 226 |
liveuser |
1560 |
#$conf["arguIsAddr"]=array();
|
|
|
1561 |
|
| 3 |
liveuser |
1562 |
#如果有參數
|
|
|
1563 |
if(count($argu)>0){
|
| 226 |
liveuser |
1564 |
|
| 3 |
liveuser |
1565 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
1566 |
$conf["external::callShell"]["thereIsShellVar"]=array();
|
| 226 |
liveuser |
1567 |
|
| 3 |
liveuser |
1568 |
#針對每個參數
|
|
|
1569 |
for($i=0;$i<count($argu);$i++){
|
| 226 |
liveuser |
1570 |
|
| 3 |
liveuser |
1571 |
#第一個參數
|
|
|
1572 |
if($i===0){
|
| 226 |
liveuser |
1573 |
|
| 3 |
liveuser |
1574 |
#含有shell變數
|
|
|
1575 |
$conf["external::callShell"]["thereIsShellVar"][$i]="true";
|
| 226 |
liveuser |
1576 |
|
| 3 |
liveuser |
1577 |
}#if end
|
| 226 |
liveuser |
1578 |
|
| 3 |
liveuser |
1579 |
#反之
|
|
|
1580 |
else{
|
| 226 |
liveuser |
1581 |
|
| 3 |
liveuser |
1582 |
#不含有shell變數
|
|
|
1583 |
$conf["external::callShell"]["thereIsShellVar"][$i]="false";
|
| 226 |
liveuser |
1584 |
|
|
|
1585 |
}#else
|
|
|
1586 |
|
| 3 |
liveuser |
1587 |
}#for end
|
| 226 |
liveuser |
1588 |
|
| 3 |
liveuser |
1589 |
}#if end
|
| 226 |
liveuser |
1590 |
|
| 3 |
liveuser |
1591 |
#如果有設置 pre
|
|
|
1592 |
if(isset($conf["pre"])){
|
| 226 |
liveuser |
1593 |
|
| 3 |
liveuser |
1594 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
1595 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
1596 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
1597 |
$conf["external::callShell"]["pre"]=$conf["pre"];
|
| 226 |
liveuser |
1598 |
|
| 3 |
liveuser |
1599 |
}#if end
|
| 226 |
liveuser |
1600 |
|
| 3 |
liveuser |
1601 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
1602 |
#$conf["enablePrintDescription"]="true";
|
|
|
1603 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
1604 |
#$conf["printDescription"]="";
|
|
|
1605 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
1606 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
1607 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
1608 |
#$conf["username"]="";
|
|
|
1609 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
1610 |
#$conf["password"]="";
|
|
|
1611 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
1612 |
#$conf["useScript"]="";
|
|
|
1613 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
1614 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
1615 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
1616 |
#$conf["inBackGround"]="";
|
|
|
1617 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
1618 |
#$conf["getErr"]="false";
|
|
|
1619 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
1620 |
$conf["external::callShell"]["doNotRun"]="true";
|
|
|
1621 |
#備註:
|
|
|
1622 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
1623 |
#參考資料:
|
|
|
1624 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
1625 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
1626 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
1627 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
1628 |
unset($conf["external::callShell"]);
|
|
|
1629 |
|
|
|
1630 |
#debug
|
| 183 |
liveuser |
1631 |
#var_dump(__LINE__,$callShell);
|
| 3 |
liveuser |
1632 |
|
|
|
1633 |
#如果檢查參數作業出錯
|
|
|
1634 |
if($callShell["status"]=="false"){
|
| 226 |
liveuser |
1635 |
|
| 3 |
liveuser |
1636 |
#設置執行錯誤識別
|
|
|
1637 |
$result["status"]="false";
|
| 226 |
liveuser |
1638 |
|
| 3 |
liveuser |
1639 |
#設置錯誤訊息
|
|
|
1640 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
1641 |
|
| 3 |
liveuser |
1642 |
#回傳結果
|
|
|
1643 |
return $result;
|
| 226 |
liveuser |
1644 |
|
| 3 |
liveuser |
1645 |
}#if end
|
| 226 |
liveuser |
1646 |
|
| 3 |
liveuser |
1647 |
#函式說明:
|
|
|
1648 |
#連線到 unixDomainSockServer 提供的 unix domain socket.
|
|
|
1649 |
#回傳結果:
|
|
|
1650 |
#$result["status"],"true"代表執行正常;"false"代表執行不正常.
|
|
|
1651 |
#$result["error"],錯誤訊息陣列.
|
|
|
1652 |
#$result["function"],當前執行的函式名稱.
|
|
|
1653 |
#$result["content"],取得的回應.
|
|
|
1654 |
#必填參數:
|
|
|
1655 |
#$conf["sock"],字串,要連線的unix domain socket.
|
|
|
1656 |
$conf["sock::unixDomainSockClient"]["sock"]=qbpwcf_usock_path;
|
|
|
1657 |
#可省略參數:
|
|
|
1658 |
#$conf["id"],字串,取得的id,若無此值,則會得到新的數值.
|
|
|
1659 |
#$conf["id"]="";
|
|
|
1660 |
#$conf["cmd"],字串,要執行的指令,當$conf["id"]參數合法時,才會執行.
|
|
|
1661 |
$conf["sock::unixDomainSockClient"]["cmd"]=$callShell["escape"]["cmd"];
|
|
|
1662 |
#$conf["param"],參數陣列.
|
|
|
1663 |
$conf["sock::unixDomainSockClient"]["param"]=$callShell["escape"]["argu"];
|
|
|
1664 |
#$conf["escaped"],字串,param參數是否已經escaped了,預設為"false",反之為"true".
|
|
|
1665 |
$conf["sock::unixDomainSockClient"]["escaped"]="true";
|
|
|
1666 |
#$conf["clear"],字串,設為"true"代表要清除過期的用戶連線.
|
|
|
1667 |
#$conf["clear"]="true";
|
|
|
1668 |
#參考資料:
|
|
|
1669 |
#http://php.net/manual/en/function.stream-socket-client.php
|
|
|
1670 |
#http://php.net/manual/en/function.stream-get-contents.php
|
|
|
1671 |
#備註:
|
|
|
1672 |
#無.
|
|
|
1673 |
$paramsOfUnixDomainSockClient=$conf["sock::unixDomainSockClient"];
|
|
|
1674 |
$unixDomainSockClient=sock::unixDomainSockClient($conf["sock::unixDomainSockClient"]);
|
|
|
1675 |
unset($conf["sock::unixDomainSockClient"]);
|
| 226 |
liveuser |
1676 |
|
| 3 |
liveuser |
1677 |
#如果執行失敗
|
|
|
1678 |
if($unixDomainSockClient["status"]==="false"){
|
| 226 |
liveuser |
1679 |
|
| 3 |
liveuser |
1680 |
#設置執行錯誤識別
|
|
|
1681 |
$result["status"]="false";
|
| 226 |
liveuser |
1682 |
|
| 3 |
liveuser |
1683 |
#設置錯誤訊息
|
|
|
1684 |
$result["error"]=$unixDomainSockClient;
|
| 226 |
liveuser |
1685 |
|
| 3 |
liveuser |
1686 |
#回傳結果
|
|
|
1687 |
return $result;
|
| 226 |
liveuser |
1688 |
|
| 3 |
liveuser |
1689 |
}#if end
|
| 226 |
liveuser |
1690 |
|
| 3 |
liveuser |
1691 |
#取得json回應
|
|
|
1692 |
$jsonRes=json_decode($unixDomainSockClient["content"]);
|
| 226 |
liveuser |
1693 |
|
| 3 |
liveuser |
1694 |
#如果執行失敗
|
|
|
1695 |
if($jsonRes===null){
|
| 226 |
liveuser |
1696 |
|
| 3 |
liveuser |
1697 |
#設置執行錯誤識別
|
|
|
1698 |
$result["status"]="false";
|
| 226 |
liveuser |
1699 |
|
| 3 |
liveuser |
1700 |
#設置錯誤訊息
|
|
|
1701 |
$result["error"]=$unixDomainSockClient;
|
| 226 |
liveuser |
1702 |
|
| 3 |
liveuser |
1703 |
#回傳結果
|
|
|
1704 |
return $result;
|
| 226 |
liveuser |
1705 |
|
| 3 |
liveuser |
1706 |
}#if end
|
| 226 |
liveuser |
1707 |
|
| 3 |
liveuser |
1708 |
#如果沒有產生新id
|
|
|
1709 |
if(!isset($jsonRes->id)){
|
| 226 |
liveuser |
1710 |
|
| 3 |
liveuser |
1711 |
#設置執行錯誤識別
|
|
|
1712 |
$result["status"]="false";
|
| 226 |
liveuser |
1713 |
|
| 3 |
liveuser |
1714 |
#設置錯誤訊息
|
|
|
1715 |
$result["error"]=$unixDomainSockClient;
|
| 226 |
liveuser |
1716 |
|
| 3 |
liveuser |
1717 |
#回傳結果
|
|
|
1718 |
return $result;
|
| 226 |
liveuser |
1719 |
|
| 3 |
liveuser |
1720 |
}#if end
|
| 226 |
liveuser |
1721 |
|
| 3 |
liveuser |
1722 |
#用新的id再傳送一次要求給 qbpwcf_usock_path
|
| 183 |
liveuser |
1723 |
$paramsOfUnixDomainSockClient["id"]=$jsonRes->id;
|
| 3 |
liveuser |
1724 |
$unixDomainSockClient=sock::unixDomainSockClient($paramsOfUnixDomainSockClient);
|
|
|
1725 |
unset($paramsOfUnixDomainSockClient);
|
| 226 |
liveuser |
1726 |
|
| 3 |
liveuser |
1727 |
#var_dump($unixDomainSockClient);
|
| 226 |
liveuser |
1728 |
|
| 3 |
liveuser |
1729 |
#如果執行失敗
|
|
|
1730 |
if($unixDomainSockClient["status"]==="false"){
|
| 226 |
liveuser |
1731 |
|
| 3 |
liveuser |
1732 |
#設置執行錯誤識別
|
|
|
1733 |
$result["status"]="false";
|
| 226 |
liveuser |
1734 |
|
| 3 |
liveuser |
1735 |
#設置錯誤訊息
|
|
|
1736 |
$result["error"]=$unixDomainSockClient;
|
| 226 |
liveuser |
1737 |
|
| 3 |
liveuser |
1738 |
#回傳結果
|
|
|
1739 |
return $result;
|
| 226 |
liveuser |
1740 |
|
| 3 |
liveuser |
1741 |
}#if end
|
| 226 |
liveuser |
1742 |
|
| 3 |
liveuser |
1743 |
#執行正常
|
|
|
1744 |
$result["status"]="true";
|
| 226 |
liveuser |
1745 |
|
| 3 |
liveuser |
1746 |
#設置執行的結果
|
|
|
1747 |
$result["content"]=$unixDomainSockClient;
|
| 226 |
liveuser |
1748 |
|
| 3 |
liveuser |
1749 |
#回傳結果
|
|
|
1750 |
return $result;
|
| 226 |
liveuser |
1751 |
|
| 3 |
liveuser |
1752 |
}#function shell end
|
|
|
1753 |
|
|
|
1754 |
/*
|
|
|
1755 |
#函式說明:
|
|
|
1756 |
#建立資料庫,會回傳一個陣列。
|
|
|
1757 |
#回傳結果:
|
|
|
1758 |
#$result["status"],成功爲"true",失敗爲"false".
|
|
|
1759 |
#$result["error"],錯誤訊息.
|
|
|
1760 |
#$result["function"],當前執行的函數名稱.
|
|
|
1761 |
#必填參數:
|
|
|
1762 |
#$conf["dbAddress"],字串,爲mysql-Server的位置。
|
|
|
1763 |
$conf["dbAddress"]=$dbAddress;
|
|
|
1764 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號。
|
|
|
1765 |
$conf["dbAccount"]=$dbAccount;
|
|
|
1766 |
#$conf["newDatabaseName"],字串,爲要新增的資料庫名稱.
|
|
|
1767 |
$conf["newDatabaseName"]="";
|
| 226 |
liveuser |
1768 |
#可省略參數:
|
| 3 |
liveuser |
1769 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
|
|
|
1770 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
1771 |
#$conf["dbName"],字串,爲要連的資料庫名稱
|
|
|
1772 |
#$conf["dbName"]="";
|
| 177 |
liveuser |
1773 |
#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,預設為3306.
|
|
|
1774 |
#$conf["dbPort"]="3306";
|
| 3 |
liveuser |
1775 |
#參考資料:
|
|
|
1776 |
#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/
|
|
|
1777 |
#備註:
|
|
|
1778 |
#無.
|
|
|
1779 |
*/
|
|
|
1780 |
public static function createDatabase($conf){
|
|
|
1781 |
|
| 226 |
liveuser |
1782 |
#初始化錯誤訊息
|
| 3 |
liveuser |
1783 |
$result=array();
|
|
|
1784 |
|
|
|
1785 |
#取得當前執行的函數名稱
|
|
|
1786 |
$result["function"]=__FUNCTION__;
|
|
|
1787 |
|
|
|
1788 |
#如果 $conf 不為陣列
|
|
|
1789 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1790 |
|
| 3 |
liveuser |
1791 |
#設置執行失敗
|
|
|
1792 |
$result["status"]="false";
|
| 226 |
liveuser |
1793 |
|
| 3 |
liveuser |
1794 |
#設置執行錯誤訊息
|
|
|
1795 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1796 |
|
|
|
1797 |
#如果傳入的參數為 null
|
|
|
1798 |
if($conf==null){
|
| 226 |
liveuser |
1799 |
|
| 3 |
liveuser |
1800 |
#設置執行錯誤訊息
|
|
|
1801 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1802 |
|
| 3 |
liveuser |
1803 |
}#if end
|
|
|
1804 |
|
|
|
1805 |
#回傳結果
|
|
|
1806 |
return $result;
|
| 226 |
liveuser |
1807 |
|
| 3 |
liveuser |
1808 |
}#if end
|
|
|
1809 |
|
|
|
1810 |
#檢查參數
|
|
|
1811 |
#函式說明:
|
|
|
1812 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
1813 |
#回傳結果:
|
|
|
1814 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1815 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1816 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1817 |
#必填參數:
|
|
|
1818 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
| 177 |
liveuser |
1819 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbPassword","newDatabaseName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
| 3 |
liveuser |
1820 |
#可省略參數:
|
| 226 |
liveuser |
1821 |
$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
1822 |
#$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
1823 |
#備註:
|
|
|
1824 |
#功能與checkExistAndType函式相同
|
|
|
1825 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
1826 |
unset($conf["variableCheck"]["isexistMuti"]);
|
|
|
1827 |
|
|
|
1828 |
#如果 $checkResult["passed"] 等於 "fasle"
|
|
|
1829 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
1830 |
|
| 3 |
liveuser |
1831 |
#設置錯誤識別
|
|
|
1832 |
$result["status"]="false";
|
| 226 |
liveuser |
1833 |
|
| 3 |
liveuser |
1834 |
#設置錯誤訊息
|
|
|
1835 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1836 |
|
| 3 |
liveuser |
1837 |
#回傳結果
|
|
|
1838 |
return $result;
|
| 226 |
liveuser |
1839 |
|
| 3 |
liveuser |
1840 |
}#if end
|
|
|
1841 |
|
|
|
1842 |
#建立資料庫的sql語法
|
|
|
1843 |
$sql="CREATE DATABASE ".$conf["newDatabaseName"]." CHARACTER SET='utf8' COLLATE='utf8_unicode_ci'";
|
|
|
1844 |
|
|
|
1845 |
#函式說明:
|
|
|
1846 |
#執行mysql指令
|
|
|
1847 |
#回傳結果::
|
|
|
1848 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
1849 |
#$result["error"],錯誤訊息的陣列
|
|
|
1850 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
1851 |
#$result["queryString"],mysql查詢的語言
|
|
|
1852 |
#查詢號的解果,需要解析。
|
|
|
1853 |
#必填參數:
|
|
|
1854 |
$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
1855 |
$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
1856 |
$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
|
| 226 |
liveuser |
1857 |
#可省略參數:
|
|
|
1858 |
|
| 3 |
liveuser |
1859 |
#如果 $conf["dbPassword"] 有設定
|
|
|
1860 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
1861 |
|
| 3 |
liveuser |
1862 |
$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
1863 |
|
| 3 |
liveuser |
1864 |
}#if end
|
| 226 |
liveuser |
1865 |
|
| 3 |
liveuser |
1866 |
#如果 $conf["dbPort"] 有設定
|
|
|
1867 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
1868 |
|
| 3 |
liveuser |
1869 |
#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
|
|
|
1870 |
$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
1871 |
|
| 3 |
liveuser |
1872 |
}#if end
|
| 226 |
liveuser |
1873 |
|
| 3 |
liveuser |
1874 |
$db["execMysqlQuery"]=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
|
|
|
1875 |
unset($conf["db"]["execMysqlQuery"]);
|
|
|
1876 |
|
|
|
1877 |
#如果 $db["execMysqlQuery"]["status"] 等於 "false"
|
|
|
1878 |
if($db["execMysqlQuery"]["status"]=="false"){
|
| 226 |
liveuser |
1879 |
|
| 3 |
liveuser |
1880 |
#設置錯誤識別
|
|
|
1881 |
$result["status"]="false";
|
| 226 |
liveuser |
1882 |
|
| 3 |
liveuser |
1883 |
#設置錯誤訊息
|
|
|
1884 |
$result["error"]=$db["execMysqlQuery"];
|
| 226 |
liveuser |
1885 |
|
| 3 |
liveuser |
1886 |
#回傳結果
|
|
|
1887 |
return $result;
|
| 226 |
liveuser |
1888 |
|
| 3 |
liveuser |
1889 |
}#if end
|
|
|
1890 |
|
|
|
1891 |
#執行道這邊代表執行正確
|
|
|
1892 |
$result["status"]="true";
|
|
|
1893 |
|
|
|
1894 |
#回傳結果
|
|
|
1895 |
return $result;
|
| 226 |
liveuser |
1896 |
|
| 3 |
liveuser |
1897 |
}#function createDatabase end
|
|
|
1898 |
|
|
|
1899 |
/*
|
|
|
1900 |
#函式說明:
|
|
|
1901 |
#建立資料表,會回傳一個陣列。
|
|
|
1902 |
#回傳結果:
|
|
|
1903 |
#$result["status"],若成功則爲"true",失敗則爲"false"。
|
|
|
1904 |
#$result["error"],錯誤訊息的陣列。
|
|
|
1905 |
#$result["sql"],要執行的sql語法。
|
|
|
1906 |
#$result["function"],當前執行的函數名稱.
|
|
|
1907 |
#必填參數:
|
|
|
1908 |
#$conf["dbAddress"],字串,爲mysql-Server的位置
|
|
|
1909 |
$conf["dbAddress"]=$dbAddress;
|
|
|
1910 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
|
|
|
1911 |
$conf["dbAccount"]=$dbAccount;
|
| 226 |
liveuser |
1912 |
#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱
|
| 3 |
liveuser |
1913 |
$conf["selectedDataBaseName"]=$dbName;
|
|
|
1914 |
#$conf["newDataTableName"],字串,爲要新增的資料表名稱.
|
|
|
1915 |
$conf["newDataTableName"]="";
|
|
|
1916 |
#$conf["newDataTableColmunName"],字串,為新資料表的欄位名稱.
|
|
|
1917 |
$conf["newDataTableColmunName"]=array("id","lastUpdatedTime");
|
|
|
1918 |
#$conf["newDataTableColmunType"],字串陣列,為新資料表的欄位儲存的型態,常見的有:int,用來儲存整數;double,用來儲存有小數點的數值;timestamp,用來儲存時間;char,用來儲存任何東西,儲存成字元
|
|
|
1919 |
$conf["newDataTableColmunType"]=array("int","timestamp");
|
|
|
1920 |
#$conf["newDataTableColmunDefault"],字串陣列,為該欄位的預設值,若為currentTime則為當前時間;若為updatedCurrentTime則為初始為當前時間,之後每更動一次就更新為當次時間;若為null則代表空值;若為""則為不設定;以外的內容視為指定的數值.
|
|
|
1921 |
$conf["newDataTableColmunDefault"]=array("","updatedCurrentTime");
|
|
|
1922 |
#$conf["newDataTableColmunLength"],字串陣列,為新資料表的欄位儲存的長度,""代表不指定長度.
|
|
|
1923 |
$conf["newDataTableColmunLength"]=array("","");
|
|
|
1924 |
#$conf["newDataTableColmunNull"],字串陣列,為新資料表的欄位是否可為NULL.若為no則代表不能為null;若為yes則代表可以為null.
|
| 226 |
liveuser |
1925 |
$conf["newDataTableColmunNull"]=array("no","no","no","no");
|
| 177 |
liveuser |
1926 |
#$conf["newDataTableColmunAutoAdd"],字串陣列,"true"為新資料表的欄位自動+1;反之設為""即可.
|
|
|
1927 |
$conf["newDataTableColmunAutoAdd"]=array("true","","","");
|
| 3 |
liveuser |
1928 |
#$conf["newDataTableColmunKeyType"],字串陣列,為該欄位的鍵屬性:primary key代表主鍵;留"",代表不指定。
|
| 177 |
liveuser |
1929 |
$conf["newDataTableColmunKeyType"]=array("primary key","","","");
|
| 3 |
liveuser |
1930 |
#可省略參數:
|
|
|
1931 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
1932 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
1933 |
#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
|
|
|
1934 |
#$conf["dbPort"]="3306";
|
|
|
1935 |
#參考資料:
|
|
|
1936 |
#無.
|
|
|
1937 |
#備註:
|
|
|
1938 |
#無.
|
|
|
1939 |
*/
|
|
|
1940 |
public static function createDataTable($conf){
|
| 226 |
liveuser |
1941 |
|
| 3 |
liveuser |
1942 |
#初始化要回傳的結果
|
|
|
1943 |
$result=array();
|
| 226 |
liveuser |
1944 |
|
| 3 |
liveuser |
1945 |
#取得當前執行的函數名稱
|
|
|
1946 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
1947 |
|
| 3 |
liveuser |
1948 |
#如果 $conf 不為陣列
|
|
|
1949 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
1950 |
|
| 3 |
liveuser |
1951 |
#設置執行失敗
|
|
|
1952 |
$result["status"]="false";
|
| 226 |
liveuser |
1953 |
|
| 3 |
liveuser |
1954 |
#設置執行錯誤訊息
|
|
|
1955 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
1956 |
|
|
|
1957 |
#如果傳入的參數為 null
|
|
|
1958 |
if($conf==null){
|
| 226 |
liveuser |
1959 |
|
| 3 |
liveuser |
1960 |
#設置執行錯誤訊息
|
|
|
1961 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
1962 |
|
| 3 |
liveuser |
1963 |
}#if end
|
|
|
1964 |
|
|
|
1965 |
#回傳結果
|
|
|
1966 |
return $result;
|
| 226 |
liveuser |
1967 |
|
| 3 |
liveuser |
1968 |
}#if end
|
| 226 |
liveuser |
1969 |
|
| 3 |
liveuser |
1970 |
#函式說明:
|
|
|
1971 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
1972 |
#回傳結果:
|
|
|
1973 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
1974 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
1975 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
1976 |
#必填參數:
|
|
|
1977 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
1978 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","newDataTableName","newDataTableColmunName","newDataTableColmunType","newDataTableColmunLength","newDataTableColmunDefault","newDataTableColmunNull","newDataTableColmunAutoAdd","newDataTableColmunKeyType");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
1979 |
#可省略參數:
|
| 226 |
liveuser |
1980 |
#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
1981 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
1982 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
1983 |
unset($conf["variableCheck"]["isexistMuti"]);
|
| 226 |
liveuser |
1984 |
|
| 3 |
liveuser |
1985 |
#如果檢查動作不正常
|
|
|
1986 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
1987 |
|
| 3 |
liveuser |
1988 |
#設置執失敗訊息
|
|
|
1989 |
$result["status"]="false";
|
| 226 |
liveuser |
1990 |
|
| 3 |
liveuser |
1991 |
#設置錯誤訊息
|
|
|
1992 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
1993 |
|
| 3 |
liveuser |
1994 |
#回傳錯誤訊息
|
|
|
1995 |
return $result;
|
| 226 |
liveuser |
1996 |
|
| 3 |
liveuser |
1997 |
}#if end
|
| 226 |
liveuser |
1998 |
|
| 3 |
liveuser |
1999 |
#如果檢查不通過
|
|
|
2000 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
2001 |
|
| 3 |
liveuser |
2002 |
#設置執失敗訊息
|
|
|
2003 |
$result["status"]="false";
|
| 226 |
liveuser |
2004 |
|
| 3 |
liveuser |
2005 |
#設置錯誤訊息
|
|
|
2006 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2007 |
|
| 3 |
liveuser |
2008 |
#回傳錯誤訊息
|
|
|
2009 |
return $result;
|
| 226 |
liveuser |
2010 |
|
| 3 |
liveuser |
2011 |
}#if end
|
| 226 |
liveuser |
2012 |
|
| 3 |
liveuser |
2013 |
#建立資料表的語法
|
|
|
2014 |
$sql="create table ".$conf["selectedDataBaseName"].".".$conf["newDataTableName"];
|
| 226 |
liveuser |
2015 |
|
| 3 |
liveuser |
2016 |
#加上指定欄位內容的開頭
|
|
|
2017 |
$sql=$sql."(";
|
| 226 |
liveuser |
2018 |
|
| 3 |
liveuser |
2019 |
#針對每個欄位
|
|
|
2020 |
for($i=0;$i<count($conf["newDataTableColmunName"]);$i++){
|
| 226 |
liveuser |
2021 |
|
| 3 |
liveuser |
2022 |
#接上欄位名稱
|
|
|
2023 |
$sql=$sql.$conf["newDataTableColmunName"][$i];
|
| 226 |
liveuser |
2024 |
|
| 3 |
liveuser |
2025 |
#接上欄位儲存型態
|
|
|
2026 |
$sql=$sql." ".$conf["newDataTableColmunType"][$i];
|
| 226 |
liveuser |
2027 |
|
| 3 |
liveuser |
2028 |
#如果有設定資料長度
|
|
|
2029 |
if($conf["newDataTableColmunLength"][$i]!=""){
|
| 226 |
liveuser |
2030 |
|
| 3 |
liveuser |
2031 |
#接上欄位儲存長度
|
|
|
2032 |
$sql=$sql." (".$conf["newDataTableColmunLength"][$i].")";
|
| 226 |
liveuser |
2033 |
|
| 3 |
liveuser |
2034 |
}#if end
|
| 226 |
liveuser |
2035 |
|
| 3 |
liveuser |
2036 |
#如果有設定值
|
|
|
2037 |
if($conf["newDataTableColmunDefault"][$i]!=""){
|
| 226 |
liveuser |
2038 |
|
| 3 |
liveuser |
2039 |
switch($conf["newDataTableColmunDefault"][$i]){
|
| 226 |
liveuser |
2040 |
|
| 3 |
liveuser |
2041 |
#如果設為 currentTime
|
|
|
2042 |
case "currentTime":
|
| 226 |
liveuser |
2043 |
|
| 3 |
liveuser |
2044 |
#設定語法
|
|
|
2045 |
$sql=$sql." default CURRENT_TIMESTAMP";
|
| 226 |
liveuser |
2046 |
|
| 3 |
liveuser |
2047 |
#跳出switch
|
|
|
2048 |
break;
|
| 226 |
liveuser |
2049 |
|
| 3 |
liveuser |
2050 |
#如果設為updatedCurrentTime
|
|
|
2051 |
case "updatedCurrentTime":
|
| 226 |
liveuser |
2052 |
|
| 3 |
liveuser |
2053 |
#設定語法
|
|
|
2054 |
$sql=$sql." default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP";
|
| 226 |
liveuser |
2055 |
|
| 3 |
liveuser |
2056 |
#跳出switch
|
|
|
2057 |
break;
|
| 226 |
liveuser |
2058 |
|
| 3 |
liveuser |
2059 |
#如果設為 null
|
|
|
2060 |
case "null":
|
| 226 |
liveuser |
2061 |
|
| 3 |
liveuser |
2062 |
#設定語法
|
|
|
2063 |
$sql=$sql." default null";
|
| 226 |
liveuser |
2064 |
|
| 3 |
liveuser |
2065 |
#跳出switch
|
|
|
2066 |
break;
|
| 226 |
liveuser |
2067 |
|
| 3 |
liveuser |
2068 |
#如果不為以上數值
|
|
|
2069 |
default :
|
| 226 |
liveuser |
2070 |
|
| 3 |
liveuser |
2071 |
#設定語法
|
|
|
2072 |
$sql=$sql." default ".$conf["newDataTableColmunDefault"][$i];
|
| 226 |
liveuser |
2073 |
|
| 3 |
liveuser |
2074 |
#跳出switch
|
|
|
2075 |
break;
|
| 226 |
liveuser |
2076 |
|
| 3 |
liveuser |
2077 |
}#switch end
|
| 226 |
liveuser |
2078 |
|
| 3 |
liveuser |
2079 |
}#if end
|
| 226 |
liveuser |
2080 |
|
| 3 |
liveuser |
2081 |
#如果有設定不能為NULL
|
|
|
2082 |
if($conf["newDataTableColmunNull"][$i]=="no"){
|
| 226 |
liveuser |
2083 |
|
| 3 |
liveuser |
2084 |
$sql=$sql." NOT NULL";
|
| 226 |
liveuser |
2085 |
|
| 3 |
liveuser |
2086 |
}#if end
|
| 226 |
liveuser |
2087 |
|
| 3 |
liveuser |
2088 |
#如果有設定要自動加1
|
|
|
2089 |
if($conf["newDataTableColmunAutoAdd"][$i]=="true"){
|
| 226 |
liveuser |
2090 |
|
| 3 |
liveuser |
2091 |
#加上自動加1的語句
|
|
|
2092 |
$sql=$sql." auto_increment";
|
| 226 |
liveuser |
2093 |
|
| 3 |
liveuser |
2094 |
}#if end
|
| 226 |
liveuser |
2095 |
|
| 3 |
liveuser |
2096 |
#如果有設定鍵的屬性
|
|
|
2097 |
if($conf["newDataTableColmunKeyType"][$i]!=""){
|
| 226 |
liveuser |
2098 |
|
| 3 |
liveuser |
2099 |
$sql=$sql." ".$conf["newDataTableColmunKeyType"][$i];
|
| 226 |
liveuser |
2100 |
|
| 3 |
liveuser |
2101 |
}#if end
|
| 226 |
liveuser |
2102 |
|
| 3 |
liveuser |
2103 |
#如果不是最後一個欄位
|
|
|
2104 |
if($i!=count($conf["newDataTableColmunName"])-1){
|
| 226 |
liveuser |
2105 |
|
| 3 |
liveuser |
2106 |
#加上逗號
|
| 177 |
liveuser |
2107 |
$sql=$sql.",";
|
| 226 |
liveuser |
2108 |
|
| 3 |
liveuser |
2109 |
}#if end
|
| 226 |
liveuser |
2110 |
|
| 3 |
liveuser |
2111 |
}#for end
|
| 226 |
liveuser |
2112 |
|
| 3 |
liveuser |
2113 |
#加上指定欄位內容的結束
|
|
|
2114 |
$sql=$sql.") DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci ;";
|
| 226 |
liveuser |
2115 |
|
| 3 |
liveuser |
2116 |
#取得sql語法
|
|
|
2117 |
$result["sql"]=$sql;
|
| 226 |
liveuser |
2118 |
|
| 3 |
liveuser |
2119 |
#var_dump($sql);
|
| 226 |
liveuser |
2120 |
|
| 3 |
liveuser |
2121 |
#函式說明:
|
|
|
2122 |
#回傳結果::
|
|
|
2123 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
2124 |
#$result["error"],錯誤訊息的陣列
|
|
|
2125 |
#查詢號的解果,需要解析。
|
|
|
2126 |
#必填參數:
|
|
|
2127 |
$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
2128 |
$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
2129 |
$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
|
| 226 |
liveuser |
2130 |
#可省略參數:
|
|
|
2131 |
|
| 3 |
liveuser |
2132 |
#如果有設定密碼
|
|
|
2133 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
2134 |
|
| 3 |
liveuser |
2135 |
$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
2136 |
|
| 3 |
liveuser |
2137 |
}#if end
|
| 226 |
liveuser |
2138 |
|
| 3 |
liveuser |
2139 |
#如果 $conf["dbPort"] 有設定
|
|
|
2140 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
2141 |
|
| 3 |
liveuser |
2142 |
#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
|
|
|
2143 |
$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
2144 |
|
| 3 |
liveuser |
2145 |
}#if end
|
| 226 |
liveuser |
2146 |
|
| 3 |
liveuser |
2147 |
$queryResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
|
|
|
2148 |
unset($conf["db"]["execMysqlQuery"]);
|
| 226 |
liveuser |
2149 |
|
| 3 |
liveuser |
2150 |
#如果執行 sql 失敗
|
|
|
2151 |
if($queryResult["status"]=="false"){
|
| 226 |
liveuser |
2152 |
|
| 3 |
liveuser |
2153 |
#設置執行失敗訊息
|
|
|
2154 |
$result["status"]="false";
|
| 226 |
liveuser |
2155 |
|
| 3 |
liveuser |
2156 |
#設置錯誤訊息
|
|
|
2157 |
$result["error"]=$queryResult["error"];
|
| 226 |
liveuser |
2158 |
|
| 177 |
liveuser |
2159 |
#回傳結果
|
| 3 |
liveuser |
2160 |
return $result;
|
| 226 |
liveuser |
2161 |
|
| 3 |
liveuser |
2162 |
}#if end
|
| 226 |
liveuser |
2163 |
|
| 3 |
liveuser |
2164 |
#設置執成功訊息
|
|
|
2165 |
$result["status"]="true";
|
| 226 |
liveuser |
2166 |
|
| 3 |
liveuser |
2167 |
#回傳結果
|
|
|
2168 |
return $result;
|
| 226 |
liveuser |
2169 |
|
| 3 |
liveuser |
2170 |
}#function createDataTable end
|
|
|
2171 |
|
|
|
2172 |
/*
|
|
|
2173 |
#函式說明:
|
|
|
2174 |
#新增資料表的欄位
|
|
|
2175 |
#回傳結果:
|
|
|
2176 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗
|
|
|
2177 |
#$result["error"],錯誤訊息陣列
|
|
|
2178 |
#$result["sql"],執行的sql內容
|
|
|
2179 |
#$result["function"],當前執行的函數名稱
|
|
|
2180 |
#必填參數:
|
|
|
2181 |
#$conf["dbAddress"],字串,爲mysql-Server的位置.
|
|
|
2182 |
$conf["dbAddress"]=$dbAddress;
|
|
|
2183 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號.
|
|
|
2184 |
$conf["dbAccount"]=$dbAccount;#爲用於連入mysql-Server時要使用的帳號.
|
|
|
2185 |
#$conf["selectedDataBaseName"],字串,爲目標資料表所屬的資料庫.
|
|
|
2186 |
$conf["selectedDataBaseName"]="";
|
|
|
2187 |
#$conf["selectedDataTableName"],字串,爲目標資料表所屬的資料庫.
|
|
|
2188 |
$conf["selectedDataTableName"]="";
|
|
|
2189 |
#$conf["addedColumnName"],字串,要增加的欄位名稱.
|
|
|
2190 |
$conf["addedColumnName"]="";
|
|
|
2191 |
#$conf["newDataTableColmunType"],字串,為新資料表的欄位儲存的型態,常見的有:#int,用來儲存整數.#double,用來儲存有小數點的數值.#timestamp,用來儲存時間.#varchar,最多可以儲存65535個字元,請記得使用$conf["newDataTableColmunLength"]參數指定長度.#char,用來儲存任何東西,儲存成字元,最大長限制為255.#tinytext,儲存長度限制為255,根據實際使用大小來調整儲存大小.#text,儲存大量文字,不能當索引鍵.
|
|
|
2192 |
$conf["newDataTableColmunType"]="char";
|
| 226 |
liveuser |
2193 |
#可省略參數:
|
| 3 |
liveuser |
2194 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
2195 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
2196 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
|
|
|
2197 |
#$conf["dbPort"]="3306";
|
|
|
2198 |
#$conf["newDataTableColmunLength"],字串,為新資料表的欄位儲存的長度.
|
|
|
2199 |
#$conf["newDataTableColmunLength"]="";
|
|
|
2200 |
#$conf["newDataTableColmunDefault"],字串,為該欄位的預設值.#currentTime,當前時間.#updatedCurrentTime,初始為當前時間,之後每更動一次就更新為當次時間.#null,代表空值.#以外的內容視為指定的數值.
|
|
|
2201 |
#$conf["newDataTableColmunDefault"]="";
|
|
|
2202 |
#$conf["newDataTableColmunNotNull"],字串,為新資料表的欄位不可為NULL.#"true"代表不能為null.#"false"代表可以為null.
|
|
|
2203 |
#$conf["newDataTableColmunNotNull"]="true";#
|
|
|
2204 |
#$conf["newDataTableColmunAutoAdd"],字串,為新資料表的欄位是否自動+1
|
|
|
2205 |
#$conf["newDataTableColmunAutoAdd"]="true";
|
|
|
2206 |
#$conf["newDataTableColmunKeyType"],字串,為該欄位的鍵屬性:"primary key"爲主鍵、"index"爲索引鍵、"foreign key"爲外鍵
|
|
|
2207 |
#$conf["newDataTableColmunKeyType"]="primary key";
|
|
|
2208 |
#$conf["foreignDb"]="";#外鍵參考的資料庫,預設為$conf["selectedDataBaseName"].
|
|
|
2209 |
#$conf["foreignDb"]=$conf["selectedDataBaseName"];
|
|
|
2210 |
#$conf["foreignTable"],字串,外鍵參考的資料表
|
|
|
2211 |
#$conf["foreignTable"]="";
|
|
|
2212 |
#$conf["foreignTableColumn"],字串,外鍵參考的資料表欄位
|
|
|
2213 |
#$conf["foreignTableColumn"]="";
|
|
|
2214 |
#$conf["onUpdateAction"],字串,當外鍵參考的欄位資料修改時,外鍵要如何回應?"CASCADE"會將有所關聯的紀錄行也會進行刪除或修改。"SET NULL"代表會將有所關聯的紀錄行設定成 NULL。"NO ACTION"代表有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
|
|
|
2215 |
#$conf["onUpdateAction"]="CASCADE";#
|
|
|
2216 |
#$conf["onDeleteAction"],字串,當外鍵參考的欄位資料移除時,外鍵要如何回應?"CASCADE"會將有所關聯的紀錄行也會進行刪除或修改。"SET NULL"代表會將有所關聯的紀錄行設定成 NULL。"NO ACTION"代表有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
|
| 226 |
liveuser |
2217 |
#$conf["onDeleteAction"]="SET NULL";
|
| 3 |
liveuser |
2218 |
#$conf["comment"],字串,欄位的註解,預設不使用.
|
|
|
2219 |
#$conf["comment"]="";
|
|
|
2220 |
#參考資料:
|
|
|
2221 |
#儲存型態=>https://mariadb.com/kb/en/data-types/
|
|
|
2222 |
#備註:
|
|
|
2223 |
#無.
|
|
|
2224 |
*/
|
|
|
2225 |
public static function addColumn(&$conf){
|
| 226 |
liveuser |
2226 |
|
| 3 |
liveuser |
2227 |
#初始化要回傳的結果
|
|
|
2228 |
$result=array();
|
| 226 |
liveuser |
2229 |
|
| 3 |
liveuser |
2230 |
#記錄當前執行的函數名稱
|
|
|
2231 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
2232 |
|
| 3 |
liveuser |
2233 |
#如果 $conf 不為陣列
|
|
|
2234 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
2235 |
|
| 3 |
liveuser |
2236 |
#設置執行失敗
|
|
|
2237 |
$result["status"]="false";
|
| 226 |
liveuser |
2238 |
|
| 3 |
liveuser |
2239 |
#設置執行錯誤訊息
|
|
|
2240 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2241 |
|
|
|
2242 |
#如果傳入的參數為 null
|
|
|
2243 |
if($conf==null){
|
| 226 |
liveuser |
2244 |
|
| 3 |
liveuser |
2245 |
#設置執行錯誤訊息
|
|
|
2246 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
2247 |
|
| 3 |
liveuser |
2248 |
}#if end
|
|
|
2249 |
|
|
|
2250 |
#回傳結果
|
|
|
2251 |
return $result;
|
| 226 |
liveuser |
2252 |
|
| 3 |
liveuser |
2253 |
}#if end
|
| 226 |
liveuser |
2254 |
|
| 3 |
liveuser |
2255 |
#檢查參數
|
|
|
2256 |
#函式說明:
|
|
|
2257 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2258 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2259 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2260 |
#$result["function"],當前執行的函式名稱.
|
|
|
2261 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2262 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2263 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2264 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2265 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2266 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2267 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2268 |
#必填參數:
|
|
|
2269 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2270 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
2271 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2272 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName","addedColumnName");
|
| 226 |
liveuser |
2273 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
2274 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string");
|
|
|
2275 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2276 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
2277 |
#可省略參數:
|
|
|
2278 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
2279 |
#$conf["canBeEmptyString"]="false";
|
|
|
2280 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2281 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort","newDataTableColmunType","newDataTableColmunLength","newDataTableColmunDefault","newDataTableColmunNotNull","newDataTableColmunAutoAdd","newDataTableColmunKeyType","foreignDb","foreignTable","foreignTableColumn","onUpdateAction","onDeleteAction","comment");
|
| 226 |
liveuser |
2282 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
2283 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string","string","string","string","string","string","string","string");
|
|
|
2284 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2285 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null,null,null,null,null,"\$conf[\"selectedDataBaseName\"]",null,null,null,null,null);
|
|
|
2286 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2287 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
2288 |
#參考資料:
|
|
|
2289 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2290 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
2291 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
2292 |
|
| 3 |
liveuser |
2293 |
#如果檢查過程有錯
|
|
|
2294 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
2295 |
|
| 3 |
liveuser |
2296 |
#設置執行失敗的訊息
|
|
|
2297 |
$result["status"]="false";
|
| 226 |
liveuser |
2298 |
|
| 3 |
liveuser |
2299 |
#設置錯誤訊息
|
|
|
2300 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2301 |
|
| 3 |
liveuser |
2302 |
#回傳結果
|
|
|
2303 |
return $result;
|
| 226 |
liveuser |
2304 |
|
| 3 |
liveuser |
2305 |
}#if end
|
| 226 |
liveuser |
2306 |
|
| 3 |
liveuser |
2307 |
#如果檢查不通過
|
|
|
2308 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
2309 |
|
| 3 |
liveuser |
2310 |
#設置執行失敗的訊息
|
|
|
2311 |
$result["status"]="false";
|
| 226 |
liveuser |
2312 |
|
| 3 |
liveuser |
2313 |
#設置錯誤訊息
|
|
|
2314 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2315 |
|
| 3 |
liveuser |
2316 |
#回傳結果
|
|
|
2317 |
return $result;
|
| 226 |
liveuser |
2318 |
|
| 3 |
liveuser |
2319 |
}#if end
|
| 226 |
liveuser |
2320 |
|
| 3 |
liveuser |
2321 |
#組合sql語言
|
|
|
2322 |
$sql="alter table `".$conf["selectedDataTableName"]."` add `".$conf["addedColumnName"]."`";
|
| 226 |
liveuser |
2323 |
|
| 3 |
liveuser |
2324 |
#接上欄位儲存型態
|
|
|
2325 |
$sql=$sql." ".$conf["newDataTableColmunType"];
|
| 226 |
liveuser |
2326 |
|
| 3 |
liveuser |
2327 |
#如果資料形態爲 "double、float"
|
|
|
2328 |
if($conf["newDataTableColmunType"]=="double" || $conf["newDataTableColmunType"]=="float" ){
|
| 226 |
liveuser |
2329 |
|
| 3 |
liveuser |
2330 |
#則取消資料長度的限制
|
|
|
2331 |
unset($conf["newDataTableColmunLength"]);
|
| 226 |
liveuser |
2332 |
|
|
|
2333 |
}#if end
|
|
|
2334 |
|
| 3 |
liveuser |
2335 |
#如果有設定資料長度,且資料儲存型態不為 tinytext 與 text
|
|
|
2336 |
if(isset($conf["newDataTableColmunLength"]) && $conf["newDataTableColmunType"]!="tinytext" && $conf["newDataTableColmunType"]!="text"){
|
| 226 |
liveuser |
2337 |
|
| 3 |
liveuser |
2338 |
#接上欄位儲存長度
|
|
|
2339 |
$sql=$sql." (".$conf["newDataTableColmunLength"].")";
|
| 226 |
liveuser |
2340 |
|
| 3 |
liveuser |
2341 |
}#if end
|
| 226 |
liveuser |
2342 |
|
| 3 |
liveuser |
2343 |
#如果資料形態不爲 "double、float、"
|
|
|
2344 |
if($conf["newDataTableColmunType"]!="double" && $conf["newDataTableColmunType"]!="float" && $conf["newDataTableColmunType"]!="int"){
|
| 226 |
liveuser |
2345 |
|
| 3 |
liveuser |
2346 |
#指定欄CHARACTER SET爲utf8,COLLATE爲utf8_unicode_ci
|
|
|
2347 |
$sql=$sql." CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'";
|
| 226 |
liveuser |
2348 |
|
| 3 |
liveuser |
2349 |
}#if end
|
| 226 |
liveuser |
2350 |
|
| 3 |
liveuser |
2351 |
#如果有設定預設值
|
|
|
2352 |
if(isset($conf["newDataTableColmunDefault"])){
|
| 226 |
liveuser |
2353 |
|
| 3 |
liveuser |
2354 |
#如果 $conf["newDataTableColmunType"] 不等於 "tinytext" 也不等於 "text"
|
|
|
2355 |
if($conf["newDataTableColmunType"]!="tinytext" && $conf["newDataTableColmunType"]!="text"){
|
| 226 |
liveuser |
2356 |
|
| 3 |
liveuser |
2357 |
#根據 $conf["newDataTableColmunDefault"] 的數值內容
|
|
|
2358 |
switch($conf["newDataTableColmunDefault"]){
|
| 226 |
liveuser |
2359 |
|
| 3 |
liveuser |
2360 |
#如果設為 currentTime
|
|
|
2361 |
case "currentTime":
|
| 226 |
liveuser |
2362 |
|
| 3 |
liveuser |
2363 |
#設定語法
|
|
|
2364 |
$sql=$sql." default CURRENT_TIMESTAMP";
|
| 226 |
liveuser |
2365 |
|
| 3 |
liveuser |
2366 |
#跳出switch
|
|
|
2367 |
break;
|
| 226 |
liveuser |
2368 |
|
| 3 |
liveuser |
2369 |
#如果設為updatedCurrentTime
|
|
|
2370 |
case "updatedCurrentTime":
|
| 226 |
liveuser |
2371 |
|
| 3 |
liveuser |
2372 |
#設定語法
|
|
|
2373 |
$sql=$sql." default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP";
|
| 226 |
liveuser |
2374 |
|
| 3 |
liveuser |
2375 |
#跳出switch
|
|
|
2376 |
break;
|
| 226 |
liveuser |
2377 |
|
| 3 |
liveuser |
2378 |
#如果設為 null
|
|
|
2379 |
case "null":
|
| 226 |
liveuser |
2380 |
|
| 3 |
liveuser |
2381 |
#設定語法
|
|
|
2382 |
$sql=$sql." default null";
|
| 226 |
liveuser |
2383 |
|
| 3 |
liveuser |
2384 |
#跳出switch
|
|
|
2385 |
break;
|
| 226 |
liveuser |
2386 |
|
| 3 |
liveuser |
2387 |
#如果不為以上數值
|
|
|
2388 |
default :
|
| 226 |
liveuser |
2389 |
|
| 3 |
liveuser |
2390 |
#設定語法
|
|
|
2391 |
$sql=$sql." default '".$conf["newDataTableColmunDefault"]."'";
|
| 226 |
liveuser |
2392 |
|
| 3 |
liveuser |
2393 |
#跳出switch
|
|
|
2394 |
break;
|
| 226 |
liveuser |
2395 |
|
| 3 |
liveuser |
2396 |
}#switch end
|
| 226 |
liveuser |
2397 |
|
| 3 |
liveuser |
2398 |
}#if end
|
| 226 |
liveuser |
2399 |
|
| 3 |
liveuser |
2400 |
}#if end
|
| 226 |
liveuser |
2401 |
|
| 3 |
liveuser |
2402 |
#如果有設定不能為NUL
|
|
|
2403 |
if(isset($conf["newDataTableColmunNotNull"])){
|
| 226 |
liveuser |
2404 |
|
| 3 |
liveuser |
2405 |
#如果 $conf["newDataTableColmunNotNull"] 等於 "true"
|
|
|
2406 |
if($conf["newDataTableColmunNotNull"]=="true"){
|
| 226 |
liveuser |
2407 |
|
| 3 |
liveuser |
2408 |
$sql=$sql." NOT NULL";
|
| 226 |
liveuser |
2409 |
|
| 3 |
liveuser |
2410 |
}#if end
|
| 226 |
liveuser |
2411 |
|
| 3 |
liveuser |
2412 |
}#if end
|
| 226 |
liveuser |
2413 |
|
| 3 |
liveuser |
2414 |
#如果有設定要自動加1
|
|
|
2415 |
if(isset($conf["newDataTableColmunAutoAdd"])){
|
| 226 |
liveuser |
2416 |
|
| 3 |
liveuser |
2417 |
#如果 $conf["newDataTableColmunAutoAdd"] 設為 "true"
|
|
|
2418 |
if($conf["newDataTableColmunAutoAdd"]=="true"){
|
| 226 |
liveuser |
2419 |
|
| 3 |
liveuser |
2420 |
#加上自動加1的語句
|
|
|
2421 |
$sql=$sql." auto_increment";
|
| 226 |
liveuser |
2422 |
|
| 3 |
liveuser |
2423 |
}#if end
|
| 226 |
liveuser |
2424 |
|
| 3 |
liveuser |
2425 |
}#if end
|
| 226 |
liveuser |
2426 |
|
| 3 |
liveuser |
2427 |
#如果有設定註解
|
|
|
2428 |
if(isset($conf["comment"])){
|
| 226 |
liveuser |
2429 |
|
| 3 |
liveuser |
2430 |
#設定其註解
|
|
|
2431 |
$sql=$sql." COMMENT '".$conf["comment"]."' ";
|
| 226 |
liveuser |
2432 |
|
|
|
2433 |
}#if end
|
|
|
2434 |
|
| 3 |
liveuser |
2435 |
#如果有設定鍵的屬性
|
|
|
2436 |
if(isset($conf["newDataTableColmunKeyType"])){
|
| 226 |
liveuser |
2437 |
|
|
|
2438 |
#如果爲 primary key
|
| 3 |
liveuser |
2439 |
if($conf["newDataTableColmunKeyType"]=="primary key"){
|
| 226 |
liveuser |
2440 |
|
| 3 |
liveuser |
2441 |
#設定其鍵值
|
|
|
2442 |
$sql=$sql." ".$conf["newDataTableColmunKeyType"];
|
| 226 |
liveuser |
2443 |
|
| 3 |
liveuser |
2444 |
}#if end
|
| 226 |
liveuser |
2445 |
|
| 3 |
liveuser |
2446 |
}#if end
|
| 226 |
liveuser |
2447 |
|
| 3 |
liveuser |
2448 |
#執行sql語法
|
|
|
2449 |
#函式說明:
|
|
|
2450 |
#執行mysql指令
|
|
|
2451 |
#回傳結果::
|
|
|
2452 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
2453 |
#$result["error"],錯誤訊息的陣列
|
|
|
2454 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
2455 |
#$result["queryString"],mysql查詢的語言
|
|
|
2456 |
#查詢號的解果,需要解析。
|
|
|
2457 |
#必填參數:
|
|
|
2458 |
$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
2459 |
$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
2460 |
$conf["db"]["execMysqlQuery"]["dbSql"]=$sql.";";#要執行sql語法
|
|
|
2461 |
#可省略參數:
|
| 226 |
liveuser |
2462 |
|
| 3 |
liveuser |
2463 |
#如果 $conf["dbPassword"] 有設定
|
|
|
2464 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
2465 |
|
| 3 |
liveuser |
2466 |
#設定其密碼
|
|
|
2467 |
$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
2468 |
|
| 3 |
liveuser |
2469 |
}#if end
|
| 226 |
liveuser |
2470 |
|
| 3 |
liveuser |
2471 |
$conf["db"]["execMysqlQuery"]["dbName"]=$conf["selectedDataBaseName"];#為是否要指定資料庫,預設不指定.
|
| 226 |
liveuser |
2472 |
|
|
|
2473 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
2474 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
2475 |
|
| 3 |
liveuser |
2476 |
#設定 $conf["dbPort"]
|
|
|
2477 |
$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
2478 |
|
|
|
2479 |
}#if end
|
|
|
2480 |
|
| 3 |
liveuser |
2481 |
$queryResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
|
|
|
2482 |
unset($conf["db"]["execMysqlQuery"]);
|
| 226 |
liveuser |
2483 |
|
| 3 |
liveuser |
2484 |
#如果有錯誤
|
|
|
2485 |
if($queryResult["status"]=="false"){
|
| 226 |
liveuser |
2486 |
|
| 3 |
liveuser |
2487 |
#設置錯誤訊息
|
|
|
2488 |
$result["status"]="false";
|
| 226 |
liveuser |
2489 |
|
| 3 |
liveuser |
2490 |
#設置錯誤提示
|
|
|
2491 |
$result["error"]=$queryResult;
|
| 226 |
liveuser |
2492 |
|
| 3 |
liveuser |
2493 |
#回傳結果
|
|
|
2494 |
return $result;
|
| 226 |
liveuser |
2495 |
|
| 3 |
liveuser |
2496 |
}#if end
|
| 226 |
liveuser |
2497 |
|
| 3 |
liveuser |
2498 |
#取得執行的sql語法
|
|
|
2499 |
$result["sql"][]=$queryResult["queryString"];
|
| 226 |
liveuser |
2500 |
|
| 3 |
liveuser |
2501 |
#如果 $conf["newDataTableColmunKeyType"] 存在
|
|
|
2502 |
if(isset($conf["newDataTableColmunKeyType"])){
|
| 226 |
liveuser |
2503 |
|
| 3 |
liveuser |
2504 |
#如果爲 index
|
|
|
2505 |
if($conf["newDataTableColmunKeyType"]=="index"){
|
| 226 |
liveuser |
2506 |
|
| 3 |
liveuser |
2507 |
#函式說明:
|
|
|
2508 |
#新增資料表的欄位
|
|
|
2509 |
#回傳結果:
|
|
|
2510 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗.
|
|
|
2511 |
#$result["function"],當前執行的函數名稱.
|
|
|
2512 |
#$result["error"],錯誤訊息陣列.
|
|
|
2513 |
#$result["sql"],執行的sql字串.
|
|
|
2514 |
#必填參數:
|
|
|
2515 |
$conf["db::setColumnIndex"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
2516 |
$conf["db::setColumnIndex"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
2517 |
$conf["db::setColumnIndex"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
|
|
|
2518 |
$conf["db::setColumnIndex"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
|
|
|
2519 |
$conf["db::setColumnIndex"]["indexedColumnName"]=$conf["addedColumnName"];#要設爲index的欄位名稱
|
|
|
2520 |
#可省略參數:
|
| 226 |
liveuser |
2521 |
|
| 3 |
liveuser |
2522 |
#如果 $conf["dbPassword"] 有設定
|
|
|
2523 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
2524 |
|
| 3 |
liveuser |
2525 |
$conf["db::setColumnIndex"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
2526 |
|
| 3 |
liveuser |
2527 |
}#if end
|
| 226 |
liveuser |
2528 |
|
|
|
2529 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
2530 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
2531 |
|
| 3 |
liveuser |
2532 |
#設定 $conf["dbPort"]
|
|
|
2533 |
$conf["db::setColumnIndex"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
2534 |
|
|
|
2535 |
}#if end
|
|
|
2536 |
|
| 3 |
liveuser |
2537 |
$setColumnIndex=db::setColumnIndex($conf["db::setColumnIndex"]);
|
|
|
2538 |
unset($conf["db::setColumnIndex"]);
|
| 226 |
liveuser |
2539 |
|
| 3 |
liveuser |
2540 |
#如果建立index失敗
|
|
|
2541 |
if($setColumnIndex["status"]=="false"){
|
| 226 |
liveuser |
2542 |
|
| 3 |
liveuser |
2543 |
#設置執行失敗
|
|
|
2544 |
$result["status"]="false";
|
| 226 |
liveuser |
2545 |
|
| 3 |
liveuser |
2546 |
#設置錯誤訊息
|
|
|
2547 |
$result["error"]=$setColumnIndex;
|
| 226 |
liveuser |
2548 |
|
| 3 |
liveuser |
2549 |
#回傳結果
|
|
|
2550 |
return $result;
|
| 226 |
liveuser |
2551 |
|
| 3 |
liveuser |
2552 |
}#if end
|
| 226 |
liveuser |
2553 |
|
| 3 |
liveuser |
2554 |
#取得執行的sql語法
|
|
|
2555 |
$result["sql"][]=$setColumnIndex["sql"];
|
| 226 |
liveuser |
2556 |
|
| 3 |
liveuser |
2557 |
}#if end
|
| 226 |
liveuser |
2558 |
|
| 3 |
liveuser |
2559 |
}#if end
|
| 226 |
liveuser |
2560 |
|
| 3 |
liveuser |
2561 |
#如果 $conf["newDataTableColmunKeyType"] 有設定
|
| 226 |
liveuser |
2562 |
if(isset($conf["newDataTableColmunKeyType"])){
|
|
|
2563 |
|
| 3 |
liveuser |
2564 |
#如果爲 foreign key
|
|
|
2565 |
if($conf["newDataTableColmunKeyType"]=="foreign key"){
|
| 226 |
liveuser |
2566 |
|
| 3 |
liveuser |
2567 |
#函式說明:
|
|
|
2568 |
#修改資料表的欄位
|
|
|
2569 |
#回傳結果:
|
|
|
2570 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗.
|
|
|
2571 |
#$result["error"],錯誤訊息陣列.
|
|
|
2572 |
#$result["function"],當前執行的函數名稱.
|
|
|
2573 |
#$result["sql"][$i],第$i+1個執行的sql語法字串陣列.
|
|
|
2574 |
#必填參數:
|
|
|
2575 |
$conf["db::editColumn"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
2576 |
$conf["db::editColumn"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
2577 |
$conf["db::editColumn"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
|
|
|
2578 |
$conf["db::editColumn"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料表
|
|
|
2579 |
$conf["db::editColumn"]["editedColumnName"]=$conf["addedColumnName"];#要修改的欄位名稱
|
| 226 |
liveuser |
2580 |
#可省略參數:
|
|
|
2581 |
|
| 3 |
liveuser |
2582 |
#如果 $conf["dbPassword"] 有設定
|
|
|
2583 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
2584 |
|
| 3 |
liveuser |
2585 |
$conf["db::editColumn"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
2586 |
|
| 3 |
liveuser |
2587 |
}#if end
|
| 226 |
liveuser |
2588 |
|
| 3 |
liveuser |
2589 |
#$conf["newColumnName"]="";#要修改成的欄位名稱,預設與$conf["dbInformation"]["editedColumnName"]一樣。
|
|
|
2590 |
#$conf["newDataTableColmunType"]="";#為新資料表的欄位儲存的型態,常見的有:
|
|
|
2591 |
#int,用來儲存整數.
|
|
|
2592 |
#double,用來儲存有小數點的數值.
|
|
|
2593 |
#timestamp,用來儲存時間.
|
|
|
2594 |
#varchar,可以儲存65536個字元.
|
|
|
2595 |
#char,用來儲存任何東西,儲存成字元,長度限制為255.
|
|
|
2596 |
#tinytest,來儲存大量的文字,會更據使用量調整儲存大小,長度限制跟char一樣.
|
|
|
2597 |
#text,用來儲存大量的文字,不能作為索引值
|
|
|
2598 |
#$conf["newDataTableColmunLength"]="";#為新資料表的欄位儲存的長度,""代表不限制長度
|
|
|
2599 |
#$conf["newDataTableColmunDefault"]="";#為該欄位的預設值
|
|
|
2600 |
#"",代表不指定預設值
|
|
|
2601 |
#currentTime,當前時間;
|
|
|
2602 |
#updatedCurrentTime,初始為當前時間,之後每更動一次就更新為當次時間
|
|
|
2603 |
#null,代表空值
|
|
|
2604 |
#以外的內容視為指定的數值
|
|
|
2605 |
#$conf["newDataTableColmunNotNull"]="";#為新資料表的欄位不可為NULL否:
|
|
|
2606 |
#true代表不能為null,
|
|
|
2607 |
#false代表可以為null。
|
|
|
2608 |
#$conf["newDataTableColmunAutoAdd"]="true";#為新資料表的欄位是否自動+1
|
|
|
2609 |
$conf["db::editColumn"]["newDataTableColmunKeyType"]="foreign key";#為該欄位的鍵屬性:""為移除鍵的設定、"primary key"爲主鍵、"index"爲索引鍵、"foreign key"為外鍵
|
|
|
2610 |
$conf["db::editColumn"]["foreignKeyDb"]=$conf["foreignDb"];#若要設定foreign key的話,則要提供參考的資料庫,預設為$conf["selectedDataBaseName"].
|
|
|
2611 |
$conf["db::editColumn"]["foreignKeyReferenceTable"]=$conf["foreignTable"];#若要設定foreign key的話,則要提供參考的資料表
|
|
|
2612 |
$conf["db::editColumn"]["foreignKeyReferenceColumn"]=$conf["foreignTableColumn"];#若要設定foreign key的話,則要提供參考的資料表欄位
|
| 226 |
liveuser |
2613 |
|
| 3 |
liveuser |
2614 |
#如果有設定 $conf["onUpdateAction"]
|
|
|
2615 |
if(isset($conf["onUpdateAction"])){
|
| 226 |
liveuser |
2616 |
|
| 3 |
liveuser |
2617 |
$conf["db::editColumn"]["foreignKeyUpdateAction"]=$conf["onUpdateAction"];#若要設定foreign key的話,可以指定參考的資料表欄位更新時該欄位該怎麼處理,預設為"CASCADE",會將有所關聯的紀錄行也會進行刪除或修改。"SET NULL"代表會將有所關聯的紀錄行設定成 NULL。"NO ACTION"代表有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
|
| 226 |
liveuser |
2618 |
|
| 3 |
liveuser |
2619 |
}#if end
|
| 226 |
liveuser |
2620 |
|
| 3 |
liveuser |
2621 |
#如果有設定 $conf["onDeleteAction"]
|
|
|
2622 |
if(isset($conf["onDeleteAction"])){
|
| 226 |
liveuser |
2623 |
|
| 3 |
liveuser |
2624 |
$conf["db::editColumn"]["foreignKeyDeleteAction"]=$conf["onDeleteAction"];#若要設定foreign key的話,可以指定參考的資料表欄位移除時該欄位該怎麼處理,預設為"SET NULL",會將有所關聯的紀錄行設定成 NULL。"NO ACTION"代表有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
|
| 226 |
liveuser |
2625 |
|
| 3 |
liveuser |
2626 |
}#if end
|
| 226 |
liveuser |
2627 |
|
|
|
2628 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
2629 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
2630 |
|
| 3 |
liveuser |
2631 |
#設定 $conf["dbPort"]
|
|
|
2632 |
$conf["db::editColumn"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
2633 |
|
| 3 |
liveuser |
2634 |
}#if end
|
| 226 |
liveuser |
2635 |
|
| 3 |
liveuser |
2636 |
$editColumn=db::editColumn($conf["db::editColumn"]);
|
|
|
2637 |
unset($conf["db::editColumn"]);
|
| 226 |
liveuser |
2638 |
|
| 3 |
liveuser |
2639 |
#如果設置為foreign失敗
|
|
|
2640 |
if($editColumn["status"]=="false"){
|
| 226 |
liveuser |
2641 |
|
| 3 |
liveuser |
2642 |
#設置執行失敗
|
|
|
2643 |
$result["status"]="false";
|
| 226 |
liveuser |
2644 |
|
| 3 |
liveuser |
2645 |
#設置錯誤訊息
|
|
|
2646 |
$result["error"]=$editColumn;
|
| 226 |
liveuser |
2647 |
|
| 3 |
liveuser |
2648 |
#回傳結果
|
|
|
2649 |
return $result;
|
| 226 |
liveuser |
2650 |
|
|
|
2651 |
}#if end
|
|
|
2652 |
|
| 3 |
liveuser |
2653 |
#有幾個執行的sql語法就執行幾次
|
|
|
2654 |
for($i=0;$i<count($editColumn["sql"]);$i++){
|
| 226 |
liveuser |
2655 |
|
| 3 |
liveuser |
2656 |
#取得執行的sql語法
|
|
|
2657 |
$result["sql"][]=$editColumn["sql"][$i];
|
| 226 |
liveuser |
2658 |
|
| 3 |
liveuser |
2659 |
}#for end
|
| 226 |
liveuser |
2660 |
|
| 3 |
liveuser |
2661 |
}#if end
|
| 226 |
liveuser |
2662 |
|
| 3 |
liveuser |
2663 |
}#if end
|
| 226 |
liveuser |
2664 |
|
| 3 |
liveuser |
2665 |
#執行到這邊代表執行成功
|
| 226 |
liveuser |
2666 |
|
| 3 |
liveuser |
2667 |
#設置成功訊息
|
|
|
2668 |
$result["status"]="true";
|
| 226 |
liveuser |
2669 |
|
| 3 |
liveuser |
2670 |
#回傳結果
|
|
|
2671 |
return $result;
|
| 226 |
liveuser |
2672 |
|
| 3 |
liveuser |
2673 |
}#function addColumn end
|
|
|
2674 |
|
|
|
2675 |
/*
|
|
|
2676 |
#函式說明:
|
|
|
2677 |
#修改資料表的欄位
|
|
|
2678 |
#回傳結果:
|
|
|
2679 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗.
|
|
|
2680 |
#$result["error"],錯誤訊息陣列.
|
|
|
2681 |
#$result["function"],當前執行的函數名稱.
|
|
|
2682 |
#$result["sql"][$i],第$i+1個執行的sql語法字串陣列.
|
|
|
2683 |
#必填參數:
|
|
|
2684 |
#$conf["dbAddress"],字串,爲mysql-Server的位置.
|
|
|
2685 |
$conf["dbAddress"]=$dbAddress;
|
|
|
2686 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號.
|
|
|
2687 |
$conf["dbAccount"]=$dbAccount;
|
|
|
2688 |
#$conf["selectedDataBaseName"],字串,爲目標資料表所屬的資料庫.
|
|
|
2689 |
$conf["selectedDataBaseName"]="";
|
|
|
2690 |
#$conf["selectedDataTableName"],字串,爲目標資料表所屬的資料表.
|
|
|
2691 |
$conf["selectedDataTableName"]="";
|
|
|
2692 |
#$conf["editedColumnName"],字串,要修改的欄位名稱.
|
|
|
2693 |
$conf["editedColumnName"]="";
|
| 226 |
liveuser |
2694 |
#可省略參數:
|
| 3 |
liveuser |
2695 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
2696 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
2697 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
|
|
|
2698 |
#$conf["dbPort"]="3306";
|
|
|
2699 |
#$conf["newColumnName"],字串,要修改成的欄位名稱,預設與$conf["editedColumnName"]一樣。
|
|
|
2700 |
#$conf["newColumnName"]=$conf["editedColumnName"];
|
|
|
2701 |
#$conf["newDataTableColmunType"],字串,為新資料表的欄位儲存的型態,常見的有:int,用來儲存整數;double,用來儲存有小數點的數值;timestamp,用來儲存時間;varchar,可以儲存65536個字元;char,用來儲存任何東西,儲存成字元,長度限制為255;tinytest,來儲存大量的文字,會更據使用量調整儲存大小,長度限制跟char一樣;text,用來儲存大量的文字,不能作為索引值
|
|
|
2702 |
#$conf["newDataTableColmunType"]="";
|
|
|
2703 |
#$conf["newDataTableColmunLength"]=,字串,為新資料表的欄位儲存的長度,""代表不限制長度.
|
|
|
2704 |
#$conf["newDataTableColmunLength"]="";
|
|
|
2705 |
#$conf["newDataTableColmunDefault"],字串,為該欄位的預設值:"",代表不指定預設值;currentTime,當前時間;updatedCurrentTime,初始為當前時間,之後每更動一次就更新為當次時間;null,代表空值;以外的內容視為指定的數值.
|
|
|
2706 |
#$conf["newDataTableColmunDefault"]="";
|
|
|
2707 |
#$conf["newDataTableColmunNotNull"],字串,為新資料表的欄位不可為NULL否:true代表不能為null;false代表可以為null.
|
|
|
2708 |
#$conf["newDataTableColmunNotNull"]="";
|
|
|
2709 |
#$conf["newDataTableColmunComment"],字串,欄位的註解.
|
|
|
2710 |
#$conf["newDataTableColmunComment"]="";
|
|
|
2711 |
#$conf["newDataTableColmunAutoAdd"],字串,為新資料表的欄位是否自動+1
|
|
|
2712 |
#$conf["newDataTableColmunAutoAdd"]="true";
|
|
|
2713 |
#$conf["newDataTableColmunKeyType"],字串,為該欄位的鍵屬性:""為移除鍵的設定、"primary key"爲主鍵、"index"爲索引鍵、"foreign key"為外鍵.
|
|
|
2714 |
#$conf["newDataTableColmunKeyType"]="";
|
|
|
2715 |
#$conf["foreignKeyDb"],字串,若要設定foreign key的話,則要提供參考的資料庫,預設為$conf["selectedDataBaseName"].
|
|
|
2716 |
#$conf["foreignKeyDb"]="";
|
|
|
2717 |
#$conf["foreignKeyReferenceTable"],字串,若要設定foreign key的話,則要提供參考的資料表.
|
|
|
2718 |
#$conf["foreignKeyReferenceTable"]="";
|
|
|
2719 |
#$conf["foreignKeyReferenceColumn"],字串,若要設定foreign key的話,則要提供參考的資料表欄位.
|
|
|
2720 |
#$conf["foreignKeyReferenceColumn"]="";
|
|
|
2721 |
#$conf["foreignKeyUpdateAction"],字串,若要設定foreign key的話,可以指定參考的資料表欄位更新時該欄位該怎麼處理,預設為"CASCADE",會將有所關聯的紀錄行也會進行刪除或修改。"SET NULL"代表會將有所關聯的紀錄行設定成 NULL。"NO ACTION"代表有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
|
|
|
2722 |
#$conf["foreignKeyUpdateAction"]="";
|
|
|
2723 |
#$conf["foreignKeyDeleteAction"],字串,若要設定foreign key的話,可以指定參考的資料表欄位移除時該欄位該怎麼處理,預設為"SET NULL",會將有所關聯的紀錄行設定成 NULL。"NO ACTION"代表有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
|
|
|
2724 |
#$conf["foreignKeyDeleteAction"]="SET NULL";
|
|
|
2725 |
#參考資料:
|
|
|
2726 |
#無.
|
|
|
2727 |
#備註:
|
|
|
2728 |
#無.
|
|
|
2729 |
*/
|
|
|
2730 |
public static function editColumn(&$conf){
|
| 226 |
liveuser |
2731 |
|
| 3 |
liveuser |
2732 |
#初始化要回傳的內容
|
|
|
2733 |
$result=array();
|
|
|
2734 |
|
|
|
2735 |
#取得當前執行的函數名稱
|
|
|
2736 |
$result["function"]=__FUNCTION__;
|
|
|
2737 |
|
|
|
2738 |
#如果 $conf 不為陣列
|
|
|
2739 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
2740 |
|
| 3 |
liveuser |
2741 |
#設置執行失敗
|
|
|
2742 |
$result["status"]="false";
|
| 226 |
liveuser |
2743 |
|
| 3 |
liveuser |
2744 |
#設置執行錯誤訊息
|
|
|
2745 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
2746 |
|
|
|
2747 |
#如果傳入的參數為 null
|
|
|
2748 |
if($conf==null){
|
| 226 |
liveuser |
2749 |
|
| 3 |
liveuser |
2750 |
#設置執行錯誤訊息
|
|
|
2751 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
2752 |
|
| 3 |
liveuser |
2753 |
}#if end
|
|
|
2754 |
|
|
|
2755 |
#回傳結果
|
|
|
2756 |
return $result;
|
| 226 |
liveuser |
2757 |
|
| 3 |
liveuser |
2758 |
}#if end
|
| 226 |
liveuser |
2759 |
|
| 3 |
liveuser |
2760 |
#檢查參數
|
|
|
2761 |
#函式說明:
|
|
|
2762 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
2763 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
2764 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
2765 |
#$result["function"],當前執行的函式名稱.
|
|
|
2766 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
2767 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
2768 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
2769 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
2770 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
2771 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
2772 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
2773 |
#必填參數:
|
|
|
2774 |
#$conf["db::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
2775 |
$conf["db::checkArguments"]["varInput"]=&$conf;
|
|
|
2776 |
#$conf["db::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
2777 |
$conf["db::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName","editedColumnName");
|
| 226 |
liveuser |
2778 |
#$conf["db::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
2779 |
$conf["db::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string");
|
|
|
2780 |
#$conf["db::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
2781 |
$conf["db::checkArguments"]["referenceVarKey"]="db::checkArguments";
|
|
|
2782 |
#可省略參數:
|
|
|
2783 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
2784 |
#$conf["canBeEmptyString"]="false";
|
|
|
2785 |
#$conf["db::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
2786 |
$conf["db::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort","newColumnName","newDataTableColmunType","newDataTableColmunLength","newDataTableColmunDefault","newDataTableColmunNotNull","newDataTableColmunAutoAdd","newDataTableColmunKeyType","foreignKeyDb","foreignKeyReferenceTable","foreignKeyReferenceColumn","foreignKeyUpdateAction","foreignKeyDeleteAction","newDataTableColmuComment");
|
| 226 |
liveuser |
2787 |
#$conf["db::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
2788 |
$conf["db::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string","string","string","string","string","string","string","string","string","string");
|
|
|
2789 |
#$conf["db::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
2790 |
$conf["db::checkArguments"]["skipableVarDefaultValue"]=array(null,null,$conf["editedColumnName"],null,null,null,null,null,null,"\$conf[\"selectedDataBaseName\"]",null,null,null,null,null);
|
|
|
2791 |
#$conf["db::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
2792 |
#$conf["db::checkArguments"]["arrayCountEqualCheck"][]=array();
|
|
|
2793 |
#參考資料:
|
|
|
2794 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
2795 |
$checkResult=variableCheck::checkArguments($conf["db::checkArguments"]);
|
|
|
2796 |
unset($conf["db::checkArguments"]);
|
| 226 |
liveuser |
2797 |
|
| 3 |
liveuser |
2798 |
#如果檢查有誤
|
|
|
2799 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
2800 |
|
| 3 |
liveuser |
2801 |
#設置執行失敗的訊息
|
|
|
2802 |
$result["status"]="false";
|
| 226 |
liveuser |
2803 |
|
| 3 |
liveuser |
2804 |
#設置錯誤訊息
|
|
|
2805 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2806 |
|
| 3 |
liveuser |
2807 |
#回傳結果
|
|
|
2808 |
return $result;
|
| 226 |
liveuser |
2809 |
|
| 3 |
liveuser |
2810 |
}#if end
|
| 226 |
liveuser |
2811 |
|
| 3 |
liveuser |
2812 |
#如果檢查不通過
|
|
|
2813 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
2814 |
|
| 3 |
liveuser |
2815 |
#設置執行失敗的訊息
|
|
|
2816 |
$result["status"]="false";
|
| 226 |
liveuser |
2817 |
|
| 3 |
liveuser |
2818 |
#設置錯誤訊息
|
|
|
2819 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
2820 |
|
| 3 |
liveuser |
2821 |
#回傳結果
|
|
|
2822 |
return $result;
|
| 226 |
liveuser |
2823 |
|
| 3 |
liveuser |
2824 |
}#if end
|
| 226 |
liveuser |
2825 |
|
| 3 |
liveuser |
2826 |
#取得目標資料表的所有資訊
|
|
|
2827 |
#函式說明:
|
|
|
2828 |
#取得資料表所有欄位的詳細資訊
|
|
|
2829 |
#回傳的內容:
|
|
|
2830 |
#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
|
|
|
2831 |
#$result["error"],錯誤訊息陣列
|
|
|
2832 |
#$result["sql"],執行的sql語法
|
|
|
2833 |
#$result["oriInput"],原始的資料表欄位資訊
|
|
|
2834 |
#$result["everyLine"],逐行的欄位資訊
|
|
|
2835 |
#$result["tableName"],當前查詢的資料表名稱
|
|
|
2836 |
#$result["engine"],資料表使用的儲存引擎
|
|
|
2837 |
#$result["charset"],資料表預設的編碼
|
|
|
2838 |
#$result["columnName"][$i],各欄位的名稱陣列,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
2839 |
#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
2840 |
#$result["columnVarType"][$i],各欄位變數儲存的型態,$i爲0開始的數字,也可以使用欄位的名稱.
|
|
|
2841 |
#$result["columnVarLengthLimit"][$i],個欄位變數的長度限制,若不存在其限制,則為"",$i爲0開始的數字,也可以使用欄位的名稱.
|
|
|
2842 |
#$result["columnNull"][$i],各欄位是否可以爲null,"true"爲可以爲null;"false"爲可不以爲"null",$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
2843 |
#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
2844 |
#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
2845 |
#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
2846 |
#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
2847 |
#$result["columnCollate"][$i],各欄位使用的Collate,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
2848 |
#$result["columnComment"][$i],各欄位的註解,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
2849 |
#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
|
|
|
2850 |
#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
|
|
|
2851 |
#$result["keyConstraintName"][$j],該資料表用於識別索引鍵的CONSTRAINT名稱陣列,$j爲0開始的數字,也可以使用欄位的名稱。
|
|
|
2852 |
#$result["primaryKey"],該資料表的主鍵
|
|
|
2853 |
#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
|
|
|
2854 |
#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲0開始的數字,也可以使用欄位的名稱。
|
|
|
2855 |
#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列,$k爲0開始的數字,也可以使用欄位的名稱。
|
|
|
2856 |
#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲0開始的數字,,也可用欄位的名稱來找value.
|
|
|
2857 |
#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲0開始的數字,也可用欄位的名稱來找value.
|
|
|
2858 |
#$result["foreignKey"]["onUpdateAction"][$i],當參照的欄位資料更新時,會怎麼同步,$i爲0開始的數字,也可用欄位的名稱來找value.
|
|
|
2859 |
#$result["foreignKey"]["onDeleteAction"][$i],當參照的欄位資料移除時,會怎麼同步,$i爲0開始的數字,也可用欄位的名稱來找value.
|
|
|
2860 |
#必填參數:
|
|
|
2861 |
$conf["db"]["getTableColumnDetailInfo"]["dbAddress"]=$conf["dbAddress"];#資料庫的網路位置
|
|
|
2862 |
$conf["db"]["getTableColumnDetailInfo"]["dbAccount"]=$conf["dbAccount"];#連線到資料庫要用的帳號
|
|
|
2863 |
$conf["db"]["getTableColumnDetailInfo"]["selectedDataBase"]=$conf["selectedDataBaseName"];#連線到資料庫要選擇的資料庫
|
|
|
2864 |
$conf["db"]["getTableColumnDetailInfo"]["selectedDataTable"]=$conf["selectedDataTableName"];#連線到資料庫要檢視的資料表
|
|
|
2865 |
#可省略參數:
|
| 226 |
liveuser |
2866 |
|
| 3 |
liveuser |
2867 |
#如果有設定連線密碼
|
|
|
2868 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
2869 |
|
| 3 |
liveuser |
2870 |
$conf["db"]["getTableColumnDetailInfo"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
2871 |
|
| 3 |
liveuser |
2872 |
}#if end
|
| 226 |
liveuser |
2873 |
|
|
|
2874 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
2875 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
2876 |
|
| 3 |
liveuser |
2877 |
#設定 $conf["dbPort"]
|
|
|
2878 |
$conf["db"]["getTableColumnDetailInfo"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
2879 |
|
|
|
2880 |
}#if end
|
|
|
2881 |
|
| 3 |
liveuser |
2882 |
$oriColumnInfo=db::getTableColumnDetailInfo($conf["db"]["getTableColumnDetailInfo"]);
|
|
|
2883 |
unset($conf["db"]["getTableColumnDetailInfo"]);
|
| 226 |
liveuser |
2884 |
|
| 3 |
liveuser |
2885 |
#debug
|
|
|
2886 |
#var_dump($oriColumnInfo);
|
|
|
2887 |
#exit;
|
| 226 |
liveuser |
2888 |
|
| 3 |
liveuser |
2889 |
#如果查詢資料表資訊失敗
|
|
|
2890 |
if($oriColumnInfo["status"]=="false"){
|
| 226 |
liveuser |
2891 |
|
| 3 |
liveuser |
2892 |
#設定執行失敗的識別
|
|
|
2893 |
$result["status"]="false";
|
| 226 |
liveuser |
2894 |
|
| 3 |
liveuser |
2895 |
#設定錯誤訊息
|
|
|
2896 |
$result["error"]=$oriColumnInfo;
|
| 226 |
liveuser |
2897 |
|
| 3 |
liveuser |
2898 |
#回傳結果
|
|
|
2899 |
return $result;
|
| 226 |
liveuser |
2900 |
|
| 3 |
liveuser |
2901 |
}#if end
|
| 226 |
liveuser |
2902 |
|
| 3 |
liveuser |
2903 |
#檢視目標欄位的鍵屬性
|
|
|
2904 |
#var_dump($oriColumnInfo);
|
| 226 |
liveuser |
2905 |
|
| 3 |
liveuser |
2906 |
#如果沒有定新的欄位明稱
|
|
|
2907 |
if(!isset($conf["newColumnName"])){
|
| 226 |
liveuser |
2908 |
|
| 3 |
liveuser |
2909 |
#則設定為原始欄位的名稱
|
|
|
2910 |
$conf["newColumnName"]=$oriColumnInfo["columnName"][$conf["editedColumnName"]];
|
| 226 |
liveuser |
2911 |
|
| 3 |
liveuser |
2912 |
}#if end
|
| 226 |
liveuser |
2913 |
|
|
|
2914 |
#如果 $conf["newDataTableColmunType"] 沒有設定
|
| 3 |
liveuser |
2915 |
if(!isset($conf["newDataTableColmunType"])){
|
| 226 |
liveuser |
2916 |
|
| 3 |
liveuser |
2917 |
#$oriColumnInfo["columnVarTypeAndLengthLimit"][$conf["editedColumnName"]];
|
| 226 |
liveuser |
2918 |
|
| 3 |
liveuser |
2919 |
#則設定為原始欄位的儲存型態
|
|
|
2920 |
$conf["newDataTableColmunType"]=$oriColumnInfo["columnVarType"][$conf["editedColumnName"]];
|
| 226 |
liveuser |
2921 |
|
| 3 |
liveuser |
2922 |
}#if end
|
| 226 |
liveuser |
2923 |
|
| 3 |
liveuser |
2924 |
#以下要檢查
|
| 226 |
liveuser |
2925 |
|
| 3 |
liveuser |
2926 |
#如果新資料型態不等於 "tinytext" 跟 "text"
|
|
|
2927 |
if($conf["newDataTableColmunType"]!="tinytext" && $conf["newDataTableColmunType"]!="text"){
|
| 226 |
liveuser |
2928 |
|
| 3 |
liveuser |
2929 |
#如果沒有設定 $conf["newDataTableColmunLength"]
|
|
|
2930 |
if(!isset($conf["newDataTableColmunLength"])){
|
| 226 |
liveuser |
2931 |
|
| 3 |
liveuser |
2932 |
#則設定為原始欄位的儲存長度
|
|
|
2933 |
$conf["newDataTableColmunLength"]=$oriColumnInfo["columnVarLengthLimit"][$conf["editedColumnName"]];
|
| 226 |
liveuser |
2934 |
|
| 3 |
liveuser |
2935 |
}#if end
|
| 226 |
liveuser |
2936 |
|
| 3 |
liveuser |
2937 |
#如果 $conf["newDataTableColmunLength"] 不為 ""
|
|
|
2938 |
if($conf["newDataTableColmunLength"]!=""){
|
| 226 |
liveuser |
2939 |
|
| 3 |
liveuser |
2940 |
#則加上 「(」與「)」
|
|
|
2941 |
$conf["newDataTableColmunLength"]="(".$conf["newDataTableColmunLength"].")";
|
| 226 |
liveuser |
2942 |
|
| 3 |
liveuser |
2943 |
#屬性後面加上長度
|
|
|
2944 |
$conf["newDataTableColmunType"]=$conf["newDataTableColmunType"].$conf["newDataTableColmunLength"];
|
| 226 |
liveuser |
2945 |
|
| 3 |
liveuser |
2946 |
}#if end
|
| 226 |
liveuser |
2947 |
|
| 3 |
liveuser |
2948 |
}#if end
|
| 226 |
liveuser |
2949 |
|
| 3 |
liveuser |
2950 |
#如果 $conf["newDataTableColmunDefault"] 不存在
|
|
|
2951 |
if(!isset($conf["newDataTableColmunDefault"])){
|
| 226 |
liveuser |
2952 |
|
| 3 |
liveuser |
2953 |
#則設定為原始欄位的預設數值
|
|
|
2954 |
$conf["newDataTableColmunDefault"]="default \"".$oriColumnInfo["columnDefault"][$conf["editedColumnName"]]."\"";
|
| 226 |
liveuser |
2955 |
|
| 3 |
liveuser |
2956 |
#如果 $oriColumnInfo["columnDefault"][$conf["editedColumnName"]] 為 ""
|
|
|
2957 |
if($oriColumnInfo["columnDefault"][$conf["editedColumnName"]]==""){
|
| 226 |
liveuser |
2958 |
|
| 3 |
liveuser |
2959 |
#則將 $conf["newDataTableColmunDefault"] 設為
|
|
|
2960 |
$conf["newDataTableColmunDefault"]="";
|
| 226 |
liveuser |
2961 |
|
| 3 |
liveuser |
2962 |
}#if end
|
| 226 |
liveuser |
2963 |
|
| 3 |
liveuser |
2964 |
#如果 $oriColumnInfo["columnDefault"][$conf["editedColumnName"]] 為 "NULL"
|
|
|
2965 |
if($oriColumnInfo["columnDefault"][$conf["editedColumnName"]]=="NULL"){
|
| 226 |
liveuser |
2966 |
|
| 3 |
liveuser |
2967 |
#則將 $conf["newDataTableColmunDefault"] 設為
|
|
|
2968 |
$conf["newDataTableColmunDefault"]="";
|
| 226 |
liveuser |
2969 |
|
| 3 |
liveuser |
2970 |
}#if end
|
| 226 |
liveuser |
2971 |
|
| 3 |
liveuser |
2972 |
#如果 $oriColumnInfo["columnDefault"][$conf["editedColumnName"]] 為 "沒有指定"
|
|
|
2973 |
if($oriColumnInfo["columnDefault"][$conf["editedColumnName"]]=="沒有指定"){
|
| 226 |
liveuser |
2974 |
|
| 3 |
liveuser |
2975 |
#則將 $conf["newDataTableColmunDefault"] 設為
|
|
|
2976 |
$conf["newDataTableColmunDefault"]="";
|
| 226 |
liveuser |
2977 |
|
| 3 |
liveuser |
2978 |
}#if end
|
| 226 |
liveuser |
2979 |
|
| 3 |
liveuser |
2980 |
}#if end
|
| 226 |
liveuser |
2981 |
|
| 3 |
liveuser |
2982 |
#反之有設定 $conf["newDataTableColmunDefault"]
|
|
|
2983 |
else{
|
| 226 |
liveuser |
2984 |
|
| 3 |
liveuser |
2985 |
#當 $conf["newDataTableColmunType"] 不等於 "text" 與 "tinytest" 時,才能用預設值。
|
|
|
2986 |
if($conf["newDataTableColmunType"]!="text" && $conf["newDataTableColmunType"]!="tinytest" ){
|
| 226 |
liveuser |
2987 |
|
| 3 |
liveuser |
2988 |
#判斷 $conf["newDataTableColmunDefault"] 的數值
|
|
|
2989 |
#currentTime,當前時間;
|
|
|
2990 |
#updatedCurrentTime,初始為當前時間,之後每更動一次就更新為當次時間
|
|
|
2991 |
#null,代表空值
|
|
|
2992 |
#以外的內容視為指定的數值
|
|
|
2993 |
switch($conf["newDataTableColmunDefault"]){
|
| 226 |
liveuser |
2994 |
|
| 3 |
liveuser |
2995 |
#如果是
|
|
|
2996 |
case "currentTime":
|
| 226 |
liveuser |
2997 |
|
| 3 |
liveuser |
2998 |
#則將 $conf["newDataTableColmunDefault"] 設為 " default CURRENT_TIMESTAMP "
|
|
|
2999 |
$conf["newDataTableColmunDefault"]=" default CURRENT_TIMESTAMP ";
|
| 226 |
liveuser |
3000 |
|
|
|
3001 |
#跳出 switch
|
| 3 |
liveuser |
3002 |
break;
|
| 226 |
liveuser |
3003 |
|
| 3 |
liveuser |
3004 |
#如果是 "updatedCurrentTime"
|
|
|
3005 |
case "updatedCurrentTime":
|
| 226 |
liveuser |
3006 |
|
| 3 |
liveuser |
3007 |
#則將 $conf["newDataTableColmunDefault"] 設為 " default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP "
|
|
|
3008 |
$conf["newDataTableColmunDefault"]=" default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP ";
|
| 226 |
liveuser |
3009 |
|
|
|
3010 |
#跳出 switch
|
| 3 |
liveuser |
3011 |
break;
|
| 226 |
liveuser |
3012 |
|
| 3 |
liveuser |
3013 |
#如果是 "null"
|
|
|
3014 |
case "null":
|
| 226 |
liveuser |
3015 |
|
| 3 |
liveuser |
3016 |
#則將 $conf["newDataTableColmunDefault"] 設為 " default null "
|
|
|
3017 |
$conf["newDataTableColmunDefault"]=" default null ";
|
| 226 |
liveuser |
3018 |
|
|
|
3019 |
#跳出 switch
|
| 3 |
liveuser |
3020 |
break;
|
| 226 |
liveuser |
3021 |
|
| 3 |
liveuser |
3022 |
#如果是 "NULL"
|
|
|
3023 |
case "NULL":
|
| 226 |
liveuser |
3024 |
|
| 3 |
liveuser |
3025 |
#則將 $conf["newDataTableColmunDefault"] 設為 " default null "
|
|
|
3026 |
$conf["newDataTableColmunDefault"]=" default NULL ";
|
| 226 |
liveuser |
3027 |
|
|
|
3028 |
#跳出 switch
|
| 3 |
liveuser |
3029 |
break;
|
| 226 |
liveuser |
3030 |
|
| 3 |
liveuser |
3031 |
#如果是 ""
|
|
|
3032 |
case "":
|
| 226 |
liveuser |
3033 |
|
| 3 |
liveuser |
3034 |
#則代表不設定預設值
|
|
|
3035 |
$conf["newDataTableColmunDefault"]="";
|
|
|
3036 |
|
|
|
3037 |
break;
|
| 226 |
liveuser |
3038 |
|
|
|
3039 |
#如果為其他內容
|
| 3 |
liveuser |
3040 |
default :
|
| 226 |
liveuser |
3041 |
|
| 3 |
liveuser |
3042 |
#套用自訂的預設值
|
| 226 |
liveuser |
3043 |
$conf["newDataTableColmunDefault"]=" default '".$conf["newDataTableColmunDefault"]."'";
|
|
|
3044 |
|
| 3 |
liveuser |
3045 |
}#switch end
|
| 226 |
liveuser |
3046 |
|
| 3 |
liveuser |
3047 |
}#if end
|
| 226 |
liveuser |
3048 |
|
| 3 |
liveuser |
3049 |
}#else end
|
| 226 |
liveuser |
3050 |
|
| 3 |
liveuser |
3051 |
#如果 $conf["newDataTableColmunNotNull"] 沒有設定
|
|
|
3052 |
if(!isset($conf["newDataTableColmunNotNull"])){
|
| 226 |
liveuser |
3053 |
|
| 3 |
liveuser |
3054 |
#則按照原始欄位的設定
|
| 226 |
liveuser |
3055 |
|
| 3 |
liveuser |
3056 |
#如果 $oriColumnInfo["columnNotNull"][$conf["editedColumnName"]] 等於 "true"
|
|
|
3057 |
if($oriColumnInfo["columnNotNull"][$conf["editedColumnName"]]=="true"){
|
| 226 |
liveuser |
3058 |
|
| 3 |
liveuser |
3059 |
#則代表不能為 null
|
|
|
3060 |
$conf["newDataTableColmunNotNull"]=" not null";
|
| 226 |
liveuser |
3061 |
|
| 3 |
liveuser |
3062 |
}#if end
|
| 226 |
liveuser |
3063 |
|
| 3 |
liveuser |
3064 |
#反之 $oriColumnInfo["columnNotNull"][$conf["editedColumnName"]] 等於 "false"
|
|
|
3065 |
else{
|
| 226 |
liveuser |
3066 |
|
| 3 |
liveuser |
3067 |
#則代表可以為 null
|
|
|
3068 |
#將 $conf["newDataTableColmunNotNull"] 置換為 ""
|
|
|
3069 |
$conf["newDataTableColmunNotNull"]="";
|
| 226 |
liveuser |
3070 |
|
| 3 |
liveuser |
3071 |
}#if end
|
| 226 |
liveuser |
3072 |
|
| 3 |
liveuser |
3073 |
}#if end
|
| 226 |
liveuser |
3074 |
|
| 3 |
liveuser |
3075 |
#反之 如果 $conf["newDataTableColmunNotNull"] 有設定
|
|
|
3076 |
else{
|
| 226 |
liveuser |
3077 |
|
| 3 |
liveuser |
3078 |
#如果 $conf["newDataTableColmunNotNull"] 為 "true"
|
|
|
3079 |
if($conf["newDataTableColmunNotNull"]=="true"){
|
| 226 |
liveuser |
3080 |
|
| 3 |
liveuser |
3081 |
#則置換為 "not null"
|
|
|
3082 |
$conf["newDataTableColmunNotNull"]="not null";
|
| 226 |
liveuser |
3083 |
|
| 3 |
liveuser |
3084 |
}#if end
|
| 226 |
liveuser |
3085 |
|
| 3 |
liveuser |
3086 |
#如果 $conf["newDataTableColmunNotNull"] 為 "false"
|
|
|
3087 |
if($conf["newDataTableColmunNotNull"]=="false"){
|
| 226 |
liveuser |
3088 |
|
| 3 |
liveuser |
3089 |
#則置換為 ""
|
|
|
3090 |
$conf["newDataTableColmunNotNull"]="";
|
| 226 |
liveuser |
3091 |
|
| 3 |
liveuser |
3092 |
}#if end
|
| 226 |
liveuser |
3093 |
|
| 3 |
liveuser |
3094 |
}#else end
|
| 226 |
liveuser |
3095 |
|
| 3 |
liveuser |
3096 |
#如果 $conf["newDataTableColmunAutoAdd"] 沒有設定
|
|
|
3097 |
if(!isset($conf["newDataTableColmunAutoAdd"])){
|
| 226 |
liveuser |
3098 |
|
| 3 |
liveuser |
3099 |
#原始欄位的設定為 true 的話
|
|
|
3100 |
if($oriColumnInfo["columnAutoIncrement"][$conf["editedColumnName"]]=="true"){
|
| 226 |
liveuser |
3101 |
|
| 3 |
liveuser |
3102 |
#則按照原始欄位的設定
|
|
|
3103 |
$conf["newDataTableColmunAutoAdd"]="auto_increment";
|
| 226 |
liveuser |
3104 |
|
| 3 |
liveuser |
3105 |
}#if end
|
| 226 |
liveuser |
3106 |
|
| 3 |
liveuser |
3107 |
#反之代表沒有設定
|
|
|
3108 |
else{
|
| 226 |
liveuser |
3109 |
|
| 3 |
liveuser |
3110 |
#設為 ""
|
|
|
3111 |
$conf["newDataTableColmunAutoAdd"]="";
|
| 226 |
liveuser |
3112 |
|
| 3 |
liveuser |
3113 |
}#else end
|
| 226 |
liveuser |
3114 |
|
| 3 |
liveuser |
3115 |
}#if end
|
| 226 |
liveuser |
3116 |
|
| 3 |
liveuser |
3117 |
#反之代表 $conf["newDataTableColmunAutoAdd"] 有設定
|
|
|
3118 |
else{
|
| 226 |
liveuser |
3119 |
|
| 3 |
liveuser |
3120 |
#如果 $conf["newDataTableColmunAutoAdd"] 等於 "true"
|
|
|
3121 |
if($conf["newDataTableColmunAutoAdd"]=="true"){
|
| 226 |
liveuser |
3122 |
|
| 3 |
liveuser |
3123 |
#則將 $conf["newDataTableColmunAutoAdd"] 設為 auto_increment
|
|
|
3124 |
$conf["newDataTableColmunAutoAdd"]="auto_increment";
|
| 226 |
liveuser |
3125 |
|
| 3 |
liveuser |
3126 |
}#if end
|
| 226 |
liveuser |
3127 |
|
| 3 |
liveuser |
3128 |
#反之 $conf["newDataTableColmunAutoAdd"] 不等於 "true"
|
|
|
3129 |
else{
|
| 226 |
liveuser |
3130 |
|
| 3 |
liveuser |
3131 |
#則將 $conf["newDataTableColmunAutoAdd"] 設為 ""
|
|
|
3132 |
$conf["newDataTableColmunAutoAdd"]="";
|
| 226 |
liveuser |
3133 |
|
|
|
3134 |
}#else end
|
|
|
3135 |
|
| 3 |
liveuser |
3136 |
}#else end
|
| 226 |
liveuser |
3137 |
|
|
|
3138 |
#如果 $conf["newDataTableColmunType"] 為 "char" 或 "text"
|
| 3 |
liveuser |
3139 |
if($conf["newDataTableColmunType"]=="char" || $conf["newDataTableColmunType"]=="text"){
|
| 226 |
liveuser |
3140 |
|
| 3 |
liveuser |
3141 |
#CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci',設定為utf8
|
|
|
3142 |
$utf8="CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci'";
|
| 226 |
liveuser |
3143 |
|
| 3 |
liveuser |
3144 |
}#if end
|
| 226 |
liveuser |
3145 |
|
| 3 |
liveuser |
3146 |
#反之不是字元或文字
|
|
|
3147 |
else{
|
| 226 |
liveuser |
3148 |
|
| 3 |
liveuser |
3149 |
#則設為""
|
|
|
3150 |
$utf8="";
|
| 226 |
liveuser |
3151 |
|
|
|
3152 |
}#else end
|
|
|
3153 |
|
| 3 |
liveuser |
3154 |
#如果有設定 $conf["newDataTableColmunComment"]
|
|
|
3155 |
if(isset($conf["newDataTableColmunComment"])){
|
| 226 |
liveuser |
3156 |
|
| 3 |
liveuser |
3157 |
#如果 $conf["newDataTableColmunComment"] 等於 ""
|
|
|
3158 |
if($conf["newDataTableColmunComment"]==""){
|
| 226 |
liveuser |
3159 |
|
| 3 |
liveuser |
3160 |
#設置為"沒有註解"
|
|
|
3161 |
$comment=" COMMENT '沒有註解'";
|
| 226 |
liveuser |
3162 |
|
| 3 |
liveuser |
3163 |
}#if end
|
| 226 |
liveuser |
3164 |
|
| 3 |
liveuser |
3165 |
#反之設置指定的註解字串
|
|
|
3166 |
else{
|
| 226 |
liveuser |
3167 |
|
| 3 |
liveuser |
3168 |
#設置註解
|
|
|
3169 |
$comment=" COMMENT '".$conf["newDataTableColmunComment"]."'";
|
| 226 |
liveuser |
3170 |
|
| 3 |
liveuser |
3171 |
}#else end
|
| 226 |
liveuser |
3172 |
|
| 3 |
liveuser |
3173 |
}#if end
|
| 226 |
liveuser |
3174 |
|
| 3 |
liveuser |
3175 |
#反之
|
|
|
3176 |
else{
|
| 226 |
liveuser |
3177 |
|
| 3 |
liveuser |
3178 |
#如果原始沒有註解
|
|
|
3179 |
if(!isset($oriColumnInfo["colmunComment"][$conf["editedColumnName"]])){
|
| 226 |
liveuser |
3180 |
|
| 3 |
liveuser |
3181 |
#設為空字串
|
|
|
3182 |
$comment="";
|
| 226 |
liveuser |
3183 |
|
| 3 |
liveuser |
3184 |
}#if end
|
| 226 |
liveuser |
3185 |
|
| 3 |
liveuser |
3186 |
#反之
|
|
|
3187 |
else{
|
| 226 |
liveuser |
3188 |
|
| 3 |
liveuser |
3189 |
#設為原始的註解
|
|
|
3190 |
$comment=" COMMENT '".$oriColumnInfo["colmunComment"][$conf["editedColumnName"]]."'";
|
| 226 |
liveuser |
3191 |
|
| 3 |
liveuser |
3192 |
}#else end
|
| 226 |
liveuser |
3193 |
|
|
|
3194 |
}#else end
|
|
|
3195 |
|
| 3 |
liveuser |
3196 |
#組合sql語法
|
|
|
3197 |
$sql="alter table ".$conf["selectedDataBaseName"].".".$conf["selectedDataTableName"]." change `".$conf["editedColumnName"]."` `".$conf["newColumnName"]."` ".$conf["newDataTableColmunType"]." ".$utf8." ".$conf["newDataTableColmunDefault"]." ".$conf["newDataTableColmunNotNull"]." ".$conf["newDataTableColmunAutoAdd"]." ".$comment." ;";
|
| 226 |
liveuser |
3198 |
|
| 3 |
liveuser |
3199 |
#執行 sql 語法
|
|
|
3200 |
#函式說明:
|
|
|
3201 |
#執行mysql指令
|
|
|
3202 |
#回傳結果::
|
|
|
3203 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
3204 |
#$result["error"],錯誤訊息的陣列
|
|
|
3205 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
3206 |
#$result["queryString"],mysql查詢的語言
|
|
|
3207 |
#查詢號的解果,需要解析。
|
|
|
3208 |
#必填參數:
|
|
|
3209 |
$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3210 |
$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3211 |
$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
|
| 226 |
liveuser |
3212 |
#可省略參數:
|
|
|
3213 |
|
| 3 |
liveuser |
3214 |
#如果有設定連線密碼
|
|
|
3215 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
3216 |
|
| 3 |
liveuser |
3217 |
$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
3218 |
|
| 3 |
liveuser |
3219 |
}#if end
|
| 226 |
liveuser |
3220 |
|
|
|
3221 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
3222 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
3223 |
|
| 3 |
liveuser |
3224 |
#設定 $conf["dbPort"]
|
|
|
3225 |
$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
3226 |
|
|
|
3227 |
}#if end
|
|
|
3228 |
|
| 3 |
liveuser |
3229 |
$sqlExecResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
|
|
|
3230 |
unset($conf["db"]["execMysqlQuery"]);
|
| 226 |
liveuser |
3231 |
|
| 3 |
liveuser |
3232 |
#如果執行 sql 語法錯誤
|
|
|
3233 |
if($sqlExecResult["status"]=="false"){
|
| 226 |
liveuser |
3234 |
|
| 3 |
liveuser |
3235 |
#設定執行失敗的識別
|
|
|
3236 |
$result["status"]="false";
|
| 226 |
liveuser |
3237 |
|
| 3 |
liveuser |
3238 |
#設定錯誤訊息
|
|
|
3239 |
$result["error"]=$sqlExecResult;
|
| 226 |
liveuser |
3240 |
|
| 3 |
liveuser |
3241 |
#回傳結果
|
|
|
3242 |
return $result;
|
| 226 |
liveuser |
3243 |
|
| 3 |
liveuser |
3244 |
}#if end
|
| 226 |
liveuser |
3245 |
|
| 3 |
liveuser |
3246 |
#取得執行的sql語法
|
|
|
3247 |
$result["sql"][]=$sqlExecResult["queryString"];
|
| 226 |
liveuser |
3248 |
|
| 3 |
liveuser |
3249 |
#如果 $conf["newDataTableColmunKeyType"] 有設定
|
|
|
3250 |
if(isset($conf["newDataTableColmunKeyType"])){
|
| 226 |
liveuser |
3251 |
|
| 3 |
liveuser |
3252 |
#取得其key為何種
|
|
|
3253 |
#函式說明:
|
|
|
3254 |
#取得資料表所有欄位的詳細資訊
|
|
|
3255 |
#回傳的內容:
|
|
|
3256 |
#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
|
|
|
3257 |
#$result["error"],錯誤訊息陣列
|
|
|
3258 |
#$result["sql"],執行的sql語法
|
|
|
3259 |
#$result["oriInput"],原始的資料表欄位資訊
|
|
|
3260 |
#$result["everyLine"],逐行的欄位資訊
|
|
|
3261 |
#$result["tableName"],當前查詢的資料表名稱
|
|
|
3262 |
#$result["engine"],資料表使用的儲存引擎
|
|
|
3263 |
#$result["charset"],資料表預設的編碼
|
|
|
3264 |
#$result["columnName"][$i],各欄位的名稱陣列,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3265 |
#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3266 |
#$result["columnNotNull"][$i],各欄位是否可以不爲null,"true"爲可以不爲null;"false"爲可以爲"null",$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3267 |
#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3268 |
#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3269 |
#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3270 |
#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3271 |
#$result["columnCollate"][$i],各欄位使用的Collate,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3272 |
#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
|
|
|
3273 |
#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3274 |
#$result["primaryKey"],該資料表的主鍵
|
|
|
3275 |
#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
|
|
|
3276 |
#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3277 |
#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列
|
|
|
3278 |
#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲0開始的數字
|
|
|
3279 |
#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲0開始的數字
|
|
|
3280 |
#$result["foreignKey"]["OnUpdateAction"][$l],當參照的欄位資料更新時,會怎麼同步,$l爲0開始的數字
|
|
|
3281 |
#$result["foreignKey"]["OnDeleteAction"][$m],當參照的欄位資料移除時,會怎麼同步,$m爲0開始的數字
|
|
|
3282 |
#必填參數:
|
|
|
3283 |
$conf["db"]["getTableColumnDetailInfo"]["dbAddress"]=$conf["dbAddress"];
|
|
|
3284 |
$conf["db"]["getTableColumnDetailInfo"]["dbAccount"]=$conf["dbAccount"];
|
|
|
3285 |
$conf["db"]["getTableColumnDetailInfo"]["selectedDataBase"]=$conf["selectedDataBaseName"];
|
|
|
3286 |
$conf["db"]["getTableColumnDetailInfo"]["selectedDataTable"]=$conf["selectedDataTableName"];
|
|
|
3287 |
#可省略參數:
|
| 226 |
liveuser |
3288 |
|
| 3 |
liveuser |
3289 |
#如果 $conf["dbPassword"] 有設定
|
|
|
3290 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
3291 |
|
| 3 |
liveuser |
3292 |
#套用連限時的密碼
|
|
|
3293 |
$conf["db"]["getTableColumnDetailInfo"]["dbPassword"]=$conf["dbPassword"];
|
| 226 |
liveuser |
3294 |
|
| 3 |
liveuser |
3295 |
}#if end
|
| 226 |
liveuser |
3296 |
|
|
|
3297 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
3298 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
3299 |
|
| 3 |
liveuser |
3300 |
#設定 $conf["dbPort"]
|
|
|
3301 |
$conf["db"]["getTableColumnDetailInfo"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
3302 |
|
|
|
3303 |
}#if end
|
|
|
3304 |
|
| 3 |
liveuser |
3305 |
$tableColumnDetial=db::getTableColumnDetailInfo($conf["db"]["getTableColumnDetailInfo"]);
|
|
|
3306 |
unset($conf["db"]["getTableColumnDetailInfo"]);#卸除變數,避免錯誤產生.
|
| 226 |
liveuser |
3307 |
|
| 3 |
liveuser |
3308 |
#如果取得資料表結構失敗
|
|
|
3309 |
if($tableColumnDetial["status"]=="false"){
|
| 226 |
liveuser |
3310 |
|
| 3 |
liveuser |
3311 |
#設置執行不正常
|
|
|
3312 |
$result["status"]="false";
|
| 226 |
liveuser |
3313 |
|
| 3 |
liveuser |
3314 |
#設置執行錯誤訊息
|
|
|
3315 |
$result["error"]=$tableColumnDetial;
|
| 226 |
liveuser |
3316 |
|
| 3 |
liveuser |
3317 |
#回傳結果
|
|
|
3318 |
return $result;
|
| 226 |
liveuser |
3319 |
|
| 3 |
liveuser |
3320 |
}#if end
|
| 226 |
liveuser |
3321 |
|
| 3 |
liveuser |
3322 |
#判斷 $conf["newDataTableColmunKeyType"] 來進行處理
|
|
|
3323 |
#"index"爲索引鍵,"foreign key"為外鍵,""為將鍵屬性取消。
|
|
|
3324 |
switch($conf["newDataTableColmunKeyType"]){
|
| 226 |
liveuser |
3325 |
|
| 3 |
liveuser |
3326 |
#如果 $conf["newDataTableColmunKeyType"] 是 ""
|
|
|
3327 |
case "":
|
| 226 |
liveuser |
3328 |
|
| 3 |
liveuser |
3329 |
#檢查目標欄位是主鍵或是索引鍵或是外鍵
|
| 226 |
liveuser |
3330 |
|
|
|
3331 |
#debug
|
| 3 |
liveuser |
3332 |
#var_dump($tableColumnDetial);
|
| 226 |
liveuser |
3333 |
|
| 3 |
liveuser |
3334 |
#如果 $tableColumnDetial["foreignKey"]["exist"] 等於 "true",代表有外鍵
|
|
|
3335 |
if($tableColumnDetial["foreignKey"]["exist"]=="true"){
|
| 226 |
liveuser |
3336 |
|
| 3 |
liveuser |
3337 |
#如果 $tableColumnDetial["foreignKey"]["columnName"][$conf["dbInformation"]["newColumnName"]] 存在,則代表該欄位為索引鍵
|
|
|
3338 |
if(isset($tableColumnDetial["foreignKey"]["columnName"][$conf["newColumnName"]])){
|
| 226 |
liveuser |
3339 |
|
| 3 |
liveuser |
3340 |
#移除外鍵
|
|
|
3341 |
#函式說明:
|
|
|
3342 |
#移除資料表單1欄位的外鍵
|
|
|
3343 |
#回傳結果:
|
|
|
3344 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗
|
|
|
3345 |
#$result["error"],錯誤訊息陣列
|
|
|
3346 |
#$result["sql"],執行的sql字串.
|
|
|
3347 |
#必填參數:
|
|
|
3348 |
$conf["db"]["eraseForeignKey"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3349 |
$conf["db"]["eraseForeignKey"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3350 |
$conf["db"]["eraseForeignKey"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
|
|
|
3351 |
$conf["db"]["eraseForeignKey"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
|
|
|
3352 |
$conf["db"]["eraseForeignKey"]["erasedForeignKeyColumnConstraintName"]=$tableColumnDetial["foreignKey"]["constraintName"][$conf["newColumnName"]];#要移除外鍵欄位的CONSTRAINT名稱
|
| 226 |
liveuser |
3353 |
#可省略參數:
|
|
|
3354 |
|
| 3 |
liveuser |
3355 |
#如果 $conf["dbPassword"] 存在
|
|
|
3356 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
3357 |
|
| 3 |
liveuser |
3358 |
#則設定連線的密碼
|
|
|
3359 |
$conf["db"]["eraseForeignKey"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
3360 |
|
| 3 |
liveuser |
3361 |
}#if end
|
| 226 |
liveuser |
3362 |
|
|
|
3363 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
3364 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
3365 |
|
| 3 |
liveuser |
3366 |
#設定 $conf["dbPort"]
|
|
|
3367 |
$conf["db"]["eraseForeignKey"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
3368 |
|
|
|
3369 |
}#if end
|
|
|
3370 |
|
| 3 |
liveuser |
3371 |
$eraseForeignKeyResult=db::eraseForeignKey($conf["db"]["eraseForeignKey"]);
|
|
|
3372 |
unset($conf["db"]["eraseForeignKey"]);
|
| 226 |
liveuser |
3373 |
|
| 3 |
liveuser |
3374 |
#取得執行的sql字串
|
|
|
3375 |
$result["sql"][]=$eraseForeignKeyResult["sql"];
|
| 226 |
liveuser |
3376 |
|
| 3 |
liveuser |
3377 |
#如果 $eraseForeignKeyResult["status"]等於"fasle"
|
|
|
3378 |
if($eraseForeignKeyResult["status"]=="false"){
|
| 226 |
liveuser |
3379 |
|
| 3 |
liveuser |
3380 |
#設置出錯的識別
|
|
|
3381 |
$result["status"]="fasle";
|
| 226 |
liveuser |
3382 |
|
| 3 |
liveuser |
3383 |
#設置錯誤訊息
|
|
|
3384 |
$result["error"]=$eraseForeignKeyResult;
|
| 226 |
liveuser |
3385 |
|
| 3 |
liveuser |
3386 |
#回傳結果
|
|
|
3387 |
return $result;
|
| 226 |
liveuser |
3388 |
|
| 3 |
liveuser |
3389 |
}#if end
|
| 226 |
liveuser |
3390 |
|
| 3 |
liveuser |
3391 |
}#if end
|
| 226 |
liveuser |
3392 |
|
| 3 |
liveuser |
3393 |
}#if end
|
| 226 |
liveuser |
3394 |
|
| 3 |
liveuser |
3395 |
#如果 $tableColumnDetial["key"]["exist"] 等於 "true",代表有索引鍵
|
|
|
3396 |
if($tableColumnDetial["key"]["exist"]=="true"){
|
| 226 |
liveuser |
3397 |
|
| 3 |
liveuser |
3398 |
#如果 $tableColumnDetial["key"][$conf["newColumnName"]] 存在,則代表該欄位為索引鍵
|
|
|
3399 |
if(isset($tableColumnDetial["key"][$conf["newColumnName"]])){
|
| 226 |
liveuser |
3400 |
|
| 3 |
liveuser |
3401 |
#移除索引鍵
|
|
|
3402 |
#函式說明:
|
|
|
3403 |
#移除資料表單1欄位的索引鍵
|
|
|
3404 |
#回傳結果:
|
|
|
3405 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗
|
|
|
3406 |
#$result["error"],錯誤訊息陣列
|
|
|
3407 |
#$result["sql"],執行的sql字串.
|
|
|
3408 |
#必填參數:
|
|
|
3409 |
$conf["db"]["eraseIndexKey"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3410 |
$conf["db"]["eraseIndexKey"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3411 |
$conf["db"]["eraseIndexKey"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
|
|
|
3412 |
$conf["db"]["eraseIndexKey"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料表
|
|
|
3413 |
$conf["db"]["eraseIndexKey"]["erasedIndexKeyColumnConstraintName"]=$tableColumnDetial["keyConstraintName"][$conf["newColumnName"]];#要移除外鍵欄位的CONSTRAINT名稱
|
|
|
3414 |
#可省略參數:
|
| 226 |
liveuser |
3415 |
|
| 3 |
liveuser |
3416 |
#如果 $conf["dbPassword"] 存在
|
|
|
3417 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
3418 |
|
| 3 |
liveuser |
3419 |
#則設定連線的密碼
|
|
|
3420 |
$conf["db"]["eraseIndexKey"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
3421 |
|
| 3 |
liveuser |
3422 |
}#if end
|
| 226 |
liveuser |
3423 |
|
|
|
3424 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
3425 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
3426 |
|
| 3 |
liveuser |
3427 |
#設定 $conf["dbPort"]
|
|
|
3428 |
$conf["db"]["eraseIndexKey"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
3429 |
|
|
|
3430 |
}#if end
|
|
|
3431 |
|
| 3 |
liveuser |
3432 |
$eraseIndexKeyResult=db::eraseIndexKey($conf["db"]["eraseIndexKey"]);
|
|
|
3433 |
#var_dump($conf["db"]["eraseIndexKey"]);
|
|
|
3434 |
unset($conf["db"]);
|
| 226 |
liveuser |
3435 |
|
| 3 |
liveuser |
3436 |
#debug
|
|
|
3437 |
#var_dump($eraseIndexKeyResult);
|
| 226 |
liveuser |
3438 |
|
| 3 |
liveuser |
3439 |
#取得執行的sql語言
|
|
|
3440 |
$result["sql"][]=$eraseIndexKeyResult["sql"];
|
| 226 |
liveuser |
3441 |
|
| 3 |
liveuser |
3442 |
#如果 $eraseIndexKeyResult["status"]等於"fasle"
|
|
|
3443 |
if($eraseIndexKeyResult["status"]=="false"){
|
| 226 |
liveuser |
3444 |
|
| 3 |
liveuser |
3445 |
#設置出錯的識別
|
|
|
3446 |
$result["status"]="false";
|
| 226 |
liveuser |
3447 |
|
| 3 |
liveuser |
3448 |
#設置錯誤訊息
|
|
|
3449 |
$result["error"]=$eraseIndexKeyResult;
|
| 226 |
liveuser |
3450 |
|
| 3 |
liveuser |
3451 |
#回傳結果
|
|
|
3452 |
return $result;
|
| 226 |
liveuser |
3453 |
|
| 3 |
liveuser |
3454 |
}#if end
|
| 226 |
liveuser |
3455 |
|
| 3 |
liveuser |
3456 |
}#if end
|
| 226 |
liveuser |
3457 |
|
| 3 |
liveuser |
3458 |
}#if end
|
| 226 |
liveuser |
3459 |
|
| 3 |
liveuser |
3460 |
#中斷switch
|
|
|
3461 |
break;
|
| 226 |
liveuser |
3462 |
|
| 3 |
liveuser |
3463 |
#如果 $conf["newDataTableColmunKeyType"] 是 "index"
|
|
|
3464 |
case "index":
|
| 226 |
liveuser |
3465 |
|
| 3 |
liveuser |
3466 |
#如果 $tableColumnDetial["foreignKey"]["exist"] 等於 "true",代表有外鍵
|
|
|
3467 |
if($tableColumnDetial["foreignKey"]["exist"]=="true"){
|
| 226 |
liveuser |
3468 |
|
| 3 |
liveuser |
3469 |
#echo "have foreign key";
|
| 226 |
liveuser |
3470 |
|
| 3 |
liveuser |
3471 |
#如果 $tableColumnDetial["foreignKey"]["columnName"][$conf["newColumnName"]] 存在,則代表該欄位為索引鍵
|
|
|
3472 |
if(isset($tableColumnDetial["foreignKey"]["columnName"][$conf["newColumnName"]])){
|
| 226 |
liveuser |
3473 |
|
| 3 |
liveuser |
3474 |
#移除外鍵
|
|
|
3475 |
#函式說明:
|
|
|
3476 |
#移除資料表單1欄位的外鍵
|
|
|
3477 |
#回傳結果:
|
|
|
3478 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗
|
|
|
3479 |
#$result["error"],錯誤訊息陣列
|
|
|
3480 |
#必填參數:
|
|
|
3481 |
$conf["db"]["eraseForeignKey"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3482 |
$conf["db"]["eraseForeignKey"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3483 |
$conf["db"]["eraseForeignKey"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
|
|
|
3484 |
$conf["db"]["eraseForeignKey"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
|
|
|
3485 |
$conf["db"]["eraseForeignKey"]["erasedForeignKeyColumnConstraintName"]=$tableColumnDetial["foreignKey"]["constraintName"][$conf["newColumnName"]];#要移除外鍵欄位的CONSTRAINT名稱
|
| 226 |
liveuser |
3486 |
#可省略參數:
|
|
|
3487 |
|
| 3 |
liveuser |
3488 |
#如果 $conf["dbPassword"] 存在
|
|
|
3489 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
3490 |
|
| 3 |
liveuser |
3491 |
#則設定連線的密碼
|
|
|
3492 |
$conf["db"]["eraseForeignKey"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
3493 |
|
| 3 |
liveuser |
3494 |
}#if end
|
| 226 |
liveuser |
3495 |
|
|
|
3496 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
3497 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
3498 |
|
| 3 |
liveuser |
3499 |
#設定 $conf["dbPort"]
|
|
|
3500 |
$conf["db"]["eraseForeignKey"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
3501 |
|
|
|
3502 |
}#if end
|
|
|
3503 |
|
| 3 |
liveuser |
3504 |
$eraseForeignKeyResult=db::eraseForeignKey($conf["db"]["eraseForeignKey"]);
|
|
|
3505 |
unset($conf["db"]["eraseForeignKey"]);
|
| 226 |
liveuser |
3506 |
|
| 3 |
liveuser |
3507 |
#執行的sql字串
|
|
|
3508 |
$result["sql"][]=$eraseForeignKeyResult["sql"];
|
| 226 |
liveuser |
3509 |
|
| 3 |
liveuser |
3510 |
#如果 $eraseForeignKeyResult["status"]等於"fasle"
|
|
|
3511 |
if($eraseForeignKeyResult["status"]=="false"){
|
| 226 |
liveuser |
3512 |
|
| 3 |
liveuser |
3513 |
#設置出錯的識別
|
|
|
3514 |
$result["status"]="false";
|
| 226 |
liveuser |
3515 |
|
| 3 |
liveuser |
3516 |
#設置錯誤訊息
|
|
|
3517 |
$result["error"]=$eraseForeignKeyResult;
|
| 226 |
liveuser |
3518 |
|
| 3 |
liveuser |
3519 |
#回傳結果
|
|
|
3520 |
return $result;
|
| 226 |
liveuser |
3521 |
|
| 3 |
liveuser |
3522 |
}#if end
|
| 226 |
liveuser |
3523 |
|
| 3 |
liveuser |
3524 |
}#if end
|
| 226 |
liveuser |
3525 |
|
| 3 |
liveuser |
3526 |
}#if end
|
| 226 |
liveuser |
3527 |
|
| 3 |
liveuser |
3528 |
#如果 $tableColumnDetial["key"]["exist"] 等於 "true",代表有索引鍵
|
|
|
3529 |
if($tableColumnDetial["key"]["exist"]=="true"){
|
| 226 |
liveuser |
3530 |
|
| 3 |
liveuser |
3531 |
#檢查目標欄位是否為索引鍵
|
|
|
3532 |
if(!isset($tableColumnDetial["index"][$conf["newColumnName"]])){
|
| 226 |
liveuser |
3533 |
|
| 3 |
liveuser |
3534 |
#代表目標欄位不為索引鍵
|
| 226 |
liveuser |
3535 |
|
| 3 |
liveuser |
3536 |
#建立索引鍵
|
|
|
3537 |
#函式說明:
|
|
|
3538 |
#新增資料表的欄位
|
|
|
3539 |
#回傳結果:
|
|
|
3540 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗.
|
|
|
3541 |
#$result["function"],當前執行的函數名稱.
|
|
|
3542 |
#$result["error"],錯誤訊息陣列.
|
|
|
3543 |
#$result["warning"],警告訊息.
|
|
|
3544 |
#$result["sql"],執行的sql字串.
|
|
|
3545 |
#必填參數:
|
|
|
3546 |
$conf["db"]["setColumnIndex"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3547 |
$conf["db"]["setColumnIndex"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3548 |
$conf["db"]["setColumnIndex"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
|
|
|
3549 |
$conf["db"]["setColumnIndex"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
|
|
|
3550 |
$conf["db"]["setColumnIndex"]["indexedColumnName"]=$conf["newColumnName"];#要設爲index的欄位名稱
|
|
|
3551 |
#可省略參數:
|
| 226 |
liveuser |
3552 |
|
| 3 |
liveuser |
3553 |
#如果 $conf["dbPassword"] 存在
|
|
|
3554 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
3555 |
|
| 3 |
liveuser |
3556 |
#則設定連線的密碼
|
|
|
3557 |
$conf["db"]["setColumnIndex"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
3558 |
|
| 3 |
liveuser |
3559 |
}#if end
|
| 226 |
liveuser |
3560 |
|
|
|
3561 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
3562 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
3563 |
|
| 3 |
liveuser |
3564 |
#設定 $conf["dbPort"]
|
|
|
3565 |
$conf["db"]["setColumnIndex"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
3566 |
|
|
|
3567 |
}#if end
|
|
|
3568 |
|
| 3 |
liveuser |
3569 |
$setColumnIndexResult=db::setColumnIndex($conf["db"]["setColumnIndex"]);
|
|
|
3570 |
unset($conf["db"]["setColumnIndex"]);
|
| 226 |
liveuser |
3571 |
|
| 3 |
liveuser |
3572 |
#如果設置 column index 失敗
|
|
|
3573 |
if($setColumnIndexResult["status"]==="false"){
|
| 226 |
liveuser |
3574 |
|
| 3 |
liveuser |
3575 |
#設置出錯的識別
|
|
|
3576 |
$result["status"]="false";
|
| 226 |
liveuser |
3577 |
|
| 3 |
liveuser |
3578 |
#設置錯誤訊息
|
|
|
3579 |
$result["error"]=$setColumnIndexResult;
|
| 226 |
liveuser |
3580 |
|
| 3 |
liveuser |
3581 |
#回傳結果
|
|
|
3582 |
return $result;
|
| 226 |
liveuser |
3583 |
|
| 3 |
liveuser |
3584 |
}#if end
|
| 226 |
liveuser |
3585 |
|
| 3 |
liveuser |
3586 |
#如果有執行 sql
|
|
|
3587 |
if(isset($setColumnIndexResult["sql"])){
|
| 226 |
liveuser |
3588 |
|
| 3 |
liveuser |
3589 |
#取得執行的sql字串
|
|
|
3590 |
$result["sql"][]=$setColumnIndexResult["sql"];
|
| 226 |
liveuser |
3591 |
|
| 3 |
liveuser |
3592 |
}#if end
|
| 226 |
liveuser |
3593 |
|
| 3 |
liveuser |
3594 |
#如果 $setColumnIndexResult["status"] 為 "fasle"
|
|
|
3595 |
if($setColumnIndexResult["status"]=="fasle"){
|
| 226 |
liveuser |
3596 |
|
| 3 |
liveuser |
3597 |
#設置出錯的識別
|
|
|
3598 |
$result["status"]="false";
|
| 226 |
liveuser |
3599 |
|
| 3 |
liveuser |
3600 |
#設置錯誤訊息
|
|
|
3601 |
$result["error"]=$setColumnIndexResult;
|
| 226 |
liveuser |
3602 |
|
| 3 |
liveuser |
3603 |
#回傳結果
|
|
|
3604 |
return $result;
|
| 226 |
liveuser |
3605 |
|
| 3 |
liveuser |
3606 |
}#if end
|
| 226 |
liveuser |
3607 |
|
| 3 |
liveuser |
3608 |
}#if end
|
| 226 |
liveuser |
3609 |
|
| 3 |
liveuser |
3610 |
}#if end
|
| 226 |
liveuser |
3611 |
|
| 3 |
liveuser |
3612 |
#如果 $tableColumnDetial["key"]["exist"] 等於 "fasle",代表沒有索引鍵
|
|
|
3613 |
if($tableColumnDetial["key"]["exist"]=="false"){
|
| 226 |
liveuser |
3614 |
|
| 3 |
liveuser |
3615 |
#建立索引鍵
|
|
|
3616 |
#函式說明:
|
|
|
3617 |
#新增資料表的欄位
|
|
|
3618 |
#回傳結果:
|
|
|
3619 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗
|
|
|
3620 |
#$result["error"],錯誤訊息陣列
|
|
|
3621 |
#必填參數:
|
|
|
3622 |
$conf["db"]["setColumnIndex"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3623 |
$conf["db"]["setColumnIndex"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3624 |
$conf["db"]["setColumnIndex"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
|
|
|
3625 |
$conf["db"]["setColumnIndex"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
|
|
|
3626 |
$conf["db"]["setColumnIndex"]["indexedColumnName"]=$conf["newColumnName"];#要設爲index的欄位名稱
|
|
|
3627 |
#可省略參數:
|
| 226 |
liveuser |
3628 |
|
| 3 |
liveuser |
3629 |
#如果 $conf["dbPassword"] 存在
|
|
|
3630 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
3631 |
|
| 3 |
liveuser |
3632 |
#則設定連線的密碼
|
|
|
3633 |
$conf["db"]["setColumnIndex"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
3634 |
|
| 3 |
liveuser |
3635 |
}#if end
|
| 226 |
liveuser |
3636 |
|
|
|
3637 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
3638 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
3639 |
|
| 3 |
liveuser |
3640 |
#設定 $conf["dbPort"]
|
|
|
3641 |
$conf["db"]["setColumnIndex"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
3642 |
|
|
|
3643 |
}#if end
|
|
|
3644 |
|
| 3 |
liveuser |
3645 |
$setColumnIndexResult=db::setColumnIndex($conf["db"]["setColumnIndex"]);
|
|
|
3646 |
unset($conf["db"]["setColumnIndex"]);
|
| 226 |
liveuser |
3647 |
|
| 3 |
liveuser |
3648 |
#取得執行的sql字串.
|
|
|
3649 |
$result["sql"][]=$setColumnIndexResult["sql"];
|
| 226 |
liveuser |
3650 |
|
| 3 |
liveuser |
3651 |
#如果 $setColumnIndexResult["status"] 為 "fasle"
|
|
|
3652 |
if($setColumnIndexResult["status"]=="fasle"){
|
| 226 |
liveuser |
3653 |
|
| 3 |
liveuser |
3654 |
#設置出錯的識別
|
|
|
3655 |
$result["status"]="false";
|
| 226 |
liveuser |
3656 |
|
| 3 |
liveuser |
3657 |
#設置錯誤訊息
|
|
|
3658 |
$result["error"]=$setColumnIndexResult;
|
| 226 |
liveuser |
3659 |
|
| 3 |
liveuser |
3660 |
#回傳結果
|
|
|
3661 |
return $result;
|
| 226 |
liveuser |
3662 |
|
| 3 |
liveuser |
3663 |
}#if end
|
| 226 |
liveuser |
3664 |
|
| 3 |
liveuser |
3665 |
}#if end
|
| 226 |
liveuser |
3666 |
|
| 3 |
liveuser |
3667 |
#中斷switch
|
|
|
3668 |
break;
|
| 226 |
liveuser |
3669 |
|
| 3 |
liveuser |
3670 |
#如果是 foreign key
|
|
|
3671 |
case "foreign key":
|
| 226 |
liveuser |
3672 |
|
| 3 |
liveuser |
3673 |
#echo "enter foreign key";
|
| 226 |
liveuser |
3674 |
|
| 3 |
liveuser |
3675 |
#檢查該欄位是否為foreign key
|
|
|
3676 |
#如果 $tableColumnDetial["foreignKey"]["exist"] 等於 "true",代表有外鍵
|
|
|
3677 |
if($tableColumnDetial["foreignKey"]["exist"]=="true"){
|
| 226 |
liveuser |
3678 |
|
| 3 |
liveuser |
3679 |
#echo "have foreig key";
|
| 226 |
liveuser |
3680 |
|
| 3 |
liveuser |
3681 |
#如果 $tableColumnDetial["foreignKey"]["columnName"][$conf["dbInformation"]["newColumnName"]] 存在,則代表該欄位為索引鍵
|
|
|
3682 |
if(isset($tableColumnDetial["foreignKey"]["columnName"][$conf["newColumnName"]])){
|
| 226 |
liveuser |
3683 |
|
| 3 |
liveuser |
3684 |
#移除外鍵
|
|
|
3685 |
#函式說明:
|
|
|
3686 |
#移除資料表單1欄位的外鍵
|
|
|
3687 |
#回傳結果:
|
|
|
3688 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗
|
|
|
3689 |
#$result["error"],錯誤訊息陣列
|
|
|
3690 |
#必填參數:
|
|
|
3691 |
$conf["db"]["eraseForeignKey"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3692 |
$conf["db"]["eraseForeignKey"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3693 |
$conf["db"]["eraseForeignKey"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
|
|
|
3694 |
$conf["db"]["eraseForeignKey"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
|
|
|
3695 |
$conf["db"]["eraseForeignKey"]["erasedForeignKeyColumnConstraintName"]=$tableColumnDetial["foreignKey"]["constraintName"][$conf["newColumnName"]];#要移除外鍵欄位的CONSTRAINT名稱
|
| 226 |
liveuser |
3696 |
#可省略參數:
|
|
|
3697 |
|
| 3 |
liveuser |
3698 |
#如果 $conf["dbPassword"] 存在
|
|
|
3699 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
3700 |
|
| 3 |
liveuser |
3701 |
#則設定連線的密碼
|
|
|
3702 |
$conf["db"]["eraseForeignKey"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
3703 |
|
| 3 |
liveuser |
3704 |
}#if end
|
| 226 |
liveuser |
3705 |
|
|
|
3706 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
3707 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
3708 |
|
| 3 |
liveuser |
3709 |
#設定 $conf["dbPort"]
|
|
|
3710 |
$conf["db"]["eraseForeignKey"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
3711 |
|
| 3 |
liveuser |
3712 |
}#if end
|
| 226 |
liveuser |
3713 |
|
| 3 |
liveuser |
3714 |
$eraseForeignKeyResult=db::eraseForeignKey($conf["db"]["eraseForeignKey"]);
|
|
|
3715 |
unset($conf["db"]["eraseForeignKey"]);
|
| 226 |
liveuser |
3716 |
|
| 3 |
liveuser |
3717 |
#取得執行的sql字串
|
|
|
3718 |
$result["sql"][]=$eraseForeignKeyResult["sql"];
|
| 226 |
liveuser |
3719 |
|
| 3 |
liveuser |
3720 |
#如果 $eraseForeignKeyResult["status"]等於"fasle"
|
|
|
3721 |
if($eraseForeignKeyResult["status"]=="false"){
|
| 226 |
liveuser |
3722 |
|
| 3 |
liveuser |
3723 |
#設置出錯的識別
|
|
|
3724 |
$result["status"]="false";
|
| 226 |
liveuser |
3725 |
|
| 3 |
liveuser |
3726 |
#設置錯誤訊息
|
|
|
3727 |
$result["error"]=$eraseForeignKeyResult;
|
| 226 |
liveuser |
3728 |
|
| 3 |
liveuser |
3729 |
#回傳結果
|
|
|
3730 |
return $result;
|
| 226 |
liveuser |
3731 |
|
| 3 |
liveuser |
3732 |
}#if end
|
| 226 |
liveuser |
3733 |
|
| 3 |
liveuser |
3734 |
}#if end
|
| 226 |
liveuser |
3735 |
|
| 3 |
liveuser |
3736 |
}#if end
|
| 226 |
liveuser |
3737 |
|
| 3 |
liveuser |
3738 |
#檢查該欄位是否為index
|
|
|
3739 |
#如果 $tableColumnDetial["key"]["exist"] 等於 "false",代表沒有索引鍵
|
|
|
3740 |
if($tableColumnDetial["key"]["exist"]=="false"){
|
| 226 |
liveuser |
3741 |
|
| 3 |
liveuser |
3742 |
#echo "have no index";
|
| 226 |
liveuser |
3743 |
|
| 3 |
liveuser |
3744 |
#建立索引鍵
|
|
|
3745 |
#函式說明:
|
|
|
3746 |
#新增資料表的欄位
|
|
|
3747 |
#回傳結果:
|
|
|
3748 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗
|
|
|
3749 |
#$result["error"],錯誤訊息陣列
|
|
|
3750 |
#必填參數:
|
|
|
3751 |
$conf["db"]["setColumnIndex"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3752 |
$conf["db"]["setColumnIndex"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3753 |
$conf["db"]["setColumnIndex"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
|
|
|
3754 |
$conf["db"]["setColumnIndex"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
|
|
|
3755 |
$conf["db"]["setColumnIndex"]["indexedColumnName"]=$conf["newColumnName"];#要設爲index的欄位名稱
|
|
|
3756 |
#可省略參數:
|
| 226 |
liveuser |
3757 |
|
| 3 |
liveuser |
3758 |
#如果 $conf["dbPassword"] 存在
|
|
|
3759 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
3760 |
|
| 3 |
liveuser |
3761 |
#則設定連線的密碼
|
|
|
3762 |
$conf["db"]["setColumnIndex"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
3763 |
|
| 3 |
liveuser |
3764 |
}#if end
|
| 226 |
liveuser |
3765 |
|
|
|
3766 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
3767 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
3768 |
|
| 3 |
liveuser |
3769 |
#設定 $conf["dbPort"]
|
|
|
3770 |
$conf["db"]["setColumnIndex"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
3771 |
|
|
|
3772 |
}#if end
|
|
|
3773 |
|
| 3 |
liveuser |
3774 |
$setColumnIndexResult=db::setColumnIndex($conf["db"]["setColumnIndex"]);
|
|
|
3775 |
unset($conf["db"]["setColumnIndex"]);
|
| 226 |
liveuser |
3776 |
|
| 3 |
liveuser |
3777 |
#取得執行的sql字串
|
|
|
3778 |
$result["sql"][]=$setColumnIndexResult["sql"];
|
| 226 |
liveuser |
3779 |
|
| 3 |
liveuser |
3780 |
#如果 $setColumnIndexResult["status"] 為 "false"
|
|
|
3781 |
if($setColumnIndexResult["status"]=="false"){
|
| 226 |
liveuser |
3782 |
|
| 3 |
liveuser |
3783 |
#設置出錯的識別
|
|
|
3784 |
$result["status"]="false";
|
| 226 |
liveuser |
3785 |
|
| 3 |
liveuser |
3786 |
#設置錯誤訊息
|
|
|
3787 |
$result["error"]=$setColumnIndexResult;
|
| 226 |
liveuser |
3788 |
|
| 3 |
liveuser |
3789 |
#回傳結果
|
|
|
3790 |
return $result;
|
| 226 |
liveuser |
3791 |
|
| 3 |
liveuser |
3792 |
}#if end
|
| 226 |
liveuser |
3793 |
|
| 3 |
liveuser |
3794 |
}#if end
|
| 226 |
liveuser |
3795 |
|
|
|
3796 |
#反之有索引鍵
|
| 3 |
liveuser |
3797 |
#如果目標欄位不是索引鍵
|
|
|
3798 |
else if(!isset($tableColumnDetial["key"][$conf["newColumnName"]])){
|
| 226 |
liveuser |
3799 |
|
| 3 |
liveuser |
3800 |
#建立索引鍵
|
|
|
3801 |
#函式說明:
|
|
|
3802 |
#新增資料表的欄位
|
|
|
3803 |
#回傳結果:
|
|
|
3804 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗
|
|
|
3805 |
#$result["error"],錯誤訊息陣列
|
|
|
3806 |
#必填參數:
|
|
|
3807 |
$conf["db"]["setColumnIndex"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3808 |
$conf["db"]["setColumnIndex"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
3809 |
$conf["db"]["setColumnIndex"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
|
|
|
3810 |
$conf["db"]["setColumnIndex"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
|
|
|
3811 |
$conf["db"]["setColumnIndex"]["indexedColumnName"]=$conf["newColumnName"];#要設爲index的欄位名稱
|
|
|
3812 |
#可省略參數:
|
| 226 |
liveuser |
3813 |
|
| 3 |
liveuser |
3814 |
#如果 $conf["dbPassword"] 存在
|
|
|
3815 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
3816 |
|
| 3 |
liveuser |
3817 |
#則設定連線的密碼
|
|
|
3818 |
$conf["db"]["setColumnIndex"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
3819 |
|
| 3 |
liveuser |
3820 |
}#if end
|
| 226 |
liveuser |
3821 |
|
|
|
3822 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
3823 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
3824 |
|
| 3 |
liveuser |
3825 |
#設定 $conf["dbPort"]
|
|
|
3826 |
$conf["db"]["setColumnIndex"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
3827 |
|
|
|
3828 |
}#if end
|
|
|
3829 |
|
| 3 |
liveuser |
3830 |
$setColumnIndexResult=db::setColumnIndex($conf["db"]["setColumnIndex"]);
|
|
|
3831 |
unset($conf["db"]["setColumnIndex"]);
|
| 226 |
liveuser |
3832 |
|
| 3 |
liveuser |
3833 |
#取得執行的sql字串
|
|
|
3834 |
$result["sql"][]=$setColumnIndexResult["sql"];
|
| 226 |
liveuser |
3835 |
|
| 3 |
liveuser |
3836 |
#如果 $setColumnIndexResult["status"] 為 "false"
|
|
|
3837 |
if($setColumnIndexResult["status"]=="false"){
|
| 226 |
liveuser |
3838 |
|
| 3 |
liveuser |
3839 |
#設置出錯的識別
|
|
|
3840 |
$result["status"]="false";
|
| 226 |
liveuser |
3841 |
|
| 3 |
liveuser |
3842 |
#設置錯誤訊息
|
|
|
3843 |
$result["error"]=$setColumnIndexResult;
|
| 226 |
liveuser |
3844 |
|
| 3 |
liveuser |
3845 |
#回傳結果
|
|
|
3846 |
return $result;
|
| 226 |
liveuser |
3847 |
|
|
|
3848 |
}#if end
|
|
|
3849 |
|
| 3 |
liveuser |
3850 |
}#else end
|
| 226 |
liveuser |
3851 |
|
| 3 |
liveuser |
3852 |
#檢查該欄位的foreign key設定參數是否存在
|
|
|
3853 |
#函式說明:
|
|
|
3854 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
3855 |
#回傳結果:
|
|
|
3856 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
3857 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
3858 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
3859 |
#必填參數:
|
|
|
3860 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
3861 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("foreignKeyReferenceTable","foreignKeyReferenceColumn");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
3862 |
#可省略參數:
|
| 226 |
liveuser |
3863 |
#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
3864 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
3865 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
3866 |
unset($conf["variableCheck"]["isexistMuti"]);
|
| 226 |
liveuser |
3867 |
|
| 3 |
liveuser |
3868 |
#如果檢查失敗
|
|
|
3869 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
3870 |
|
| 3 |
liveuser |
3871 |
#設置執行失敗的訊息
|
|
|
3872 |
$result["status"]="false";
|
| 226 |
liveuser |
3873 |
|
| 3 |
liveuser |
3874 |
#設置錯誤訊息
|
|
|
3875 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
3876 |
|
| 3 |
liveuser |
3877 |
#回傳結果
|
|
|
3878 |
return $result;
|
| 226 |
liveuser |
3879 |
|
| 3 |
liveuser |
3880 |
}#if end
|
| 226 |
liveuser |
3881 |
|
| 3 |
liveuser |
3882 |
#如果檢查不通過
|
|
|
3883 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
3884 |
|
| 3 |
liveuser |
3885 |
#設置執行失敗的訊息
|
|
|
3886 |
$result["status"]="false";
|
| 226 |
liveuser |
3887 |
|
| 3 |
liveuser |
3888 |
#設置錯誤訊息
|
|
|
3889 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
3890 |
|
| 3 |
liveuser |
3891 |
#回傳結果
|
|
|
3892 |
return $result;
|
| 226 |
liveuser |
3893 |
|
| 3 |
liveuser |
3894 |
}#if end
|
| 226 |
liveuser |
3895 |
|
| 3 |
liveuser |
3896 |
#如果 $conf["foreignKeyUpdateAction"] 不存在
|
|
|
3897 |
if(!isset($conf["foreignKeyUpdateAction"])){
|
| 226 |
liveuser |
3898 |
|
| 3 |
liveuser |
3899 |
#則預設為"CASCADE"將有所關聯的紀錄行也會進行刪除或修改。
|
|
|
3900 |
$conf["foreignKeyUpdateAction"]="CASCADE";#若要設定foreign key的話,可以指定參考的資料表欄位更新時該欄位該怎麼處理,預設為"CASCADE",會將有所關聯的紀錄行也會進行刪除或修改。"SET NULL"代表會將有所關聯的紀錄行設定成 NULL。"NO ACTION"代表有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
|
| 226 |
liveuser |
3901 |
|
| 3 |
liveuser |
3902 |
}#if end
|
| 226 |
liveuser |
3903 |
|
| 3 |
liveuser |
3904 |
#如果 $conf["foreignKeyDeleteAction"] 沒有設定
|
|
|
3905 |
if(!isset($conf["foreignKeyDeleteAction"])){
|
| 226 |
liveuser |
3906 |
|
| 3 |
liveuser |
3907 |
#預設為"SET NULL",會將有所關聯的紀錄行設定成 NULL。
|
|
|
3908 |
$conf["foreignKeyDeleteAction"]="SET NULL";#若要設定foreign key的話,可以指定參考的資料表欄位移除時該欄位該怎麼處理,預設為"SET NULL",會將有所關聯的紀錄行設定成 NULL。"NO ACTION"代表有存在的關聯紀錄行時,會禁止父資料表的刪除或修改動作。
|
| 226 |
liveuser |
3909 |
|
| 3 |
liveuser |
3910 |
}#if end
|
| 226 |
liveuser |
3911 |
|
| 3 |
liveuser |
3912 |
#檢查目標欄位的 key constraint 名稱
|
|
|
3913 |
#取得其key為何種
|
|
|
3914 |
#函式說明:
|
|
|
3915 |
#取得資料表所有欄位的詳細資訊
|
|
|
3916 |
#回傳的內容:
|
|
|
3917 |
#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
|
|
|
3918 |
#$result["error"],錯誤訊息陣列
|
|
|
3919 |
#$result["sql"],執行的sql語法
|
|
|
3920 |
#$result["oriInput"],原始的資料表欄位資訊
|
|
|
3921 |
#$result["everyLine"],逐行的欄位資訊
|
|
|
3922 |
#$result["tableName"],當前查詢的資料表名稱
|
|
|
3923 |
#$result["engine"],資料表使用的儲存引擎
|
|
|
3924 |
#$result["charset"],資料表預設的編碼
|
|
|
3925 |
#$result["columnName"][$i],各欄位的名稱陣列,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3926 |
#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3927 |
#$result["columnNotNull"][$i],各欄位是否可以不爲null,"true"爲可以不爲null;"false"爲可以爲"null",$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3928 |
#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3929 |
#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3930 |
#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3931 |
#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3932 |
#$result["columnCollate"][$i],各欄位使用的Collate,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3933 |
#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
|
|
|
3934 |
#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3935 |
#$result["primaryKey"],該資料表的主鍵
|
|
|
3936 |
#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
|
|
|
3937 |
#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲0開始的數字,也可以使用欄位的名稱。
|
|
|
3938 |
#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列
|
|
|
3939 |
#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲0開始的數字
|
|
|
3940 |
#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲0開始的數字
|
|
|
3941 |
#$result["foreignKey"]["OnUpdateAction"][$l],當參照的欄位資料更新時,會怎麼同步,$l爲0開始的數字
|
|
|
3942 |
#$result["foreignKey"]["OnDeleteAction"][$m],當參照的欄位資料移除時,會怎麼同步,$m爲0開始的數字
|
|
|
3943 |
#必填參數:
|
|
|
3944 |
$conf["db"]["getTableColumnDetailInfo"]["dbAddress"]=$conf["dbAddress"];
|
|
|
3945 |
$conf["db"]["getTableColumnDetailInfo"]["dbAccount"]=$conf["dbAccount"];
|
|
|
3946 |
$conf["db"]["getTableColumnDetailInfo"]["selectedDataBase"]=$conf["selectedDataBaseName"];
|
|
|
3947 |
$conf["db"]["getTableColumnDetailInfo"]["selectedDataTable"]=$conf["selectedDataTableName"];
|
|
|
3948 |
#可省略參數:
|
| 226 |
liveuser |
3949 |
|
| 3 |
liveuser |
3950 |
#如果 $conf["dbPassword"] 有設定
|
|
|
3951 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
3952 |
|
| 3 |
liveuser |
3953 |
#套用連限時的密碼
|
|
|
3954 |
$conf["db"]["getTableColumnDetailInfo"]["dbPassword"]=$conf["dbPassword"];
|
| 226 |
liveuser |
3955 |
|
| 3 |
liveuser |
3956 |
}#if end
|
| 226 |
liveuser |
3957 |
|
|
|
3958 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
3959 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
3960 |
|
| 3 |
liveuser |
3961 |
#設定 $conf["dbPort"]
|
|
|
3962 |
$conf["db"]["getTableColumnDetailInfo"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
3963 |
|
|
|
3964 |
}#if end
|
|
|
3965 |
|
| 3 |
liveuser |
3966 |
$tableColumnDetial=db::getTableColumnDetailInfo($conf["db"]["getTableColumnDetailInfo"]);
|
|
|
3967 |
unset($conf["db"]["getTableColumnDetailInfo"]);#卸除變數,避免錯誤產生.
|
| 226 |
liveuser |
3968 |
|
| 3 |
liveuser |
3969 |
#如果取得資料表結構失敗
|
|
|
3970 |
if($tableColumnDetial["status"]=="false"){
|
| 226 |
liveuser |
3971 |
|
| 3 |
liveuser |
3972 |
#設置執行不正常
|
|
|
3973 |
$result["status"]="false";
|
| 226 |
liveuser |
3974 |
|
| 3 |
liveuser |
3975 |
#設置執行錯誤訊息
|
|
|
3976 |
$result["error"]=$tableColumnDetial;
|
| 226 |
liveuser |
3977 |
|
| 3 |
liveuser |
3978 |
#回傳結果
|
|
|
3979 |
return $result;
|
| 226 |
liveuser |
3980 |
|
|
|
3981 |
}#if end
|
|
|
3982 |
|
| 3 |
liveuser |
3983 |
#依據設定將該欄位設定為foreign key
|
| 226 |
liveuser |
3984 |
|
| 3 |
liveuser |
3985 |
#設定其參照的資料表與欄位的sql語法
|
|
|
3986 |
$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"];
|
| 226 |
liveuser |
3987 |
|
| 3 |
liveuser |
3988 |
#執行 sql 語法
|
|
|
3989 |
#函式說明:
|
|
|
3990 |
#執行mysql指令
|
|
|
3991 |
#回傳結果::
|
|
|
3992 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
3993 |
#$result["error"],錯誤訊息的陣列
|
|
|
3994 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
3995 |
#$result["queryString"],mysql查詢的語言
|
|
|
3996 |
#查詢號的解果,需要解析。
|
|
|
3997 |
#必填參數:
|
|
|
3998 |
$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
3999 |
$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
4000 |
$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
|
| 226 |
liveuser |
4001 |
#可省略參數:
|
|
|
4002 |
|
| 3 |
liveuser |
4003 |
#如果有設定連線密碼
|
|
|
4004 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
4005 |
|
| 3 |
liveuser |
4006 |
$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
4007 |
|
| 3 |
liveuser |
4008 |
}#if end
|
| 226 |
liveuser |
4009 |
|
| 3 |
liveuser |
4010 |
#$conf["db"]["execMysqlQuery"]["dbName"]=$conf["selectedDataBaseName"];#為是否要指定資料庫,預設不指定.
|
| 226 |
liveuser |
4011 |
|
|
|
4012 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
4013 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
4014 |
|
| 3 |
liveuser |
4015 |
#設定 $conf["dbPort"]
|
|
|
4016 |
$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
4017 |
|
|
|
4018 |
}#if end
|
|
|
4019 |
|
| 3 |
liveuser |
4020 |
$sqlExecResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
|
|
|
4021 |
unset($conf["db"]["execMysqlQuery"]);
|
| 226 |
liveuser |
4022 |
|
| 3 |
liveuser |
4023 |
#var_dump($sqlExecResult);
|
| 226 |
liveuser |
4024 |
|
| 3 |
liveuser |
4025 |
#取得執行的sql語法
|
|
|
4026 |
$result["sql"][]=$sqlExecResult["queryString"];
|
| 226 |
liveuser |
4027 |
|
| 3 |
liveuser |
4028 |
#如果執行 sql 語法錯誤
|
|
|
4029 |
if($sqlExecResult["status"]=="false"){
|
| 226 |
liveuser |
4030 |
|
| 3 |
liveuser |
4031 |
#echo "fasle";
|
| 226 |
liveuser |
4032 |
|
| 3 |
liveuser |
4033 |
#設定執行失敗的識別
|
|
|
4034 |
$result["status"]="false";
|
| 226 |
liveuser |
4035 |
|
| 3 |
liveuser |
4036 |
#設定錯誤訊息
|
|
|
4037 |
$result["error"]=$sqlExecResult;
|
| 226 |
liveuser |
4038 |
|
| 3 |
liveuser |
4039 |
#回傳結果
|
|
|
4040 |
return $result;
|
| 226 |
liveuser |
4041 |
|
|
|
4042 |
}#if end
|
|
|
4043 |
|
| 3 |
liveuser |
4044 |
#跳出 foreign key
|
|
|
4045 |
break;
|
| 226 |
liveuser |
4046 |
|
| 3 |
liveuser |
4047 |
#如果不是以上參數
|
|
|
4048 |
default:
|
| 226 |
liveuser |
4049 |
|
| 3 |
liveuser |
4050 |
#設定執行錯誤的識別
|
|
|
4051 |
$result["status"]="false";
|
| 226 |
liveuser |
4052 |
|
| 3 |
liveuser |
4053 |
#設定錯誤訊息
|
|
|
4054 |
$result["error"]="可用的鍵型為index、foregin key、primary key";
|
| 226 |
liveuser |
4055 |
|
| 3 |
liveuser |
4056 |
#回傳結果
|
|
|
4057 |
return $result;
|
| 226 |
liveuser |
4058 |
|
| 3 |
liveuser |
4059 |
}#switch end
|
| 226 |
liveuser |
4060 |
|
| 3 |
liveuser |
4061 |
}#if end
|
| 226 |
liveuser |
4062 |
|
| 3 |
liveuser |
4063 |
#執行到這邊代表執行成功
|
|
|
4064 |
#設定執行成功的識別
|
|
|
4065 |
$result["status"]="true";
|
| 226 |
liveuser |
4066 |
|
| 3 |
liveuser |
4067 |
#回傳結果
|
|
|
4068 |
return $result;
|
| 226 |
liveuser |
4069 |
|
| 3 |
liveuser |
4070 |
}#function editColumn end
|
|
|
4071 |
|
|
|
4072 |
/*
|
|
|
4073 |
#函式說明:
|
|
|
4074 |
#新增資料表的欄位
|
|
|
4075 |
#回傳結果:
|
|
|
4076 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗.
|
|
|
4077 |
#$result["function"],當前執行的函數名稱.
|
|
|
4078 |
#$result["error"],錯誤訊息陣列.
|
|
|
4079 |
#$result["warning"],警告訊息.
|
|
|
4080 |
#$result["sql"],執行的sql字串.
|
|
|
4081 |
#必填參數:
|
|
|
4082 |
$conf["dbAddress"],字串,爲mysql-Server的位置.
|
|
|
4083 |
$conf["dbAddress"]=$dbAddress;
|
|
|
4084 |
$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號.
|
|
|
4085 |
$conf["dbAccount"]=$dbAccount;
|
|
|
4086 |
$conf["selectedDataBaseName"],字串,爲目標資料表所屬的資料庫.
|
|
|
4087 |
$conf["selectedDataBaseName"]="";
|
|
|
4088 |
$conf["selectedDataTableName"],字串,爲目標資料表所屬的資料庫.
|
|
|
4089 |
$conf["selectedDataTableName"]="";
|
|
|
4090 |
$conf["indexedColumnName"],字串,要設爲index的欄位名稱.
|
|
|
4091 |
$conf["indexedColumnName"]="";
|
|
|
4092 |
#可省略參數:
|
|
|
4093 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
4094 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
4095 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
|
|
|
4096 |
#$conf["dbPort"]="3306";
|
|
|
4097 |
#參考資料:
|
|
|
4098 |
#無.
|
|
|
4099 |
#備註:
|
|
|
4100 |
#無.
|
|
|
4101 |
*/
|
|
|
4102 |
public static function setColumnIndex($conf){
|
| 226 |
liveuser |
4103 |
|
| 3 |
liveuser |
4104 |
#初始化要回傳的內容
|
|
|
4105 |
$result=array();
|
|
|
4106 |
|
|
|
4107 |
#取得當前執行的函數名稱
|
|
|
4108 |
$result["function"]=__FUNCTION__;
|
|
|
4109 |
|
|
|
4110 |
#如果 $conf 不為陣列
|
|
|
4111 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
4112 |
|
| 3 |
liveuser |
4113 |
#設置執行失敗
|
|
|
4114 |
$result["status"]="false";
|
| 226 |
liveuser |
4115 |
|
| 3 |
liveuser |
4116 |
#設置執行錯誤訊息
|
|
|
4117 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
4118 |
|
|
|
4119 |
#如果傳入的參數為 null
|
|
|
4120 |
if($conf==null){
|
| 226 |
liveuser |
4121 |
|
| 3 |
liveuser |
4122 |
#設置執行錯誤訊息
|
|
|
4123 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
4124 |
|
| 3 |
liveuser |
4125 |
}#if end
|
|
|
4126 |
|
|
|
4127 |
#回傳結果
|
|
|
4128 |
return $result;
|
| 226 |
liveuser |
4129 |
|
| 3 |
liveuser |
4130 |
}#if end
|
| 226 |
liveuser |
4131 |
|
| 3 |
liveuser |
4132 |
#函式說明:
|
|
|
4133 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
4134 |
#回傳結果:
|
|
|
4135 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4136 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4137 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4138 |
#必填參數:
|
|
|
4139 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
4140 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName","indexedColumnName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
4141 |
#可省略參數:
|
| 226 |
liveuser |
4142 |
#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
4143 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
4144 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
4145 |
unset($conf["variableCheck"]["isexistMuti"]);
|
| 226 |
liveuser |
4146 |
|
| 3 |
liveuser |
4147 |
#如果檢查不通過
|
|
|
4148 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
4149 |
|
| 3 |
liveuser |
4150 |
#設置執行失敗的訊息
|
|
|
4151 |
$result["status"]="false";
|
| 226 |
liveuser |
4152 |
|
| 3 |
liveuser |
4153 |
#設置錯誤訊息
|
|
|
4154 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
4155 |
|
| 3 |
liveuser |
4156 |
#回傳結果
|
|
|
4157 |
return $result;
|
| 226 |
liveuser |
4158 |
|
| 3 |
liveuser |
4159 |
}#if end
|
| 226 |
liveuser |
4160 |
|
| 3 |
liveuser |
4161 |
#查詢該欄位是否已經是index了
|
|
|
4162 |
#函式說明:
|
|
|
4163 |
#取得資料表所有欄位的詳細資訊
|
|
|
4164 |
#回傳的內容:
|
|
|
4165 |
#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
|
|
|
4166 |
#$result["error"],錯誤訊息陣列
|
|
|
4167 |
#$result["function"],當前執行的函數名稱.
|
|
|
4168 |
#$result["sql"],執行的sql語法
|
|
|
4169 |
#$result["oriInput"],原始的資料表欄位資訊
|
|
|
4170 |
#$result["everyLine"],逐行的欄位資訊
|
|
|
4171 |
#$result["tableName"],當前查詢的資料表名稱
|
|
|
4172 |
#$result["engine"],資料表使用的儲存引擎
|
|
|
4173 |
#$result["charset"],資料表預設的編碼
|
|
|
4174 |
#$result["columnName"][$i],各欄位的名稱陣列,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4175 |
#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4176 |
#$result["columnVarType"][$i],各欄位變數儲存的型態,$i爲1開始的數字,也可以使用欄位的名稱.
|
|
|
4177 |
#$result["columnVarLengthLimit"][$i],個欄位變數的長度限制,若不存在其限制,則為"",$i爲1開始的數字,也可以使用欄位的名稱.
|
|
|
4178 |
#$result["columnNotNull"][$i],各欄位是否不可爲null,"true"爲不可以爲null;"false"爲可爲"null",$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4179 |
#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4180 |
#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4181 |
#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4182 |
#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4183 |
#$result["columnCollate"][$i],各欄位使用的Collate,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4184 |
#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
|
|
|
4185 |
#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
|
|
|
4186 |
#$result["keyConstraintName"][$j],該資料表用於識別索引鍵的CONSTRAINT名稱陣列,$j爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4187 |
#$result["primaryKey"],該資料表的主鍵
|
|
|
4188 |
#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
|
|
|
4189 |
#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4190 |
#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4191 |
#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲1開始的數字,,也可用欄位的名稱來找value.
|
|
|
4192 |
#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲1開始的數字,也可用欄位的名稱來找value.
|
|
|
4193 |
#$result["foreignKey"]["onUpdateAction"][$i],當參照的欄位資料更新時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
|
|
|
4194 |
#$result["foreignKey"]["onDeleteAction"][$i],當參照的欄位資料移除時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
|
|
|
4195 |
#必填參數:
|
|
|
4196 |
$conf["db::getTableColumnDetailInfo"]["dbAddress"]=$conf["dbAddress"];#資料庫的網路位置
|
|
|
4197 |
$conf["db::getTableColumnDetailInfo"]["dbAccount"]=$conf["dbAccount"];#連線到資料庫要用的帳號
|
|
|
4198 |
$conf["db::getTableColumnDetailInfo"]["selectedDataBase"]=$conf["selectedDataBaseName"];#連線到資料庫要選擇的資料庫
|
|
|
4199 |
$conf["db::getTableColumnDetailInfo"]["selectedDataTable"]=$conf["selectedDataTableName"];#連線到資料庫要檢視的資料表
|
|
|
4200 |
#可省略參數:
|
| 226 |
liveuser |
4201 |
|
| 3 |
liveuser |
4202 |
#如果 $conf["dbPassword"] 有設定
|
|
|
4203 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
4204 |
|
| 3 |
liveuser |
4205 |
#設定其密碼
|
|
|
4206 |
$conf["db::getTableColumnDetailInfo"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
4207 |
|
| 3 |
liveuser |
4208 |
}#if end
|
| 226 |
liveuser |
4209 |
|
|
|
4210 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
4211 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
4212 |
|
| 3 |
liveuser |
4213 |
#設定 $conf["dbPort"]
|
|
|
4214 |
$conf["db::getTableColumnDetailInfo"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
4215 |
|
| 3 |
liveuser |
4216 |
}#if end
|
| 226 |
liveuser |
4217 |
|
| 3 |
liveuser |
4218 |
#備註:
|
|
|
4219 |
#如果forign key參照的是別的資料庫,將無法取得參照的資料庫名稱?
|
|
|
4220 |
$getTableColumnDetailInfo=db::getTableColumnDetailInfo($conf["db::getTableColumnDetailInfo"]);
|
| 226 |
liveuser |
4221 |
unset($conf["db::getTableColumnDetailInfo"]);
|
|
|
4222 |
|
| 3 |
liveuser |
4223 |
#如果取得資料表資訊失敗
|
|
|
4224 |
if($getTableColumnDetailInfo["status"]=="false"){
|
| 226 |
liveuser |
4225 |
|
| 3 |
liveuser |
4226 |
#設置錯誤訊息
|
|
|
4227 |
$result["status"]="false";
|
| 226 |
liveuser |
4228 |
|
| 3 |
liveuser |
4229 |
#設置錯誤提示
|
|
|
4230 |
$result["error"]=$getTableColumnDetailInfo;
|
| 226 |
liveuser |
4231 |
|
| 3 |
liveuser |
4232 |
#回傳結果
|
|
|
4233 |
return $result;
|
| 226 |
liveuser |
4234 |
|
|
|
4235 |
}#if end
|
|
|
4236 |
|
| 3 |
liveuser |
4237 |
#如果該欄位已經是index了
|
|
|
4238 |
if(isset($getTableColumnDetailInfo["key"][$conf["indexedColumnName"]])){
|
| 226 |
liveuser |
4239 |
|
| 3 |
liveuser |
4240 |
#設置執行正常
|
|
|
4241 |
$result["status"]="true";
|
| 226 |
liveuser |
4242 |
|
| 3 |
liveuser |
4243 |
#設置警告提示
|
|
|
4244 |
$result["warning"][]="已經是index key了";
|
| 226 |
liveuser |
4245 |
|
| 3 |
liveuser |
4246 |
#回傳結果
|
|
|
4247 |
return $result;
|
| 226 |
liveuser |
4248 |
|
| 3 |
liveuser |
4249 |
}#if end
|
| 226 |
liveuser |
4250 |
|
| 3 |
liveuser |
4251 |
#組合sql語言
|
|
|
4252 |
$sql="alter table ".$conf["selectedDataBaseName"].".".$conf["selectedDataTableName"]." add index(`".$conf["indexedColumnName"]."`)";
|
| 226 |
liveuser |
4253 |
|
| 3 |
liveuser |
4254 |
#執行sql語法
|
|
|
4255 |
#函式說明:
|
|
|
4256 |
#執行mysql指令
|
|
|
4257 |
#回傳結果::
|
|
|
4258 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
4259 |
#$result["error"],錯誤訊息的陣列
|
|
|
4260 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
4261 |
#$result["queryString"],mysql查詢的語言
|
|
|
4262 |
#查詢號的解果,需要解析。
|
|
|
4263 |
#必填參數:
|
|
|
4264 |
$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
4265 |
$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
4266 |
$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
|
|
|
4267 |
#可省略參數:
|
| 226 |
liveuser |
4268 |
|
| 3 |
liveuser |
4269 |
#如果 $conf["dbPassword"] 有設定
|
|
|
4270 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
4271 |
|
| 3 |
liveuser |
4272 |
#設定其密碼
|
|
|
4273 |
$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
4274 |
|
| 3 |
liveuser |
4275 |
}#if end
|
| 226 |
liveuser |
4276 |
|
|
|
4277 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
4278 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
4279 |
|
| 3 |
liveuser |
4280 |
#設定 $conf["dbPort"]
|
|
|
4281 |
$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
4282 |
|
| 3 |
liveuser |
4283 |
}#if end
|
| 226 |
liveuser |
4284 |
|
| 3 |
liveuser |
4285 |
$queryResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
|
|
|
4286 |
unset($conf["db"]["execMysqlQuery"]);
|
| 226 |
liveuser |
4287 |
|
| 3 |
liveuser |
4288 |
#取得執行的sql語法
|
|
|
4289 |
$result["sql"]=$queryResult["queryString"];
|
| 226 |
liveuser |
4290 |
|
| 3 |
liveuser |
4291 |
#如果有錯誤
|
|
|
4292 |
if($queryResult["status"]=="false"){
|
| 226 |
liveuser |
4293 |
|
| 3 |
liveuser |
4294 |
#設置錯誤訊息
|
|
|
4295 |
$result["status"]="false";
|
| 226 |
liveuser |
4296 |
|
| 3 |
liveuser |
4297 |
#設置錯誤提示
|
|
|
4298 |
$result["error"]=$queryResult;
|
| 226 |
liveuser |
4299 |
|
| 3 |
liveuser |
4300 |
#回傳結果
|
|
|
4301 |
return $result;
|
| 226 |
liveuser |
4302 |
|
| 3 |
liveuser |
4303 |
}#if end
|
| 226 |
liveuser |
4304 |
|
| 3 |
liveuser |
4305 |
#執行到這邊代表執行成功
|
| 226 |
liveuser |
4306 |
|
| 3 |
liveuser |
4307 |
#設置成功訊息
|
|
|
4308 |
$result["status"]="true";
|
| 226 |
liveuser |
4309 |
|
| 3 |
liveuser |
4310 |
#回傳結果
|
|
|
4311 |
return $result;
|
| 226 |
liveuser |
4312 |
|
| 3 |
liveuser |
4313 |
}#function setColumnIndex end
|
|
|
4314 |
|
|
|
4315 |
/*
|
|
|
4316 |
#函式說明:
|
|
|
4317 |
#取得資料表所有欄位的詳細資訊
|
|
|
4318 |
#回傳的內容:
|
|
|
4319 |
#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
|
|
|
4320 |
#$result["error"],錯誤訊息陣列
|
|
|
4321 |
#$result["function"],當前執行的函數名稱.
|
|
|
4322 |
#$result["sql"],執行的sql語法
|
|
|
4323 |
#$result["oriInput"],原始的資料表欄位資訊
|
|
|
4324 |
#$result["everyLine"],逐行的欄位資訊
|
|
|
4325 |
#$result["tableName"],當前查詢的資料表名稱
|
|
|
4326 |
#$result["engine"],資料表使用的儲存引擎
|
|
|
4327 |
#$result["charset"],資料表預設的編碼
|
|
|
4328 |
#$result["columnName"][$i],各欄位的名稱陣列,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4329 |
#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4330 |
#$result["columnVarType"][$i],各欄位變數儲存的型態,$i爲1開始的數字,也可以使用欄位的名稱.
|
|
|
4331 |
#$result["columnVarLengthLimit"][$i],個欄位變數的長度限制,若不存在其限制,則為"",$i爲1開始的數字,也可以使用欄位的名稱.
|
|
|
4332 |
#$result["columnNotNull"][$i],各欄位是否不可爲null,"true"爲不可以爲null;"false"爲可爲"null",$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4333 |
#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4334 |
#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4335 |
#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4336 |
#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4337 |
#$result["columnCollate"][$i],各欄位使用的Collate,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4338 |
#$result["columnComment"][$i],各欄位的註解,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4339 |
#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
|
|
|
4340 |
#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
|
|
|
4341 |
#$result["keyConstraintName"][$j],該資料表用於識別索引鍵的CONSTRAINT名稱陣列,$j爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4342 |
#$result["primaryKey"],該資料表的主鍵
|
|
|
4343 |
#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
|
|
|
4344 |
#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4345 |
#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
|
|
|
4346 |
#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲1開始的數字,,也可用欄位的名稱來找value.
|
|
|
4347 |
#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲1開始的數字,也可用欄位的名稱來找value.
|
|
|
4348 |
#$result["foreignKey"]["onUpdateAction"][$i],當參照的欄位資料更新時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
|
|
|
4349 |
#$result["foreignKey"]["onDeleteAction"][$i],當參照的欄位資料移除時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
|
|
|
4350 |
#必填參數:
|
|
|
4351 |
#$conf["dbAddress"],字串,資料庫的網路位置
|
|
|
4352 |
$conf["dbAddress"]="";
|
|
|
4353 |
#$conf["dbAccount"],字串,連線到資料庫要用的帳號
|
|
|
4354 |
$conf["dbAccount"]="";連線到資料庫要用的帳號
|
|
|
4355 |
#$conf["selectedDataBase"]字串,連線到資料庫要選擇的資料庫
|
|
|
4356 |
$conf["selectedDataBase"]=$dbName;
|
|
|
4357 |
#$conf["selectedDataTable"],字串,連線到資料庫要檢視的資料表
|
|
|
4358 |
$conf["selectedDataTable"]="";
|
|
|
4359 |
#可省略參數:
|
|
|
4360 |
#$conf["dbPassword"],字串,連線到資料庫要用的密碼
|
|
|
4361 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
4362 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
|
|
|
4363 |
#$conf["dbPort"]="3306";
|
|
|
4364 |
#參考資料:
|
|
|
4365 |
#無.
|
|
|
4366 |
#備註:
|
|
|
4367 |
#如果forign key參照的是別的資料庫,將無法取得參照的資料庫名稱?
|
|
|
4368 |
*/
|
|
|
4369 |
public static function getTableColumnDetailInfo(&$conf){
|
| 226 |
liveuser |
4370 |
|
| 3 |
liveuser |
4371 |
#初始化要回傳的內容
|
|
|
4372 |
$result=array();
|
|
|
4373 |
|
|
|
4374 |
#取得當前執行的函數名稱
|
|
|
4375 |
$result["function"]=__FUNCTION__;
|
|
|
4376 |
|
|
|
4377 |
#如果 $conf 不為陣列
|
|
|
4378 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
4379 |
|
| 3 |
liveuser |
4380 |
#設置執行失敗
|
|
|
4381 |
$result["status"]="false";
|
| 226 |
liveuser |
4382 |
|
| 3 |
liveuser |
4383 |
#設置執行錯誤訊息
|
|
|
4384 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
4385 |
|
|
|
4386 |
#如果傳入的參數為 null
|
|
|
4387 |
if($conf==null){
|
| 226 |
liveuser |
4388 |
|
| 3 |
liveuser |
4389 |
#設置執行錯誤訊息
|
|
|
4390 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
4391 |
|
| 3 |
liveuser |
4392 |
}#if end
|
|
|
4393 |
|
|
|
4394 |
#回傳結果
|
|
|
4395 |
return $result;
|
| 226 |
liveuser |
4396 |
|
| 3 |
liveuser |
4397 |
}#if end
|
| 226 |
liveuser |
4398 |
|
| 3 |
liveuser |
4399 |
#檢查參數設定是否正確
|
|
|
4400 |
#函式說明:
|
|
|
4401 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
4402 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
4403 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
4404 |
#$result["function"],當前執行的函式名稱.
|
|
|
4405 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
4406 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
4407 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
4408 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
4409 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
4410 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
4411 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
4412 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
4413 |
#必填參數:
|
|
|
4414 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
4415 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
4416 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
4417 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","selectedDataBase","selectedDataTable");
|
|
|
4418 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
4419 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string");
|
|
|
4420 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
4421 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
4422 |
#可省略參數:
|
|
|
4423 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
4424 |
#$conf["canBeEmptyString"]="false";
|
|
|
4425 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
4426 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
4427 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
4428 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort");
|
| 226 |
liveuser |
4429 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
4430 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
4431 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
4432 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null);
|
|
|
4433 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
4434 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
4435 |
#參考資料:
|
|
|
4436 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
4437 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
4438 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
4439 |
|
| 3 |
liveuser |
4440 |
#如果檢查失敗
|
| 177 |
liveuser |
4441 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
4442 |
|
| 3 |
liveuser |
4443 |
#設置執行失敗識別
|
|
|
4444 |
$result["status"]="false";
|
| 226 |
liveuser |
4445 |
|
| 3 |
liveuser |
4446 |
#設置錯誤訊息陣列
|
|
|
4447 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
4448 |
|
| 3 |
liveuser |
4449 |
#回傳結果
|
|
|
4450 |
return $result;
|
| 226 |
liveuser |
4451 |
|
| 3 |
liveuser |
4452 |
}#if end
|
| 226 |
liveuser |
4453 |
|
| 3 |
liveuser |
4454 |
#如果檢查不通過
|
| 177 |
liveuser |
4455 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
4456 |
|
| 3 |
liveuser |
4457 |
#設置執行失敗識別
|
|
|
4458 |
$result["status"]="false";
|
| 226 |
liveuser |
4459 |
|
| 3 |
liveuser |
4460 |
#設置錯誤訊息陣列
|
|
|
4461 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
4462 |
|
| 3 |
liveuser |
4463 |
#回傳結果
|
|
|
4464 |
return $result;
|
| 226 |
liveuser |
4465 |
|
| 3 |
liveuser |
4466 |
}#if end
|
| 226 |
liveuser |
4467 |
|
| 177 |
liveuser |
4468 |
#檢查資料庫 $conf["selectedDataBase"] 是否可以存取
|
|
|
4469 |
#確認資料庫存在或可以被存取
|
|
|
4470 |
#函式說明:
|
|
|
4471 |
#執行mysql指令
|
|
|
4472 |
#回傳結果:
|
|
|
4473 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
4474 |
#$result["error"],錯誤訊息的陣列
|
|
|
4475 |
#$result["function"],當前執行的涵式
|
|
|
4476 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
4477 |
#$result["queryConn"],mysql用來查尋的連資源.
|
|
|
4478 |
#$result["queryString"],要執行的sql內容.
|
|
|
4479 |
#必填參數:
|
|
|
4480 |
#$conf["dbSql"],字串,要執行sql語法
|
|
|
4481 |
$conf["db::execMysqlQuery"]["dbSql"]="show databases;";
|
|
|
4482 |
#可省略參數:
|
|
|
4483 |
#$conf["dbLink"],物件,mysqli物件,由mysqli_connect()回傳的物件內容,若為數值則改用賬號密碼等資訊進行連線,反之則沿用連線物件.
|
|
|
4484 |
#$conf["db::execMysqlQuery"]["dbLink"]=$conf["connectInformation"];
|
|
|
4485 |
#$conf["dbAddress"],字串,爲mysql-Server的位置。
|
|
|
4486 |
$conf["db::execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];
|
|
|
4487 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號。
|
| 226 |
liveuser |
4488 |
$conf["db::execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];
|
|
|
4489 |
|
| 177 |
liveuser |
4490 |
#如果存在 $conf["dbPassword"]
|
|
|
4491 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
4492 |
|
| 177 |
liveuser |
4493 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
|
|
|
4494 |
$conf["db::execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];
|
| 226 |
liveuser |
4495 |
|
| 177 |
liveuser |
4496 |
}#if end
|
| 226 |
liveuser |
4497 |
|
| 177 |
liveuser |
4498 |
#$conf["dbName"],字串,爲要連的資料庫名稱
|
|
|
4499 |
#$conf["dbName"]="";
|
| 226 |
liveuser |
4500 |
|
| 177 |
liveuser |
4501 |
#如果存在 $dbPort
|
|
|
4502 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
4503 |
|
| 177 |
liveuser |
4504 |
#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
|
|
|
4505 |
$conf["db::execMysqlQuery"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
4506 |
|
| 177 |
liveuser |
4507 |
}#if end
|
| 226 |
liveuser |
4508 |
|
| 177 |
liveuser |
4509 |
#$conf["autoClose"],字串,"true"代表要自動斷線,預設為"true"會自動斷線
|
|
|
4510 |
#$conf["autoClose"]="true";
|
|
|
4511 |
#參考資料:
|
|
|
4512 |
#無.
|
|
|
4513 |
#備註:
|
|
|
4514 |
#無.
|
|
|
4515 |
$execMysqlQuery=db::execMysqlQuery($conf["db::execMysqlQuery"]);
|
|
|
4516 |
unset($conf["db::execMysqlQuery"]);
|
|
|
4517 |
|
|
|
4518 |
#如果執行失敗
|
|
|
4519 |
if($execMysqlQuery["status"]==="false"){
|
| 226 |
liveuser |
4520 |
|
| 177 |
liveuser |
4521 |
#設置連線失敗的提示
|
|
|
4522 |
$result["error"][]="檢查資料庫可否存取出錯";
|
| 226 |
liveuser |
4523 |
|
| 177 |
liveuser |
4524 |
#設置錯誤訊息
|
|
|
4525 |
$result["error"][]=$execMysqlQuery["error"];
|
| 226 |
liveuser |
4526 |
|
| 177 |
liveuser |
4527 |
#設置執行失敗
|
|
|
4528 |
$result["status"]="false";
|
| 226 |
liveuser |
4529 |
|
| 177 |
liveuser |
4530 |
#回傳結果
|
|
|
4531 |
return $result;
|
| 226 |
liveuser |
4532 |
|
| 177 |
liveuser |
4533 |
}#if end
|
| 226 |
liveuser |
4534 |
|
| 177 |
liveuser |
4535 |
#解析 $execMysqlQuery["queryResource"] 看是否存在要存取的資料庫
|
|
|
4536 |
#函式說明:
|
|
|
4537 |
#解析 dataTableSelect($conf) 後的結果,亦即將執行sql語法後所得到的結果解析放進變數裏面
|
|
|
4538 |
#回傳結果:
|
|
|
4539 |
#$result["status"],執行結果"true"為成功;"false"為失敗
|
|
|
4540 |
#$result["error"],錯誤訊息
|
|
|
4541 |
#$result["function"],儲存當前函數名稱
|
|
|
4542 |
#$result["dataColumnName"],為資料欄位的名稱陣列.
|
|
|
4543 |
#$result["dataColumnName"][$i]代表第一個欄位名稱.
|
|
|
4544 |
#$result["dataContent"],爲資料的內容陣列,第1維度的key為$conf["tableValueName"][$i],亦即第 $i+1 個欄位的名稱,若該欄位不存在,則其value為空字串;第2維度的key為第$i+1筆資料的索引.
|
|
|
4545 |
#$result["dataCount"],爲取得的資料筆數.
|
|
|
4546 |
#必填參數:
|
|
|
4547 |
#$conf["sqlQueryResult"],object,爲執行sql語法所獲得的查詢結果。
|
|
|
4548 |
$conf["db::sendQueryDataToVariabele"]["sqlQueryResult"]=$execMysqlQuery["queryResource"];
|
|
|
4549 |
#$conf["tableValueName"],字串陣列,爲該資料表列項目的每一項名稱,須爲陣列值,若為「array("*")」則代表所有欄位.
|
|
|
4550 |
$conf["db::sendQueryDataToVariabele"]["tableValueName"]=array("Database");
|
|
|
4551 |
#可省略參數:
|
|
|
4552 |
#$conf["dbAddress"],字串,爲mysql-Server的位置,目前沒有用途.
|
|
|
4553 |
#$conf["dbAddress"]=$dbAddress;
|
|
|
4554 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號,目前沒有用途.
|
|
|
4555 |
#$conf["dbAccount"]=$dbAccount;
|
|
|
4556 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼,目前沒有用途.
|
|
|
4557 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
4558 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port,目前沒有用途.
|
|
|
4559 |
#$conf["dbPort"]="";
|
|
|
4560 |
#$conf["valueName"],字串陣列,爲該資料表列項目的每一項所要對應的變數名稱,預設為欄位的名稱($conf["tableValueName"]).
|
|
|
4561 |
#$conf["valueName"]=$conf["tableValueName"];
|
|
|
4562 |
#參考資料:
|
|
|
4563 |
#http://www.w3school.com.cn/php/func_mysql_fetch_array.asp => 解析取得的資料表欄位時,能夠選擇回傳含有欄位名稱與數字代表的key.
|
|
|
4564 |
#備註:
|
|
|
4565 |
#無.
|
|
|
4566 |
$sendQueryDataToVariabele=db::sendQueryDataToVariabele($conf["db::sendQueryDataToVariabele"]);
|
|
|
4567 |
unset($conf["db::sendQueryDataToVariabele"]);
|
|
|
4568 |
|
|
|
4569 |
#如果執行異常
|
|
|
4570 |
if($sendQueryDataToVariabele["status"]==="false"){
|
| 226 |
liveuser |
4571 |
|
| 177 |
liveuser |
4572 |
#設置連線失敗的提示
|
|
|
4573 |
$result["error"][]="檢查資料庫可否存取出錯";
|
| 226 |
liveuser |
4574 |
|
| 177 |
liveuser |
4575 |
#設置錯誤訊息
|
|
|
4576 |
$result["error"][]=$sendQueryDataToVariabele["error"];
|
| 226 |
liveuser |
4577 |
|
| 177 |
liveuser |
4578 |
#設置執行失敗
|
|
|
4579 |
$result["status"]="false";
|
| 226 |
liveuser |
4580 |
|
| 177 |
liveuser |
4581 |
#回傳結果
|
|
|
4582 |
return $result;
|
| 226 |
liveuser |
4583 |
|
| 177 |
liveuser |
4584 |
}#if end
|
| 226 |
liveuser |
4585 |
|
| 177 |
liveuser |
4586 |
#檢查資料庫是否可以存取
|
|
|
4587 |
#函式說明:
|
|
|
4588 |
#檢查一個數值是否與陣列裏面的元素相同,找到一個相符合的元素後就會停止搜尋.
|
|
|
4589 |
#回傳結果:
|
|
|
4590 |
#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
|
|
|
4591 |
#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
|
|
|
4592 |
#$result["error"],錯誤訊息
|
|
|
4593 |
#$result["function"],當前執行的函數名稱
|
|
|
4594 |
#$result["argv"],使用的參數
|
|
|
4595 |
#$result["equalVarName"],相等的變數名稱或key.
|
|
|
4596 |
#$result["equalVarValue"],相等的變數數值內容.
|
|
|
4597 |
#必填參數:
|
|
|
4598 |
#$conf["conditionElement"],字串,條件元素,要等於的元素內容.
|
|
|
4599 |
$conf["search::getEqualVar"]["conditionElement"]=$conf["selectedDataBase"];
|
|
|
4600 |
#$conf["compareElements"],字串陣列,要比對的陣列變數內容.
|
|
|
4601 |
$conf["search::getEqualVar"]["compareElements"]=$sendQueryDataToVariabele["dataContent"]["Database"];
|
|
|
4602 |
#可省略參數:
|
|
|
4603 |
#無.
|
|
|
4604 |
#參考資料:
|
|
|
4605 |
#無.
|
|
|
4606 |
#備註:
|
|
|
4607 |
#無.
|
|
|
4608 |
$getEqualVar=search::getEqualVar($conf["search::getEqualVar"]);
|
|
|
4609 |
unset($conf["search::getEqualVar"]);
|
| 226 |
liveuser |
4610 |
|
| 177 |
liveuser |
4611 |
#如果執行失敗
|
|
|
4612 |
if($getEqualVar["status"]==="false"){
|
| 226 |
liveuser |
4613 |
|
| 177 |
liveuser |
4614 |
#設置錯誤的提示
|
|
|
4615 |
$result["error"][]="檢查資料庫可否存取出錯";
|
| 226 |
liveuser |
4616 |
|
| 177 |
liveuser |
4617 |
#設置錯誤訊息
|
|
|
4618 |
$result["error"][]=$getEqualVar["error"];
|
| 226 |
liveuser |
4619 |
|
| 177 |
liveuser |
4620 |
#設置執行失敗
|
|
|
4621 |
$result["status"]="false";
|
| 226 |
liveuser |
4622 |
|
| 177 |
liveuser |
4623 |
#回傳結果
|
|
|
4624 |
return $result;
|
| 226 |
liveuser |
4625 |
|
| 177 |
liveuser |
4626 |
}#if end
|
| 226 |
liveuser |
4627 |
|
| 177 |
liveuser |
4628 |
#如果無法存取資料庫
|
|
|
4629 |
if($getEqualVar["founded"]==="false"){
|
| 226 |
liveuser |
4630 |
|
| 177 |
liveuser |
4631 |
#設置錯誤的提示
|
|
|
4632 |
$result["error"][]="資料庫(".$conf["selectedDataBase"].")無法存取";
|
| 226 |
liveuser |
4633 |
|
| 177 |
liveuser |
4634 |
#設置錯誤訊息
|
|
|
4635 |
$result["error"][]=$getEqualVar;
|
| 226 |
liveuser |
4636 |
|
| 177 |
liveuser |
4637 |
#設置執行失敗
|
|
|
4638 |
$result["status"]="false";
|
| 226 |
liveuser |
4639 |
|
| 177 |
liveuser |
4640 |
#回傳結果
|
|
|
4641 |
return $result;
|
| 226 |
liveuser |
4642 |
|
| 177 |
liveuser |
4643 |
}#if end
|
| 226 |
liveuser |
4644 |
|
| 3 |
liveuser |
4645 |
#設置要執行的sql語法
|
|
|
4646 |
$sql="SHOW CREATE TABLE ".$conf["selectedDataBase"].".".$conf["selectedDataTable"].";";
|
| 226 |
liveuser |
4647 |
|
| 3 |
liveuser |
4648 |
#執行sql語法
|
|
|
4649 |
#函式說明:
|
|
|
4650 |
#執行mysql指令
|
| 177 |
liveuser |
4651 |
#回傳結果:
|
| 3 |
liveuser |
4652 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
4653 |
#$result["error"],錯誤訊息的陣列
|
|
|
4654 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
4655 |
#$result["queryString"],mysql查詢的語言
|
|
|
4656 |
#查詢號的解果,需要解析。
|
|
|
4657 |
#必填參數:
|
|
|
4658 |
$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
4659 |
$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
4660 |
$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
|
|
|
4661 |
#可省略參數:
|
| 226 |
liveuser |
4662 |
|
| 3 |
liveuser |
4663 |
#如果 $conf["dbPassword"] 有設定
|
|
|
4664 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
4665 |
|
| 3 |
liveuser |
4666 |
#設定其密碼
|
|
|
4667 |
$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
4668 |
|
| 3 |
liveuser |
4669 |
}#if end
|
| 226 |
liveuser |
4670 |
|
| 177 |
liveuser |
4671 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
4672 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
4673 |
|
| 3 |
liveuser |
4674 |
#設定 $conf["dbPort"]
|
|
|
4675 |
$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
4676 |
|
| 177 |
liveuser |
4677 |
}#if end
|
| 226 |
liveuser |
4678 |
|
| 3 |
liveuser |
4679 |
$queryResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
|
|
|
4680 |
unset($conf["db"]["execMysqlQuery"]);
|
| 226 |
liveuser |
4681 |
|
| 3 |
liveuser |
4682 |
#如果有錯誤
|
|
|
4683 |
if($queryResult["status"]=="false"){
|
| 226 |
liveuser |
4684 |
|
| 3 |
liveuser |
4685 |
#設置錯誤訊息
|
|
|
4686 |
$result["status"]="false";
|
| 226 |
liveuser |
4687 |
|
| 3 |
liveuser |
4688 |
#設置錯誤提示
|
|
|
4689 |
$result["error"]=$queryResult;
|
| 226 |
liveuser |
4690 |
|
| 3 |
liveuser |
4691 |
#回傳結果
|
|
|
4692 |
return $result;
|
| 226 |
liveuser |
4693 |
|
| 3 |
liveuser |
4694 |
}#if end
|
| 226 |
liveuser |
4695 |
|
| 3 |
liveuser |
4696 |
#解析mysql resource
|
| 226 |
liveuser |
4697 |
|
| 3 |
liveuser |
4698 |
#初始化暫存的變數
|
|
|
4699 |
$temp="";
|
| 226 |
liveuser |
4700 |
|
| 3 |
liveuser |
4701 |
#將讀取到的資料一次只讀取一列
|
|
|
4702 |
while($row = mysqli_fetch_array($queryResult["queryResource"])){
|
|
|
4703 |
|
|
|
4704 |
#$i筆項列資料,則運行$i次。
|
| 226 |
liveuser |
4705 |
foreach($row as $key=>$value){
|
|
|
4706 |
|
| 3 |
liveuser |
4707 |
#如果key爲"Create Table"
|
|
|
4708 |
if($key=="Create Table"){
|
| 226 |
liveuser |
4709 |
|
| 3 |
liveuser |
4710 |
#將解析的資料內容結果放進$temp變數裏面
|
| 226 |
liveuser |
4711 |
$temp=$value;
|
|
|
4712 |
|
| 3 |
liveuser |
4713 |
}#if end
|
| 226 |
liveuser |
4714 |
|
| 3 |
liveuser |
4715 |
}#foreach end
|
|
|
4716 |
|
|
|
4717 |
}#while end
|
| 226 |
liveuser |
4718 |
|
| 3 |
liveuser |
4719 |
#逐行解析$temp
|
|
|
4720 |
#函式說明:
|
|
|
4721 |
#將多行內容的字串,依行切割
|
|
|
4722 |
#回傳的參數:
|
|
|
4723 |
#$result["status"],執行成功與否,若爲"true",代表執行成功,若爲"false"代表執失敗。
|
|
|
4724 |
#$result["error"],錯誤訊息陣列.
|
|
|
4725 |
#$result["function"],當前執行的函數名稱.#$result["oriStr"],要分割的原始字串內容
|
|
|
4726 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
4727 |
#$result["dataArray"],爲以行分割好的字串陣列內容,$result["dataArray"][$i]爲第($i+1)行的內容。
|
|
|
4728 |
#$result["dataCounts"],爲總共分成幾行
|
|
|
4729 |
#必填參數:
|
|
|
4730 |
$conf["stringProcess"]["spiltMutiLineString"]["stringIn"]=$temp;#要處理的多行文字字串。
|
|
|
4731 |
#參考資料來源:
|
|
|
4732 |
#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 換行字元
|
|
|
4733 |
$everyLine=stringProcess::spiltMutiLineString($conf["stringProcess"]["spiltMutiLineString"]);
|
|
|
4734 |
unset($conf["stringProcess"]["spiltMutiLineString"]);
|
| 226 |
liveuser |
4735 |
|
| 3 |
liveuser |
4736 |
#如果 逐行解析$temp 失敗
|
|
|
4737 |
if($everyLine["status"]==="false"){
|
| 226 |
liveuser |
4738 |
|
| 3 |
liveuser |
4739 |
#設置錯誤訊息
|
|
|
4740 |
$result["status"]="false";
|
| 226 |
liveuser |
4741 |
|
| 3 |
liveuser |
4742 |
#設置錯誤提示
|
|
|
4743 |
$result["error"]=$everyLine;
|
| 226 |
liveuser |
4744 |
|
| 3 |
liveuser |
4745 |
#回傳結果
|
|
|
4746 |
return $result;
|
| 226 |
liveuser |
4747 |
|
| 3 |
liveuser |
4748 |
}#if end
|
| 226 |
liveuser |
4749 |
|
| 3 |
liveuser |
4750 |
#針對每列內容
|
|
|
4751 |
foreach($everyLine["dataArray"] as $no => $line){
|
|
|
4752 |
|
|
|
4753 |
#函式說明:
|
|
|
4754 |
#取得符合特定字首與字尾的字串
|
|
|
4755 |
#回傳結果::
|
|
|
4756 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
4757 |
#$result["function"],當前執行的函數名稱.
|
|
|
4758 |
#$result["error"],錯誤訊息陣列.
|
|
|
4759 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
4760 |
#$result["returnString"],爲符合字首條件的字串內容。
|
|
|
4761 |
#$result["argu"],使用的參數.
|
|
|
4762 |
#必填參數:
|
|
|
4763 |
#$conf["checkString"],字串,要檢查的字串.
|
|
|
4764 |
$conf["search::getMeetConditionsString"]["checkString"]=$line;
|
|
|
4765 |
#可省略參數:
|
|
|
4766 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
4767 |
$conf["search::getMeetConditionsString"]["frontWord"]="/*";
|
|
|
4768 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
4769 |
#$conf["tailWord"]="";
|
|
|
4770 |
#參考資料:
|
|
|
4771 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
4772 |
$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
|
| 226 |
liveuser |
4773 |
unset($conf["search::getMeetConditionsString"]);
|
| 3 |
liveuser |
4774 |
|
|
|
4775 |
#如果執行失敗
|
|
|
4776 |
if($getMeetConditionsString["status"]==="false"){
|
|
|
4777 |
|
|
|
4778 |
#設置錯誤訊息
|
|
|
4779 |
$result["status"]="false";
|
| 226 |
liveuser |
4780 |
|
| 3 |
liveuser |
4781 |
#設置錯誤提示
|
|
|
4782 |
$result["error"]=$getMeetConditionsString;
|
| 226 |
liveuser |
4783 |
|
| 3 |
liveuser |
4784 |
#回傳結果
|
|
|
4785 |
return $result;
|
|
|
4786 |
|
|
|
4787 |
}#if end
|
|
|
4788 |
|
|
|
4789 |
#如果執行失敗
|
|
|
4790 |
if($getMeetConditionsString["founded"]==="true"){
|
|
|
4791 |
|
|
|
4792 |
#while loop
|
|
|
4793 |
while(true){
|
|
|
4794 |
|
| 226 |
liveuser |
4795 |
#移除 partion 描述 - start
|
| 3 |
liveuser |
4796 |
|
|
|
4797 |
#如果存在該列
|
|
|
4798 |
if(isset($everyLine["dataArray"][$no])){
|
|
|
4799 |
|
|
|
4800 |
#卸除之
|
|
|
4801 |
unset($everyLine["dataArray"][$no]);
|
|
|
4802 |
|
|
|
4803 |
#行數加1
|
|
|
4804 |
$no++;
|
|
|
4805 |
|
|
|
4806 |
}#if end
|
|
|
4807 |
|
|
|
4808 |
#移除 partion 描述 - end
|
|
|
4809 |
|
|
|
4810 |
#反之
|
|
|
4811 |
else{
|
|
|
4812 |
|
|
|
4813 |
//end while
|
|
|
4814 |
break;
|
|
|
4815 |
|
| 226 |
liveuser |
4816 |
}#else end
|
| 3 |
liveuser |
4817 |
|
|
|
4818 |
}#while loop end
|
|
|
4819 |
|
|
|
4820 |
#end foreach
|
|
|
4821 |
break;
|
|
|
4822 |
|
|
|
4823 |
}#if end
|
|
|
4824 |
|
|
|
4825 |
}#foreach end
|
| 226 |
liveuser |
4826 |
|
| 3 |
liveuser |
4827 |
#重新更新總行數
|
|
|
4828 |
$everyLine["dataCounts"]=count($everyLine["dataArray"]);
|
|
|
4829 |
|
|
|
4830 |
#取得原始輸入的多行字串
|
|
|
4831 |
$result["oriInput"]=$everyLine["oriStr"];
|
| 226 |
liveuser |
4832 |
|
| 3 |
liveuser |
4833 |
#取得原始的每一行
|
|
|
4834 |
$result["everyLine"]=$everyLine["dataArray"];
|
| 226 |
liveuser |
4835 |
|
| 3 |
liveuser |
4836 |
#取得資料表名稱
|
|
|
4837 |
#函式說明:
|
|
|
4838 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
4839 |
#回傳的參數:
|
|
|
4840 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
4841 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
4842 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
4843 |
#必填參數:
|
|
|
4844 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][0];#要處理的字串。
|
|
|
4845 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="`";#爲以哪個符號作爲分割
|
|
|
4846 |
$tableName=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
4847 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
4848 |
|
| 3 |
liveuser |
4849 |
#如果 取得資料表名稱 失敗
|
|
|
4850 |
if($tableName["status"]=="false"){
|
| 226 |
liveuser |
4851 |
|
| 3 |
liveuser |
4852 |
#設置錯誤訊息
|
|
|
4853 |
$result["status"]="false";
|
| 226 |
liveuser |
4854 |
|
| 3 |
liveuser |
4855 |
#設置錯誤提示
|
|
|
4856 |
$result["error"]=$tableName;
|
| 226 |
liveuser |
4857 |
|
| 3 |
liveuser |
4858 |
#回傳結果
|
|
|
4859 |
return $result;
|
| 226 |
liveuser |
4860 |
|
| 3 |
liveuser |
4861 |
}#if end
|
| 226 |
liveuser |
4862 |
|
| 3 |
liveuser |
4863 |
#取得資料表名稱
|
|
|
4864 |
$result["tableName"]=$tableName["dataArray"][1];
|
| 226 |
liveuser |
4865 |
|
| 3 |
liveuser |
4866 |
#取得資料表用的 ENGINE 與 DEFAULT CHARSET",亦即最後一行的內容.
|
|
|
4867 |
#函式說明:
|
|
|
4868 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
4869 |
#回傳的參數:
|
|
|
4870 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
4871 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
4872 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
4873 |
#必填參數:
|
|
|
4874 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][$everyLine["dataCounts"]-1];#要處理的字串。
|
|
|
4875 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
4876 |
$engineAndCharset=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
4877 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
4878 |
|
| 3 |
liveuser |
4879 |
#如果 取得資料表用的 ENGINE與DEFAULT CHARSET" 失敗
|
|
|
4880 |
if($engineAndCharset["status"]=="false"){
|
| 226 |
liveuser |
4881 |
|
| 3 |
liveuser |
4882 |
#設置錯誤訊息
|
|
|
4883 |
$result["status"]="false";
|
| 226 |
liveuser |
4884 |
|
| 3 |
liveuser |
4885 |
#設置錯誤提示
|
|
|
4886 |
$result["error"]=$engineAndCharset;
|
| 226 |
liveuser |
4887 |
|
| 3 |
liveuser |
4888 |
#回傳結果
|
|
|
4889 |
return $result;
|
| 226 |
liveuser |
4890 |
|
| 3 |
liveuser |
4891 |
}#if end
|
| 226 |
liveuser |
4892 |
|
| 3 |
liveuser |
4893 |
#get engine string
|
|
|
4894 |
$engine=$engineAndCharset["dataArray"][1];
|
| 226 |
liveuser |
4895 |
|
| 3 |
liveuser |
4896 |
#函式說明:
|
|
|
4897 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
4898 |
#回傳的參數:
|
|
|
4899 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
4900 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
4901 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
4902 |
#必填參數:
|
|
|
4903 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$engine;#要處理的字串。
|
|
|
4904 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="=";#爲以哪個符號作爲分割
|
|
|
4905 |
$engine=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
4906 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
4907 |
|
| 3 |
liveuser |
4908 |
#如果 取得資料表用的 ENGINE與DEFAULT CHARSET" 失敗
|
|
|
4909 |
if($engine["status"]=="false"){
|
| 226 |
liveuser |
4910 |
|
| 3 |
liveuser |
4911 |
#設置錯誤訊息
|
|
|
4912 |
$result["status"]="false";
|
| 226 |
liveuser |
4913 |
|
| 3 |
liveuser |
4914 |
#設置錯誤提示
|
|
|
4915 |
$result["error"]=$engine;
|
| 226 |
liveuser |
4916 |
|
| 3 |
liveuser |
4917 |
#回傳結果
|
|
|
4918 |
return $result;
|
| 226 |
liveuser |
4919 |
|
| 3 |
liveuser |
4920 |
}#if end
|
| 226 |
liveuser |
4921 |
|
| 3 |
liveuser |
4922 |
#如果不存在 engine
|
|
|
4923 |
if(!isset($engine["dataArray"][1])){
|
|
|
4924 |
|
|
|
4925 |
#設置錯誤訊息
|
|
|
4926 |
$result["status"]="false";
|
| 226 |
liveuser |
4927 |
|
| 3 |
liveuser |
4928 |
#設置錯誤提示
|
|
|
4929 |
$result["error"]=$engine;
|
|
|
4930 |
|
|
|
4931 |
return $result;
|
|
|
4932 |
|
|
|
4933 |
}#if end
|
|
|
4934 |
|
|
|
4935 |
#get engine
|
|
|
4936 |
$result["engine"]=$engine["dataArray"][1];
|
| 226 |
liveuser |
4937 |
|
| 3 |
liveuser |
4938 |
#取得字元編碼
|
|
|
4939 |
#函式說明:
|
|
|
4940 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
4941 |
#回傳的參數:
|
|
|
4942 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
4943 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
4944 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
4945 |
#必填參數:
|
|
|
4946 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$engineAndCharset["oriStr"];#要處理的字串。
|
|
|
4947 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="CHARSET=";#爲以哪個符號作爲分割
|
|
|
4948 |
$charset=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
4949 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
4950 |
|
| 3 |
liveuser |
4951 |
#如果 取得字元編碼 失敗
|
|
|
4952 |
if($charset["status"]=="false"){
|
| 226 |
liveuser |
4953 |
|
| 3 |
liveuser |
4954 |
#設置錯誤訊息
|
|
|
4955 |
$result["status"]="false";
|
| 226 |
liveuser |
4956 |
|
| 3 |
liveuser |
4957 |
#設置錯誤提示
|
|
|
4958 |
$result["error"]=$charset;
|
| 226 |
liveuser |
4959 |
|
| 3 |
liveuser |
4960 |
#回傳結果
|
|
|
4961 |
return $result;
|
| 226 |
liveuser |
4962 |
|
| 3 |
liveuser |
4963 |
}#if end
|
| 226 |
liveuser |
4964 |
|
| 3 |
liveuser |
4965 |
#取得字元編碼
|
|
|
4966 |
#函式說明:
|
|
|
4967 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
4968 |
#回傳的參數:
|
|
|
4969 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
4970 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
4971 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
4972 |
#必填參數:
|
|
|
4973 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$charset["dataArray"][1];#要處理的字串。
|
|
|
4974 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
4975 |
$charset=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
4976 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
4977 |
|
| 3 |
liveuser |
4978 |
#如果 取得字元編碼 失敗
|
|
|
4979 |
if($charset["status"]=="false"){
|
| 226 |
liveuser |
4980 |
|
| 3 |
liveuser |
4981 |
#設置錯誤訊息
|
|
|
4982 |
$result["status"]="false";
|
| 226 |
liveuser |
4983 |
|
| 3 |
liveuser |
4984 |
#設置錯誤提示
|
|
|
4985 |
$result["error"]=$charset;
|
| 226 |
liveuser |
4986 |
|
| 3 |
liveuser |
4987 |
#回傳結果
|
|
|
4988 |
return $result;
|
| 226 |
liveuser |
4989 |
|
| 3 |
liveuser |
4990 |
}#if end
|
| 226 |
liveuser |
4991 |
|
| 3 |
liveuser |
4992 |
#取得字元編碼
|
|
|
4993 |
$result["charset"]=$charset["dataArray"][0];
|
| 226 |
liveuser |
4994 |
|
| 3 |
liveuser |
4995 |
#初始化,儲存鍵值定義的陣列變數
|
|
|
4996 |
$keyDefine=array();
|
| 226 |
liveuser |
4997 |
|
| 3 |
liveuser |
4998 |
#逐行取得各欄位詳細資料
|
|
|
4999 |
for($i=1;$i<$everyLine["dataCounts"]-1;$i++){
|
| 226 |
liveuser |
5000 |
|
| 3 |
liveuser |
5001 |
#檢查開頭是否爲 " `"
|
|
|
5002 |
#函式說明:
|
|
|
5003 |
#取得符合特定字首與字尾的字串
|
|
|
5004 |
#回傳結果::
|
|
|
5005 |
#$result["status"],若爲"true"則代表執行正常;若爲"false"則代表執行失敗。
|
|
|
5006 |
#$result["function"],當前執行的函數名稱.
|
|
|
5007 |
#$result["error"],錯誤訊息陣列.
|
|
|
5008 |
#$result["founded"],若為"true"則代表有找到符合字首條件的結果;若爲"false"則代表沒有找到。
|
|
|
5009 |
#$result["returnString"],爲符合字首條件的字串內容。
|
|
|
5010 |
#必填參數:
|
|
|
5011 |
#$conf["checkString"],字串,要檢查的字串.
|
|
|
5012 |
$conf["search::getMeetConditionsString"]["checkString"]=$everyLine["dataArray"][$i];
|
|
|
5013 |
#可省略參數:
|
|
|
5014 |
#$conf["frontWord"],字串,用來檢查字首應該要有什麼字串,預設不指定.
|
|
|
5015 |
$conf["search::getMeetConditionsString"]["frontWord"]=" `";
|
|
|
5016 |
#$conf["tailWord"],字串,用來檢查字尾應該要有什麼字串,預設不指定.
|
|
|
5017 |
#$conf["tailWord"]="";
|
|
|
5018 |
#參考資料:
|
|
|
5019 |
#str_spilt(),可以將字串依照字母分割成一個個陣列字串。
|
|
|
5020 |
$getMeetConditionsString=search::getMeetConditionsString($conf["search::getMeetConditionsString"]);
|
|
|
5021 |
unset($conf["search::getMeetConditionsString"]);
|
| 226 |
liveuser |
5022 |
|
| 3 |
liveuser |
5023 |
#如果分割失敗
|
|
|
5024 |
if($getMeetConditionsString["status"]==="false"){
|
|
|
5025 |
|
|
|
5026 |
#設置錯誤訊息
|
|
|
5027 |
$result["status"]="false";
|
| 226 |
liveuser |
5028 |
|
| 3 |
liveuser |
5029 |
#設置錯誤提示
|
|
|
5030 |
$result["error"]=$getMeetConditionsString;
|
| 226 |
liveuser |
5031 |
|
| 3 |
liveuser |
5032 |
#回傳結果
|
|
|
5033 |
return $result;
|
|
|
5034 |
|
|
|
5035 |
}#if end
|
| 226 |
liveuser |
5036 |
|
| 3 |
liveuser |
5037 |
#如果有符合的前戳
|
|
|
5038 |
if($getMeetConditionsString["founded"]==="true"){
|
| 226 |
liveuser |
5039 |
|
| 3 |
liveuser |
5040 |
#函式說明:
|
|
|
5041 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5042 |
#回傳的參數:
|
|
|
5043 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5044 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5045 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5046 |
#必填參數:
|
|
|
5047 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][$i];#要處理的字串。
|
|
|
5048 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="`";#爲以哪個符號作爲分割
|
|
|
5049 |
$columnString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
5050 |
unset($conf["stringProcess"]["spiltString"]);
|
|
|
5051 |
|
|
|
5052 |
#如果 分割字串失敗 失敗
|
|
|
5053 |
if($columnString["status"]==="false"){
|
| 226 |
liveuser |
5054 |
|
| 3 |
liveuser |
5055 |
#設置錯誤訊息
|
|
|
5056 |
$result["status"]="false";
|
| 226 |
liveuser |
5057 |
|
| 3 |
liveuser |
5058 |
#設置錯誤提示
|
|
|
5059 |
$result["error"]=$columnString;
|
| 226 |
liveuser |
5060 |
|
| 3 |
liveuser |
5061 |
#回傳結果
|
|
|
5062 |
return $result;
|
| 226 |
liveuser |
5063 |
|
| 3 |
liveuser |
5064 |
}#if end
|
|
|
5065 |
|
|
|
5066 |
#取得欄位名稱
|
|
|
5067 |
$result["columnName"][$i]=$columnString["dataArray"][1];
|
|
|
5068 |
$result["columnName"][$result["columnName"][$i]]=$result["columnName"][$i];
|
|
|
5069 |
|
|
|
5070 |
#函式說明:
|
|
|
5071 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5072 |
#回傳的參數:
|
|
|
5073 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5074 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5075 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5076 |
#必填參數:
|
|
|
5077 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$columnString["dataArray"][2];#要處理的字串。
|
|
|
5078 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
5079 |
$columnString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
5080 |
unset($conf["stringProcess"]["spiltString"]);
|
|
|
5081 |
|
|
|
5082 |
#debug
|
|
|
5083 |
#var_dump($columnString);
|
|
|
5084 |
|
|
|
5085 |
#如果 分割字串失敗 失敗
|
|
|
5086 |
if($columnString["status"]==="false"){
|
| 226 |
liveuser |
5087 |
|
| 3 |
liveuser |
5088 |
#設置錯誤訊息
|
|
|
5089 |
$result["status"]="false";
|
| 226 |
liveuser |
5090 |
|
| 3 |
liveuser |
5091 |
#設置錯誤提示
|
|
|
5092 |
$result["error"]=$columnString;
|
| 226 |
liveuser |
5093 |
|
| 3 |
liveuser |
5094 |
#回傳結果
|
|
|
5095 |
return $result;
|
| 226 |
liveuser |
5096 |
|
| 3 |
liveuser |
5097 |
}#if end
|
| 226 |
liveuser |
5098 |
|
| 3 |
liveuser |
5099 |
#取得欄位屬性與長度
|
|
|
5100 |
$result["columnVarTypeAndLengthLimit"][$i]=$columnString["dataArray"][0];
|
|
|
5101 |
$result["columnVarTypeAndLengthLimit"][$result["columnName"][$i]]=$columnString["dataArray"][0];
|
| 226 |
liveuser |
5102 |
|
| 3 |
liveuser |
5103 |
}#if end
|
| 226 |
liveuser |
5104 |
|
| 3 |
liveuser |
5105 |
#函式說明:
|
|
|
5106 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5107 |
#回傳的參數:
|
|
|
5108 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5109 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5110 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5111 |
#必填參數:
|
|
|
5112 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][$i];#要處理的字串。
|
|
|
5113 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
5114 |
$columnString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
5115 |
unset($conf["stringProcess"]["spiltString"]);
|
| 3 |
liveuser |
5116 |
|
|
|
5117 |
#如果 分割字串失敗 失敗
|
|
|
5118 |
if($columnString["status"]=="false"){
|
| 226 |
liveuser |
5119 |
|
| 3 |
liveuser |
5120 |
#設置錯誤訊息
|
|
|
5121 |
$result["status"]="false";
|
| 226 |
liveuser |
5122 |
|
| 3 |
liveuser |
5123 |
#設置錯誤提示
|
|
|
5124 |
$result["error"]=$columnString;
|
| 226 |
liveuser |
5125 |
|
| 3 |
liveuser |
5126 |
#回傳結果
|
|
|
5127 |
return $result;
|
| 226 |
liveuser |
5128 |
|
| 3 |
liveuser |
5129 |
}#if end
|
|
|
5130 |
|
|
|
5131 |
#如果分割字串失敗
|
|
|
5132 |
if($columnString["status"]==="false"){
|
| 226 |
liveuser |
5133 |
|
| 3 |
liveuser |
5134 |
#設置執行失敗
|
|
|
5135 |
$reuslt["status"]="false";
|
| 226 |
liveuser |
5136 |
|
| 3 |
liveuser |
5137 |
#設置錯誤訊息
|
|
|
5138 |
$result["error"]=$columnString;
|
| 226 |
liveuser |
5139 |
|
| 3 |
liveuser |
5140 |
#回傳結果
|
|
|
5141 |
return $result;
|
| 226 |
liveuser |
5142 |
|
| 3 |
liveuser |
5143 |
}#if end
|
| 226 |
liveuser |
5144 |
|
| 3 |
liveuser |
5145 |
#debug
|
|
|
5146 |
#var_dump($columnString);
|
| 226 |
liveuser |
5147 |
|
| 3 |
liveuser |
5148 |
#判斷該 $columnString["dataArray"][2]是一般名稱,還是鍵值定義。
|
|
|
5149 |
#函式說明:
|
|
|
5150 |
#檢查字串裡面有無指定的關鍵字
|
|
|
5151 |
#回傳結果::
|
|
|
5152 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
5153 |
#$result["error"],錯誤訊息
|
|
|
5154 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
5155 |
#必填參數:
|
|
|
5156 |
$conf["search"]["findKeyWord"]["keyWord"]="`";#想要搜尋的關鍵字
|
|
|
5157 |
$conf["search"]["findKeyWord"]["string"]=$columnString["dataArray"][2];#要被搜尋的字串內容
|
|
|
5158 |
#可省略參數:
|
|
|
5159 |
#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
5160 |
$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
|
|
|
5161 |
unset($conf["search"]["findKeyWord"]);
|
| 226 |
liveuser |
5162 |
|
| 3 |
liveuser |
5163 |
#如果尋找失敗
|
|
|
5164 |
if($searchResult["status"]==="false"){
|
| 226 |
liveuser |
5165 |
|
| 3 |
liveuser |
5166 |
#設置執行失敗
|
|
|
5167 |
$reuslt["status"]="false";
|
| 226 |
liveuser |
5168 |
|
| 3 |
liveuser |
5169 |
#設置錯誤訊息
|
|
|
5170 |
$result["error"]=$columnString;
|
| 226 |
liveuser |
5171 |
|
| 3 |
liveuser |
5172 |
#回傳結果
|
|
|
5173 |
return $result;
|
| 226 |
liveuser |
5174 |
|
| 3 |
liveuser |
5175 |
}#if end
|
| 226 |
liveuser |
5176 |
|
| 3 |
liveuser |
5177 |
#如果有找到,且沒有長度與形態資訊
|
|
|
5178 |
if($searchResult["founded"]==="true" && !isset($result["columnVarTypeAndLengthLimit"][$i]) ){
|
| 226 |
liveuser |
5179 |
|
| 3 |
liveuser |
5180 |
#代表是屬於鍵值的定義
|
|
|
5181 |
$keyDefine[]=$everyLine["dataArray"][$i];
|
| 226 |
liveuser |
5182 |
|
| 3 |
liveuser |
5183 |
#var_dump($keyDefine);
|
| 226 |
liveuser |
5184 |
|
| 3 |
liveuser |
5185 |
#跳過該行內容
|
|
|
5186 |
continue;
|
| 226 |
liveuser |
5187 |
|
| 3 |
liveuser |
5188 |
}#if end
|
| 226 |
liveuser |
5189 |
|
| 3 |
liveuser |
5190 |
#判斷該 $columnString["dataArray"][0]是否為 "CONSTRAINT" 或 "KEY"
|
|
|
5191 |
if($columnString["dataArray"][0]==="CONSTRAINT" || $columnString["dataArray"][0]==="KEY"){
|
| 226 |
liveuser |
5192 |
|
| 3 |
liveuser |
5193 |
#代表是屬於定義 外鍵 的 CONSTRAINT 定義
|
|
|
5194 |
$keyDefine[]=$everyLine["dataArray"][$i];
|
| 226 |
liveuser |
5195 |
|
| 3 |
liveuser |
5196 |
#跳過該行內容
|
|
|
5197 |
continue;
|
| 226 |
liveuser |
5198 |
|
| 3 |
liveuser |
5199 |
}#if end
|
| 226 |
liveuser |
5200 |
|
| 3 |
liveuser |
5201 |
#函式說明:
|
|
|
5202 |
#處理字串避免網頁出錯
|
|
|
5203 |
#回傳結果::
|
|
|
5204 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
5205 |
#$result["function"],當前執行的函數.
|
|
|
5206 |
#$result["content"],爲處理好的字串.
|
|
|
5207 |
#$result["error"],錯誤訊息陣列.
|
|
|
5208 |
#必填參數:
|
|
|
5209 |
$conf["stringProcess"]["correctCharacter"]["stringIn"]=$columnString["dataArray"][0];#爲要處理的字串
|
|
|
5210 |
#可省略參數:
|
|
|
5211 |
$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array("`");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
5212 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
5213 |
#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
5214 |
$correctCharacterResult=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
|
|
|
5215 |
unset($conf["stringProcess"]);
|
|
|
5216 |
|
|
|
5217 |
#如果處理字串失敗
|
|
|
5218 |
if($correctCharacterResult["status"]==="false"){
|
| 226 |
liveuser |
5219 |
|
| 3 |
liveuser |
5220 |
#設置執行失敗
|
|
|
5221 |
$reuslt["status"]="false";
|
| 226 |
liveuser |
5222 |
|
| 3 |
liveuser |
5223 |
#設置錯誤訊息
|
|
|
5224 |
$result["error"]=$correctCharacterResult;
|
| 226 |
liveuser |
5225 |
|
| 3 |
liveuser |
5226 |
#回傳結果
|
|
|
5227 |
return $result;
|
| 226 |
liveuser |
5228 |
|
| 3 |
liveuser |
5229 |
}#if end
|
| 226 |
liveuser |
5230 |
|
| 3 |
liveuser |
5231 |
#如果不是 "CONSTRAINT" 且 存在 $result["columnVarTypeAndLengthLimit"][$i]
|
|
|
5232 |
if($correctCharacterResult["content"]!=="CONSTRAINT" && isset($result["columnVarTypeAndLengthLimit"][$i])){
|
| 226 |
liveuser |
5233 |
|
| 3 |
liveuser |
5234 |
#取得欄位名稱,遇到有空格的欄位名稱會出錯
|
|
|
5235 |
#$result["columnName"][$i]=$correctCharacterResult["content"];
|
|
|
5236 |
#$result["columnName"][$correctCharacterResult["content"]]=$correctCharacterResult["content"];
|
| 226 |
liveuser |
5237 |
|
| 3 |
liveuser |
5238 |
#取得欄位變數形態與長度限制,遇到有空格的欄位名稱會出錯
|
|
|
5239 |
#$result["columnVarTypeAndLengthLimit"][$i]=$columnString["dataArray"][1];
|
|
|
5240 |
#$result["columnVarTypeAndLengthLimit"][$result["columnName"][$i]]=$columnString["dataArray"][1];
|
| 226 |
liveuser |
5241 |
|
| 3 |
liveuser |
5242 |
#檢查是否有欄位的長度限制關鍵字 "(" ")"
|
|
|
5243 |
#函式說明:
|
|
|
5244 |
#檢查一個字串裡面是否有多個關鍵字
|
|
|
5245 |
#回傳結果::
|
|
|
5246 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
5247 |
#$result["error"],錯誤訊息
|
|
|
5248 |
#$result["founded"],是否找到所有的關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
5249 |
#必填參數:
|
|
|
5250 |
$conf["search"]["findManyKeyWords"]["keyWords"]=array("(",")");#想要搜尋的關鍵字
|
|
|
5251 |
$conf["search"]["findManyKeyWords"]["string"]=$result["columnVarTypeAndLengthLimit"][$i];#要被搜尋的字串內容
|
|
|
5252 |
#可省略參數:
|
|
|
5253 |
#$conf["search"]["findManyKeyWords"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
5254 |
$lengthLimitKeyWordSearchResult=search::findManyKeyWords($conf["search"]["findManyKeyWords"]);
|
|
|
5255 |
unset($conf["search"]["findManyKeyWords"]);
|
| 226 |
liveuser |
5256 |
|
| 3 |
liveuser |
5257 |
#如果 檢查是否有欄位的長度限制關鍵字 "(" ")" 失敗
|
|
|
5258 |
if($lengthLimitKeyWordSearchResult["status"]==="false"){
|
| 226 |
liveuser |
5259 |
|
| 3 |
liveuser |
5260 |
#設置執行失敗
|
|
|
5261 |
$reuslt["status"]="false";
|
| 226 |
liveuser |
5262 |
|
| 3 |
liveuser |
5263 |
#設置錯誤訊息
|
|
|
5264 |
$result["error"]=$lengthLimitKeyWordSearchResult;
|
| 226 |
liveuser |
5265 |
|
| 3 |
liveuser |
5266 |
#回傳結果
|
|
|
5267 |
return $result;
|
| 226 |
liveuser |
5268 |
|
| 3 |
liveuser |
5269 |
}#if end
|
| 226 |
liveuser |
5270 |
|
| 3 |
liveuser |
5271 |
#如果 $lengthLimitKeyWordSearchResult["founded"] 等於 "true"
|
|
|
5272 |
if($lengthLimitKeyWordSearchResult["foundedAll"]==="true"){
|
| 226 |
liveuser |
5273 |
|
| 3 |
liveuser |
5274 |
#代表有長度限制的字串
|
| 226 |
liveuser |
5275 |
|
| 3 |
liveuser |
5276 |
#以"("為關鍵字進行分割
|
|
|
5277 |
#函式說明:
|
|
|
5278 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5279 |
#回傳的參數:
|
|
|
5280 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5281 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5282 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5283 |
#必填參數:
|
|
|
5284 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$result["columnVarTypeAndLengthLimit"][$i];#要處理的字串。
|
|
|
5285 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="(";#爲以哪個符號作爲分割
|
|
|
5286 |
$columnTypeAndLengthLimitSpiledStr=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
5287 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
5288 |
|
| 3 |
liveuser |
5289 |
#如果分割字串失敗
|
|
|
5290 |
if($columnTypeAndLengthLimitSpiledStr["status"]==="false"){
|
| 226 |
liveuser |
5291 |
|
| 3 |
liveuser |
5292 |
#設置執行失敗
|
|
|
5293 |
$reuslt["status"]="false";
|
| 226 |
liveuser |
5294 |
|
| 3 |
liveuser |
5295 |
#設置錯誤訊息
|
|
|
5296 |
$result["error"]=$columnTypeAndLengthLimitSpiledStr;
|
| 226 |
liveuser |
5297 |
|
| 3 |
liveuser |
5298 |
#回傳結果
|
|
|
5299 |
return $result;
|
| 226 |
liveuser |
5300 |
|
| 3 |
liveuser |
5301 |
}#if end
|
| 226 |
liveuser |
5302 |
|
| 3 |
liveuser |
5303 |
#取得欄位變數型別
|
|
|
5304 |
$result["columnVarType"][$i]=$columnTypeAndLengthLimitSpiledStr["dataArray"][0];
|
|
|
5305 |
$result["columnVarType"][$result["columnName"][$i]]=$columnTypeAndLengthLimitSpiledStr["dataArray"][0];
|
| 226 |
liveuser |
5306 |
|
| 3 |
liveuser |
5307 |
#以")"為關鍵字進行分割
|
|
|
5308 |
#函式說明:
|
|
|
5309 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5310 |
#回傳的參數:
|
|
|
5311 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5312 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5313 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5314 |
#必填參數:
|
|
|
5315 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$columnTypeAndLengthLimitSpiledStr["dataArray"][1];#要處理的字串。
|
|
|
5316 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=")";#爲以哪個符號作爲分割
|
|
|
5317 |
$columnTypeAndLengthLimitSpiledStr=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
5318 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
5319 |
|
| 3 |
liveuser |
5320 |
#如果分割字串失敗
|
|
|
5321 |
if($columnTypeAndLengthLimitSpiledStr["status"]==="false"){
|
| 226 |
liveuser |
5322 |
|
| 3 |
liveuser |
5323 |
#設置執行失敗
|
|
|
5324 |
$reuslt["status"]="false";
|
| 226 |
liveuser |
5325 |
|
| 3 |
liveuser |
5326 |
#設置錯誤訊息
|
|
|
5327 |
$result["error"]=$columnTypeAndLengthLimitSpiledStr;
|
| 226 |
liveuser |
5328 |
|
| 3 |
liveuser |
5329 |
#回傳結果
|
|
|
5330 |
return $result;
|
| 226 |
liveuser |
5331 |
|
| 3 |
liveuser |
5332 |
}#if end
|
| 226 |
liveuser |
5333 |
|
| 3 |
liveuser |
5334 |
#取得欄位的長度限制
|
|
|
5335 |
$result["columnVarLengthLimit"][$i]=$columnTypeAndLengthLimitSpiledStr["dataArray"][0];
|
|
|
5336 |
$result["columnVarLengthLimit"][$result["columnName"][$i]]=$columnTypeAndLengthLimitSpiledStr["dataArray"][0];
|
| 226 |
liveuser |
5337 |
|
| 3 |
liveuser |
5338 |
}#if end
|
| 226 |
liveuser |
5339 |
|
| 3 |
liveuser |
5340 |
#反之代表沒有長度限制的字串
|
|
|
5341 |
else{
|
| 226 |
liveuser |
5342 |
|
| 3 |
liveuser |
5343 |
#取得欄位變數型別
|
|
|
5344 |
$result["columnVarType"][$i]=$result["columnVarTypeAndLengthLimit"][$i];
|
|
|
5345 |
$result["columnVarType"][$result["columnName"][$i]]=$result["columnVarTypeAndLengthLimit"][$i];
|
| 226 |
liveuser |
5346 |
|
| 3 |
liveuser |
5347 |
#取得欄位變數長度限制
|
|
|
5348 |
$result["columnVarLengthLimit"][$i]="";
|
|
|
5349 |
$result["columnVarLengthLimit"][$result["columnName"][$i]]="";
|
| 226 |
liveuser |
5350 |
|
| 3 |
liveuser |
5351 |
}#else
|
| 226 |
liveuser |
5352 |
|
| 3 |
liveuser |
5353 |
#欄位是否不可為null
|
|
|
5354 |
#函式說明:
|
|
|
5355 |
#檢查字串裡面有無指定的關鍵字
|
|
|
5356 |
#回傳結果::
|
|
|
5357 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
5358 |
#$result["error"],錯誤訊息
|
|
|
5359 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
5360 |
#必填參數:
|
|
|
5361 |
$conf["search"]["findKeyWord"]["keyWord"]="NOT NULL";#想要搜尋的關鍵字
|
|
|
5362 |
$conf["search"]["findKeyWord"]["string"]=$everyLine["dataArray"][$i];#要被搜尋的字串內容
|
|
|
5363 |
#可省略參數:
|
|
|
5364 |
#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
5365 |
$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
|
|
|
5366 |
unset($conf["search"]["findKeyWord"]);
|
| 226 |
liveuser |
5367 |
|
| 3 |
liveuser |
5368 |
#如果取得 欄位是否不可為null 失敗
|
|
|
5369 |
if($searchResult["status"]==="false"){
|
| 226 |
liveuser |
5370 |
|
| 3 |
liveuser |
5371 |
#設置執行失敗
|
|
|
5372 |
$reuslt["status"]="false";
|
| 226 |
liveuser |
5373 |
|
| 3 |
liveuser |
5374 |
#設置錯誤訊息
|
|
|
5375 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
5376 |
|
| 3 |
liveuser |
5377 |
#回傳結果
|
|
|
5378 |
return $result;
|
| 226 |
liveuser |
5379 |
|
| 3 |
liveuser |
5380 |
}#if end
|
| 226 |
liveuser |
5381 |
|
| 3 |
liveuser |
5382 |
#如果有找到 NOT NULL
|
|
|
5383 |
if($searchResult["founded"]==="true"){
|
| 226 |
liveuser |
5384 |
|
| 3 |
liveuser |
5385 |
$result["columnNotNull"][$i]="true";
|
|
|
5386 |
$result["columnNotNull"][$result["columnName"][$i]]="true";
|
| 226 |
liveuser |
5387 |
|
| 3 |
liveuser |
5388 |
}#if end
|
| 226 |
liveuser |
5389 |
|
| 3 |
liveuser |
5390 |
#反之沒有找到 NOT NULL
|
|
|
5391 |
else{
|
| 226 |
liveuser |
5392 |
|
| 3 |
liveuser |
5393 |
$result["columnNotNull"][$i]="false";
|
|
|
5394 |
$result["columnNotNull"][$result["columnName"][$i]]="false";
|
| 226 |
liveuser |
5395 |
|
| 3 |
liveuser |
5396 |
}#else end
|
| 226 |
liveuser |
5397 |
|
| 3 |
liveuser |
5398 |
#欄位是否會自動加1
|
|
|
5399 |
#函式說明:
|
|
|
5400 |
#檢查字串裡面有無指定的關鍵字
|
|
|
5401 |
#回傳結果::
|
|
|
5402 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
5403 |
#$result["error"],錯誤訊息
|
|
|
5404 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
5405 |
#必填參數:
|
|
|
5406 |
$conf["search"]["findKeyWord"]["keyWord"]="AUTO_INCREMENT";#想要搜尋的關鍵字
|
|
|
5407 |
$conf["search"]["findKeyWord"]["string"]=$everyLine["dataArray"][$i];#要被搜尋的字串內容
|
|
|
5408 |
#可省略參數:
|
|
|
5409 |
#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
5410 |
$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
|
|
|
5411 |
unset($conf["search"]["findKeyWord"]);
|
| 226 |
liveuser |
5412 |
|
| 3 |
liveuser |
5413 |
#如果取得 欄位是否會自動加1 失敗
|
|
|
5414 |
if($searchResult["status"]==="false"){
|
| 226 |
liveuser |
5415 |
|
| 3 |
liveuser |
5416 |
#設置執行失敗
|
|
|
5417 |
$reuslt["status"]="false";
|
| 226 |
liveuser |
5418 |
|
| 3 |
liveuser |
5419 |
#設置錯誤訊息
|
|
|
5420 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
5421 |
|
| 3 |
liveuser |
5422 |
#回傳結果
|
|
|
5423 |
return $result;
|
| 226 |
liveuser |
5424 |
|
| 3 |
liveuser |
5425 |
}#if end
|
| 226 |
liveuser |
5426 |
|
| 3 |
liveuser |
5427 |
#如果有找到 AUTO_INCREMENT
|
|
|
5428 |
if($searchResult["founded"]==="true"){
|
| 226 |
liveuser |
5429 |
|
| 3 |
liveuser |
5430 |
$result["columnAutoIncrement"][$i]="true";
|
|
|
5431 |
$result["columnAutoIncrement"][$result["columnName"][$i]]="true";
|
| 226 |
liveuser |
5432 |
|
| 3 |
liveuser |
5433 |
}#if end
|
| 226 |
liveuser |
5434 |
|
| 3 |
liveuser |
5435 |
#反之沒有 AUTO_INCREMENT
|
|
|
5436 |
else{
|
| 226 |
liveuser |
5437 |
|
| 3 |
liveuser |
5438 |
$result["columnAutoIncrement"][$i]="false";
|
|
|
5439 |
$result["columnAutoIncrement"][$result["columnName"][$i]]="false";
|
| 226 |
liveuser |
5440 |
|
| 3 |
liveuser |
5441 |
}#else end
|
| 226 |
liveuser |
5442 |
|
| 3 |
liveuser |
5443 |
#欄位是否有預設內容
|
| 226 |
liveuser |
5444 |
|
| 3 |
liveuser |
5445 |
#函式說明:
|
|
|
5446 |
#檢查字串裡面有無指定的關鍵字
|
|
|
5447 |
#回傳結果::
|
|
|
5448 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
5449 |
#$result["error"],錯誤訊息
|
|
|
5450 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
5451 |
#必填參數:
|
|
|
5452 |
$conf["search"]["findKeyWord"]["keyWord"]="DEFAULT";#想要搜尋的關鍵字
|
|
|
5453 |
$conf["search"]["findKeyWord"]["string"]=$everyLine["dataArray"][$i];#要被搜尋的字串內容
|
|
|
5454 |
#可省略參數:
|
|
|
5455 |
#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
5456 |
$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
|
|
|
5457 |
unset($conf["search"]["findKeyWord"]);
|
| 226 |
liveuser |
5458 |
|
| 3 |
liveuser |
5459 |
#如果取得 欄位是否有預設內容 失敗
|
|
|
5460 |
if($searchResult["status"]==="false"){
|
| 226 |
liveuser |
5461 |
|
| 3 |
liveuser |
5462 |
#設置執行失敗
|
|
|
5463 |
$reuslt["status"]="false";
|
| 226 |
liveuser |
5464 |
|
| 3 |
liveuser |
5465 |
#設置錯誤訊息
|
|
|
5466 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
5467 |
|
| 3 |
liveuser |
5468 |
#回傳結果
|
|
|
5469 |
return $result;
|
| 226 |
liveuser |
5470 |
|
| 3 |
liveuser |
5471 |
}#if end
|
| 226 |
liveuser |
5472 |
|
| 3 |
liveuser |
5473 |
#如果有找到 DEFAULT
|
|
|
5474 |
if($searchResult["founded"]==="true"){
|
| 226 |
liveuser |
5475 |
|
| 3 |
liveuser |
5476 |
#函式說明:
|
|
|
5477 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5478 |
#回傳的參數:
|
|
|
5479 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5480 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5481 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5482 |
#必填參數:
|
|
|
5483 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][$i];#要處理的字串。
|
|
|
5484 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="DEFAULT ";#爲以哪個符號作爲分割
|
|
|
5485 |
$defaultString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
5486 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
5487 |
|
| 3 |
liveuser |
5488 |
#如果分割字串失敗
|
|
|
5489 |
if($defaultString["status"]=="false"){
|
| 226 |
liveuser |
5490 |
|
| 3 |
liveuser |
5491 |
#設置執行失敗
|
|
|
5492 |
$result["status"]="false";
|
| 226 |
liveuser |
5493 |
|
| 3 |
liveuser |
5494 |
#設置執行錯誤訊息
|
|
|
5495 |
$result["error"]=$defaultString;
|
| 226 |
liveuser |
5496 |
|
| 3 |
liveuser |
5497 |
#回傳結果
|
|
|
5498 |
return $result;
|
| 226 |
liveuser |
5499 |
|
| 3 |
liveuser |
5500 |
}#if end
|
| 226 |
liveuser |
5501 |
|
| 3 |
liveuser |
5502 |
#函式說明:
|
|
|
5503 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5504 |
#回傳的參數:
|
|
|
5505 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5506 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5507 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5508 |
#必填參數:
|
|
|
5509 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$defaultString["dataArray"][1];#要處理的字串。
|
|
|
5510 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
5511 |
$defaultString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
5512 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
5513 |
|
| 3 |
liveuser |
5514 |
#如果分割字串失敗
|
|
|
5515 |
if($defaultString["status"]=="false"){
|
| 226 |
liveuser |
5516 |
|
| 3 |
liveuser |
5517 |
#設置執行失敗
|
|
|
5518 |
$result["status"]="false";
|
| 226 |
liveuser |
5519 |
|
| 3 |
liveuser |
5520 |
#設置執行錯誤訊息
|
|
|
5521 |
$result["error"]=$defaultString;
|
| 226 |
liveuser |
5522 |
|
| 3 |
liveuser |
5523 |
#回傳結果
|
|
|
5524 |
return $result;
|
| 226 |
liveuser |
5525 |
|
| 3 |
liveuser |
5526 |
}#if end
|
| 226 |
liveuser |
5527 |
|
|
|
5528 |
#將「,」,「'」去掉
|
| 3 |
liveuser |
5529 |
#函式說明:
|
|
|
5530 |
#處理字串避免網頁出錯
|
|
|
5531 |
#回傳結果::
|
|
|
5532 |
#$result,爲處理好的字串。
|
|
|
5533 |
#必填參數:
|
|
|
5534 |
$conf["stringProcess"]["correctCharacter"]["stringIn"]=$defaultString["dataArray"][0];#爲要處理的字串
|
|
|
5535 |
#可省略參數:
|
|
|
5536 |
$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",","'");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
5537 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
5538 |
#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
5539 |
$thisColumnDefaultValue=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
|
|
|
5540 |
unset($conf["stringProcess"]["correctCharacter"]);
|
| 226 |
liveuser |
5541 |
|
| 3 |
liveuser |
5542 |
#如果處理字串失敗
|
|
|
5543 |
if($thisColumnDefaultValue["status"]=="false"){
|
| 226 |
liveuser |
5544 |
|
| 3 |
liveuser |
5545 |
#設置執行不正常
|
|
|
5546 |
$result["status"]="false";
|
| 226 |
liveuser |
5547 |
|
| 3 |
liveuser |
5548 |
#設置錯誤訊息
|
|
|
5549 |
$result["error"]=$thisColumnDefaultValue;
|
| 226 |
liveuser |
5550 |
|
| 3 |
liveuser |
5551 |
#回傳結果
|
|
|
5552 |
return $result;
|
| 226 |
liveuser |
5553 |
|
| 3 |
liveuser |
5554 |
}#if end
|
| 226 |
liveuser |
5555 |
|
| 3 |
liveuser |
5556 |
#取得該欄位的預設內容
|
|
|
5557 |
$result["columnDefault"][$i]=$thisColumnDefaultValue["content"];
|
|
|
5558 |
$result["columnDefault"][$result["columnName"][$i]]=$thisColumnDefaultValue["content"];
|
| 226 |
liveuser |
5559 |
|
| 3 |
liveuser |
5560 |
}#if end
|
| 226 |
liveuser |
5561 |
|
|
|
5562 |
#反之沒有找到 DEFAULT
|
| 3 |
liveuser |
5563 |
else{
|
| 226 |
liveuser |
5564 |
|
| 3 |
liveuser |
5565 |
$result["columnDefault"][$i]="沒有指定";
|
|
|
5566 |
$result["columnDefault"][$result["columnName"][$i]]=$result["columnDefault"][$i];
|
| 226 |
liveuser |
5567 |
|
| 3 |
liveuser |
5568 |
}#else end
|
| 226 |
liveuser |
5569 |
|
| 3 |
liveuser |
5570 |
#如果有欄位內有 ON UPDATE 的字樣
|
| 226 |
liveuser |
5571 |
|
| 3 |
liveuser |
5572 |
#函式說明:
|
|
|
5573 |
#檢查字串裡面有無指定的關鍵字
|
|
|
5574 |
#回傳結果::
|
|
|
5575 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
5576 |
#$result["error"],錯誤訊息
|
|
|
5577 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
5578 |
#必填參數:
|
|
|
5579 |
$conf["search"]["findKeyWord"]["keyWord"]="ON UPDATE";#想要搜尋的關鍵字
|
|
|
5580 |
$conf["search"]["findKeyWord"]["string"]=$everyLine["dataArray"][$i];#要被搜尋的字串內容
|
|
|
5581 |
#可省略參數:
|
|
|
5582 |
#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
5583 |
$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
|
|
|
5584 |
unset($conf["search"]["findKeyWord"]);
|
| 226 |
liveuser |
5585 |
|
| 3 |
liveuser |
5586 |
#如果尋找 欄位內是否有 ON UPDATE 的字樣失敗
|
|
|
5587 |
if($searchResult["status"]==="false"){
|
| 226 |
liveuser |
5588 |
|
| 3 |
liveuser |
5589 |
#設置執行失敗
|
|
|
5590 |
$result["status"]="false";
|
| 226 |
liveuser |
5591 |
|
| 3 |
liveuser |
5592 |
#設置執行錯誤訊息
|
|
|
5593 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
5594 |
|
| 3 |
liveuser |
5595 |
#回傳結果
|
|
|
5596 |
return $result;
|
| 226 |
liveuser |
5597 |
|
| 3 |
liveuser |
5598 |
}#if end
|
| 226 |
liveuser |
5599 |
|
| 3 |
liveuser |
5600 |
#如果有找到 ON UPDATE
|
| 226 |
liveuser |
5601 |
if($searchResult["founded"]==="true"){
|
|
|
5602 |
|
| 3 |
liveuser |
5603 |
#函式說明:
|
|
|
5604 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5605 |
#回傳的參數:
|
|
|
5606 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5607 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5608 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5609 |
#必填參數:
|
|
|
5610 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][$i];#要處理的字串。
|
|
|
5611 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="ON UPDATE ";#爲以哪個符號作爲分割
|
|
|
5612 |
$onUpdateString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
5613 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
5614 |
|
| 3 |
liveuser |
5615 |
#函式說明:
|
|
|
5616 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5617 |
#回傳的參數:
|
|
|
5618 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5619 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5620 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5621 |
#必填參數:
|
|
|
5622 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$onUpdateString["dataArray"][1];#要處理的字串。
|
|
|
5623 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
5624 |
$onUpdateString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
5625 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
5626 |
|
| 3 |
liveuser |
5627 |
#如果分割字串失敗
|
|
|
5628 |
if($onUpdateString["status"]=="false"){
|
| 226 |
liveuser |
5629 |
|
| 3 |
liveuser |
5630 |
#設置執行不正常
|
|
|
5631 |
$result["status"]="false";
|
| 226 |
liveuser |
5632 |
|
| 3 |
liveuser |
5633 |
#設置錯誤訊息
|
|
|
5634 |
$result["error"]=$onUpdateString;
|
| 226 |
liveuser |
5635 |
|
| 3 |
liveuser |
5636 |
#回傳結果
|
|
|
5637 |
return $result;
|
| 226 |
liveuser |
5638 |
|
| 3 |
liveuser |
5639 |
}#if end
|
| 226 |
liveuser |
5640 |
|
|
|
5641 |
#將「,」去掉
|
| 3 |
liveuser |
5642 |
#函式說明:
|
|
|
5643 |
#處理字串避免網頁出錯
|
|
|
5644 |
#回傳結果::
|
|
|
5645 |
#$result,爲處理好的字串。
|
|
|
5646 |
#必填參數:
|
|
|
5647 |
$conf["stringProcess"]["correctCharacter"]["stringIn"]=$onUpdateString["dataArray"][0];#爲要處理的字串
|
|
|
5648 |
#可省略參數:
|
|
|
5649 |
$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
5650 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
5651 |
#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
5652 |
$columnOnUpdateActionStr=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
|
|
|
5653 |
unset($conf["stringProcess"]["correctCharacter"]);
|
| 226 |
liveuser |
5654 |
|
| 3 |
liveuser |
5655 |
#如果 處理字串失敗
|
|
|
5656 |
if($columnOnUpdateActionStr["status"]=="false"){
|
| 226 |
liveuser |
5657 |
|
| 3 |
liveuser |
5658 |
#設置執行不正常
|
|
|
5659 |
$result["status"]="false";
|
| 226 |
liveuser |
5660 |
|
| 3 |
liveuser |
5661 |
#設置錯誤訊息
|
|
|
5662 |
$result["error"]=$columnOnUpdateActionStr;
|
| 226 |
liveuser |
5663 |
|
| 3 |
liveuser |
5664 |
#回傳結果
|
|
|
5665 |
return $result;
|
| 226 |
liveuser |
5666 |
|
| 3 |
liveuser |
5667 |
}#if end
|
| 226 |
liveuser |
5668 |
|
| 3 |
liveuser |
5669 |
#取得 ON UPDATE 的對應動作
|
|
|
5670 |
$result["columnOnUpdateAction"][$result["columnName"][$i]]=$columnOnUpdateActionStr["content"];
|
|
|
5671 |
$result["columnOnUpdateAction"][$i]=$columnOnUpdateActionStr["content"];
|
| 226 |
liveuser |
5672 |
|
| 3 |
liveuser |
5673 |
}#if end
|
| 226 |
liveuser |
5674 |
|
| 3 |
liveuser |
5675 |
#反之,沒有 ON UPDATE 的對應動作
|
|
|
5676 |
else{
|
| 226 |
liveuser |
5677 |
|
| 3 |
liveuser |
5678 |
$result["columnOnUpdateAction"][$i]="沒有指定";
|
|
|
5679 |
$result["columnOnUpdateAction"][$result["columnName"][$i]]=$result["columnOnUpdateAction"][$i];
|
| 226 |
liveuser |
5680 |
|
| 3 |
liveuser |
5681 |
}#else end
|
| 226 |
liveuser |
5682 |
|
| 3 |
liveuser |
5683 |
}#if end
|
| 226 |
liveuser |
5684 |
|
| 3 |
liveuser |
5685 |
#如果有欄位內有 CHARACTER SET 的字樣
|
| 226 |
liveuser |
5686 |
|
| 3 |
liveuser |
5687 |
#函式說明:
|
|
|
5688 |
#檢查字串裡面有無指定的關鍵字
|
|
|
5689 |
#回傳結果::
|
|
|
5690 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
5691 |
#$result["error"],錯誤訊息
|
|
|
5692 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
5693 |
#必填參數:
|
|
|
5694 |
$conf["search"]["findKeyWord"]["keyWord"]="CHARACTER SET";#想要搜尋的關鍵字
|
|
|
5695 |
$conf["search"]["findKeyWord"]["string"]=$everyLine["dataArray"][$i];#要被搜尋的字串內容
|
|
|
5696 |
#可省略參數:
|
|
|
5697 |
#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
5698 |
$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
|
|
|
5699 |
unset($conf["search"]["findKeyWord"]);
|
| 226 |
liveuser |
5700 |
|
| 3 |
liveuser |
5701 |
#如果尋找關鍵字失敗
|
|
|
5702 |
if($searchResult["status"]==="false"){
|
| 226 |
liveuser |
5703 |
|
| 3 |
liveuser |
5704 |
#設置執行不正常
|
|
|
5705 |
$result["status"]="false";
|
| 226 |
liveuser |
5706 |
|
| 3 |
liveuser |
5707 |
#設置錯誤訊息
|
|
|
5708 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
5709 |
|
| 3 |
liveuser |
5710 |
#回傳結果
|
|
|
5711 |
return $result;
|
| 226 |
liveuser |
5712 |
|
| 3 |
liveuser |
5713 |
}#if end
|
| 226 |
liveuser |
5714 |
|
| 3 |
liveuser |
5715 |
#如果有找到 CHARACTER SET
|
| 226 |
liveuser |
5716 |
if($searchResult["founded"]==="true"){
|
|
|
5717 |
|
| 3 |
liveuser |
5718 |
#函式說明:
|
|
|
5719 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5720 |
#回傳的參數:
|
|
|
5721 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5722 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5723 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5724 |
#必填參數:
|
|
|
5725 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][$i];#要處理的字串。
|
|
|
5726 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="CHARACTER SET ";#爲以哪個符號作爲分割
|
|
|
5727 |
$characterSetString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
5728 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
5729 |
|
| 3 |
liveuser |
5730 |
#如果分割字串失敗
|
|
|
5731 |
if($characterSetString["status"]==="false"){
|
| 226 |
liveuser |
5732 |
|
| 3 |
liveuser |
5733 |
#設置執行不正常
|
|
|
5734 |
$result["status"]="false";
|
| 226 |
liveuser |
5735 |
|
| 3 |
liveuser |
5736 |
#設置錯誤訊息
|
|
|
5737 |
$result["error"]=$characterSetString;
|
| 226 |
liveuser |
5738 |
|
| 3 |
liveuser |
5739 |
#回傳結果
|
|
|
5740 |
return $result;
|
| 226 |
liveuser |
5741 |
|
| 3 |
liveuser |
5742 |
}#if end
|
| 226 |
liveuser |
5743 |
|
| 3 |
liveuser |
5744 |
#函式說明:
|
|
|
5745 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5746 |
#回傳的參數:
|
|
|
5747 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5748 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5749 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5750 |
#必填參數:
|
|
|
5751 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$characterSetString["dataArray"][1];#要處理的字串。
|
|
|
5752 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
5753 |
$characterSetString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
5754 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
5755 |
|
| 3 |
liveuser |
5756 |
#如果分割字串失敗
|
|
|
5757 |
if($characterSetString["status"]==="false"){
|
| 226 |
liveuser |
5758 |
|
| 3 |
liveuser |
5759 |
#設置執行不正常
|
|
|
5760 |
$result["status"]="false";
|
| 226 |
liveuser |
5761 |
|
| 3 |
liveuser |
5762 |
#設置錯誤訊息
|
|
|
5763 |
$result["error"]=$characterSetString;
|
| 226 |
liveuser |
5764 |
|
| 3 |
liveuser |
5765 |
#回傳結果
|
|
|
5766 |
return $result;
|
| 226 |
liveuser |
5767 |
|
| 3 |
liveuser |
5768 |
}#if end
|
| 226 |
liveuser |
5769 |
|
|
|
5770 |
#將「,」去掉
|
| 3 |
liveuser |
5771 |
#函式說明:
|
|
|
5772 |
#處理字串避免網頁出錯
|
|
|
5773 |
#回傳結果::
|
|
|
5774 |
#$result,爲處理好的字串。
|
|
|
5775 |
#必填參數:
|
|
|
5776 |
$conf["stringProcess"]["correctCharacter"]["stringIn"]=$characterSetString["dataArray"][0];#爲要處理的字串
|
|
|
5777 |
#可省略參數:
|
|
|
5778 |
$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
5779 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
5780 |
#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
5781 |
$processedCharacterSetStr=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
|
|
|
5782 |
unset($conf["stringProcess"]["correctCharacter"]);
|
| 226 |
liveuser |
5783 |
|
| 3 |
liveuser |
5784 |
#如果處理字串失敗
|
|
|
5785 |
if($processedCharacterSetStr["status"]==="false"){
|
| 226 |
liveuser |
5786 |
|
| 3 |
liveuser |
5787 |
#設置執行不正常
|
|
|
5788 |
$result["status"]="false";
|
| 226 |
liveuser |
5789 |
|
| 3 |
liveuser |
5790 |
#設置錯誤訊息
|
|
|
5791 |
$result["error"]=$processedCharacterSetStr;
|
| 226 |
liveuser |
5792 |
|
| 3 |
liveuser |
5793 |
#回傳結果
|
|
|
5794 |
return $result;
|
| 226 |
liveuser |
5795 |
|
| 3 |
liveuser |
5796 |
}#if end
|
| 226 |
liveuser |
5797 |
|
| 3 |
liveuser |
5798 |
#取得CHARACTER SET的設定字串
|
|
|
5799 |
$result["columnCharacterSet"][$i]=$processedCharacterSetStr["content"];
|
|
|
5800 |
$result["columnCharacterSet"][$result["columnName"][$i]]=$processedCharacterSetStr["content"];
|
| 226 |
liveuser |
5801 |
|
| 3 |
liveuser |
5802 |
}#if end
|
| 226 |
liveuser |
5803 |
|
| 3 |
liveuser |
5804 |
#反之,沒有 CHARACTER SET 字樣
|
|
|
5805 |
else{
|
| 226 |
liveuser |
5806 |
|
| 3 |
liveuser |
5807 |
#如果存在該欄位
|
|
|
5808 |
if(isset($result["columnName"][$i])){
|
| 226 |
liveuser |
5809 |
|
| 3 |
liveuser |
5810 |
#採用預設的 $result["charset"]
|
|
|
5811 |
$result["columnCharacterSet"][$i]=$result["charset"];
|
|
|
5812 |
$result["columnCharacterSet"][$result["columnName"][$i]]=$result["columnCharacterSet"][$i];
|
| 226 |
liveuser |
5813 |
|
| 3 |
liveuser |
5814 |
}#if end
|
| 226 |
liveuser |
5815 |
|
| 3 |
liveuser |
5816 |
}#else end
|
| 226 |
liveuser |
5817 |
|
| 3 |
liveuser |
5818 |
#檢查是否有 COLLATE 字樣...
|
| 226 |
liveuser |
5819 |
|
| 3 |
liveuser |
5820 |
#函式說明:
|
|
|
5821 |
#檢查字串裡面有無指定的關鍵字
|
|
|
5822 |
#回傳結果::
|
|
|
5823 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
5824 |
#$result["error"],錯誤訊息
|
|
|
5825 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
5826 |
#必填參數:
|
|
|
5827 |
$conf["search"]["findKeyWord"]["keyWord"]="COLLATE";#想要搜尋的關鍵字
|
|
|
5828 |
$conf["search"]["findKeyWord"]["string"]=$everyLine["dataArray"][$i];#要被搜尋的字串內容
|
|
|
5829 |
#可省略參數:
|
|
|
5830 |
#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
5831 |
$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
|
|
|
5832 |
unset($conf["search"]["findKeyWord"]);
|
| 226 |
liveuser |
5833 |
|
| 3 |
liveuser |
5834 |
#如果尋找關鍵字失敗
|
|
|
5835 |
if($searchResult["status"]==="false"){
|
| 226 |
liveuser |
5836 |
|
| 3 |
liveuser |
5837 |
#設置執行不正常
|
|
|
5838 |
$result["status"]="false";
|
| 226 |
liveuser |
5839 |
|
| 3 |
liveuser |
5840 |
#設置錯誤訊息
|
|
|
5841 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
5842 |
|
| 3 |
liveuser |
5843 |
#回傳結果
|
|
|
5844 |
return $result;
|
| 226 |
liveuser |
5845 |
|
| 3 |
liveuser |
5846 |
}#if end
|
| 226 |
liveuser |
5847 |
|
| 3 |
liveuser |
5848 |
#如果有找到 CHARACTER SET
|
| 226 |
liveuser |
5849 |
if($searchResult["founded"]==="true"){
|
|
|
5850 |
|
| 3 |
liveuser |
5851 |
#函式說明:
|
|
|
5852 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5853 |
#回傳的參數:
|
|
|
5854 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5855 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5856 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5857 |
#必填參數:
|
|
|
5858 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][$i];#要處理的字串。
|
|
|
5859 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="COLLATE ";#爲以哪個符號作爲分割
|
|
|
5860 |
$collateString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
5861 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
5862 |
|
| 3 |
liveuser |
5863 |
#如果分割字串失敗
|
|
|
5864 |
if($collateString["status"]=="false"){
|
| 226 |
liveuser |
5865 |
|
| 3 |
liveuser |
5866 |
#設置執行不正常
|
|
|
5867 |
$result["status"]="false";
|
| 226 |
liveuser |
5868 |
|
| 3 |
liveuser |
5869 |
#設置錯誤訊息
|
|
|
5870 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
5871 |
|
| 3 |
liveuser |
5872 |
#回傳結果
|
|
|
5873 |
return $result;
|
| 226 |
liveuser |
5874 |
|
| 3 |
liveuser |
5875 |
}#if end
|
| 226 |
liveuser |
5876 |
|
| 3 |
liveuser |
5877 |
#函式說明:
|
|
|
5878 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5879 |
#回傳的參數:
|
|
|
5880 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5881 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5882 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5883 |
#必填參數:
|
|
|
5884 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$collateString["dataArray"][1];#要處理的字串。
|
|
|
5885 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
5886 |
$collateString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
5887 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
5888 |
|
| 3 |
liveuser |
5889 |
#如果分割字串失敗
|
|
|
5890 |
if($collateString["status"]==="false"){
|
| 226 |
liveuser |
5891 |
|
| 3 |
liveuser |
5892 |
#設置執行不正常
|
|
|
5893 |
$result["status"]="false";
|
| 226 |
liveuser |
5894 |
|
| 3 |
liveuser |
5895 |
#設置錯誤訊息
|
|
|
5896 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
5897 |
|
| 3 |
liveuser |
5898 |
#回傳結果
|
|
|
5899 |
return $result;
|
| 226 |
liveuser |
5900 |
|
| 3 |
liveuser |
5901 |
}#if end
|
| 226 |
liveuser |
5902 |
|
|
|
5903 |
#將「,」去掉
|
| 3 |
liveuser |
5904 |
#函式說明:
|
|
|
5905 |
#處理字串避免網頁出錯
|
|
|
5906 |
#回傳結果::
|
|
|
5907 |
#$result,爲處理好的字串。
|
|
|
5908 |
#必填參數:
|
|
|
5909 |
$conf["stringProcess"]["correctCharacter"]["stringIn"]=$collateString["dataArray"][0];#爲要處理的字串
|
|
|
5910 |
#可省略參數:
|
|
|
5911 |
$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
5912 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
5913 |
#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
5914 |
$thisColumnCollate=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
|
|
|
5915 |
unset($conf["stringProcess"]["correctCharacter"]);
|
| 226 |
liveuser |
5916 |
|
| 3 |
liveuser |
5917 |
#如果處理字串失敗
|
|
|
5918 |
if($thisColumnCollate["status"]==="false"){
|
| 226 |
liveuser |
5919 |
|
| 3 |
liveuser |
5920 |
#設置執行不正常
|
|
|
5921 |
$result["status"]="false";
|
| 226 |
liveuser |
5922 |
|
| 3 |
liveuser |
5923 |
#設置錯誤訊息
|
|
|
5924 |
$result["error"]=$thisColumnCollate;
|
| 226 |
liveuser |
5925 |
|
| 3 |
liveuser |
5926 |
#回傳結果
|
|
|
5927 |
return $result;
|
| 226 |
liveuser |
5928 |
|
| 3 |
liveuser |
5929 |
}#if end
|
| 226 |
liveuser |
5930 |
|
| 3 |
liveuser |
5931 |
#儲存 COLLATE 資訊字串
|
|
|
5932 |
$result["columnCollate"][$i]=$thisColumnCollate["content"];
|
|
|
5933 |
$result["columnCollate"][$result["columnName"][$i]]=$thisColumnCollate["content"];
|
| 226 |
liveuser |
5934 |
|
| 3 |
liveuser |
5935 |
}#if end
|
| 226 |
liveuser |
5936 |
|
| 3 |
liveuser |
5937 |
#反之,沒有 COLLATE 字樣
|
|
|
5938 |
else{
|
|
|
5939 |
#如果存在該欄位
|
|
|
5940 |
if(isset($result["columnName"][$i])){
|
| 226 |
liveuser |
5941 |
|
| 3 |
liveuser |
5942 |
$result["columnCollate"][$i]="沒有指定";
|
|
|
5943 |
$result["columnCollate"][$result["columnName"][$i]]=$result["columnCollate"][$i];
|
| 226 |
liveuser |
5944 |
|
| 3 |
liveuser |
5945 |
}#if end
|
| 226 |
liveuser |
5946 |
|
| 3 |
liveuser |
5947 |
}#else end
|
| 226 |
liveuser |
5948 |
|
| 3 |
liveuser |
5949 |
#檢查是否有COMMENT字樣
|
|
|
5950 |
#函式說明:
|
|
|
5951 |
#檢查字串裡面有無指定的關鍵字
|
|
|
5952 |
#回傳結果::
|
|
|
5953 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
5954 |
#$result["error"],錯誤訊息
|
|
|
5955 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
5956 |
#必填參數:
|
|
|
5957 |
$conf["search"]["findKeyWord"]["keyWord"]="COMMENT";#想要搜尋的關鍵字
|
|
|
5958 |
$conf["search"]["findKeyWord"]["string"]=$everyLine["dataArray"][$i];#要被搜尋的字串內容
|
|
|
5959 |
#可省略參數:
|
|
|
5960 |
#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
5961 |
$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
|
|
|
5962 |
unset($conf["search"]);
|
| 226 |
liveuser |
5963 |
|
| 3 |
liveuser |
5964 |
#如果尋找關鍵字失敗
|
|
|
5965 |
if($searchResult["status"]==="false"){
|
| 226 |
liveuser |
5966 |
|
| 3 |
liveuser |
5967 |
#設置執行不正常
|
|
|
5968 |
$result["status"]="false";
|
| 226 |
liveuser |
5969 |
|
| 3 |
liveuser |
5970 |
#設置錯誤訊息
|
|
|
5971 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
5972 |
|
| 3 |
liveuser |
5973 |
#回傳結果
|
|
|
5974 |
return $result;
|
| 226 |
liveuser |
5975 |
|
| 3 |
liveuser |
5976 |
}#if end
|
| 226 |
liveuser |
5977 |
|
| 3 |
liveuser |
5978 |
#如果有 COMMENT 字樣
|
|
|
5979 |
if($searchResult["founded"]==="true"){
|
| 226 |
liveuser |
5980 |
|
| 3 |
liveuser |
5981 |
#函式說明:
|
|
|
5982 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
5983 |
#回傳的參數:
|
|
|
5984 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
5985 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
5986 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
5987 |
#必填參數:
|
|
|
5988 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$everyLine["dataArray"][$i];#要處理的字串。
|
|
|
5989 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="COMMENT ";#爲以哪個符號作爲分割
|
|
|
5990 |
$commentString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
5991 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
5992 |
|
| 3 |
liveuser |
5993 |
#如果分割字串失敗
|
|
|
5994 |
if($commentString["status"]=="false"){
|
| 226 |
liveuser |
5995 |
|
| 3 |
liveuser |
5996 |
#設置執行不正常
|
|
|
5997 |
$result["status"]="false";
|
| 226 |
liveuser |
5998 |
|
| 3 |
liveuser |
5999 |
#設置錯誤訊息
|
|
|
6000 |
$result["error"]=$commentString;
|
| 226 |
liveuser |
6001 |
|
| 3 |
liveuser |
6002 |
#回傳結果
|
|
|
6003 |
return $result;
|
| 226 |
liveuser |
6004 |
|
| 3 |
liveuser |
6005 |
}#if end
|
| 226 |
liveuser |
6006 |
|
| 3 |
liveuser |
6007 |
#函式說明:
|
|
|
6008 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
6009 |
#回傳的參數:
|
|
|
6010 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
6011 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
6012 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
6013 |
#必填參數:
|
|
|
6014 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$commentString["dataArray"][1];#要處理的字串。
|
|
|
6015 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="'";#爲以哪個符號作爲分割
|
|
|
6016 |
$commentString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
6017 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
6018 |
|
| 3 |
liveuser |
6019 |
#如果分割字串失敗
|
|
|
6020 |
if($commentString["status"]==="false"){
|
| 226 |
liveuser |
6021 |
|
| 3 |
liveuser |
6022 |
#設置執行不正常
|
|
|
6023 |
$result["status"]="false";
|
| 226 |
liveuser |
6024 |
|
| 3 |
liveuser |
6025 |
#設置錯誤訊息
|
|
|
6026 |
$result["error"]=$commentString;
|
| 226 |
liveuser |
6027 |
|
| 3 |
liveuser |
6028 |
#回傳結果
|
|
|
6029 |
return $result;
|
| 226 |
liveuser |
6030 |
|
| 3 |
liveuser |
6031 |
}#if end
|
| 226 |
liveuser |
6032 |
|
| 3 |
liveuser |
6033 |
#取得該欄位的註解內容
|
|
|
6034 |
$result["columnComment"][$i]=$commentString["dataArray"][0];
|
|
|
6035 |
$result["columnComment"][$result["columnName"][$i]]=$commentString["dataArray"][0];
|
| 226 |
liveuser |
6036 |
|
| 3 |
liveuser |
6037 |
}#if end
|
| 226 |
liveuser |
6038 |
|
| 3 |
liveuser |
6039 |
#反之,沒有 COMMENT 字樣
|
|
|
6040 |
else{
|
|
|
6041 |
#如果存在該欄位
|
|
|
6042 |
if(isset($result["columnName"][$i])){
|
| 226 |
liveuser |
6043 |
|
| 3 |
liveuser |
6044 |
#設置該欄位沒有註解
|
|
|
6045 |
$result["columnComment"][$i]="沒有註解";
|
|
|
6046 |
$result["columnComment"][$result["columnName"][$i]]="沒有註解";
|
| 226 |
liveuser |
6047 |
|
| 3 |
liveuser |
6048 |
}#if end
|
| 226 |
liveuser |
6049 |
|
| 3 |
liveuser |
6050 |
}#else end
|
| 226 |
liveuser |
6051 |
|
| 3 |
liveuser |
6052 |
}#for end
|
| 226 |
liveuser |
6053 |
|
| 3 |
liveuser |
6054 |
#初始化索引鍵的陣列
|
|
|
6055 |
$result["key"]=array();
|
| 226 |
liveuser |
6056 |
|
| 3 |
liveuser |
6057 |
#依據有幾個鍵值的定義來執行
|
|
|
6058 |
foreach($keyDefine as $unClassifyString){
|
| 226 |
liveuser |
6059 |
|
| 3 |
liveuser |
6060 |
#依據第一個單字來進行判斷
|
|
|
6061 |
#可能的有:
|
|
|
6062 |
#PRIMARY KEY,主鍵
|
|
|
6063 |
#KEY,索引鍵
|
|
|
6064 |
#CONSTRAINT,外鍵
|
| 226 |
liveuser |
6065 |
|
| 3 |
liveuser |
6066 |
#如果找到 PRIMARY KEY
|
|
|
6067 |
#函式說明:
|
|
|
6068 |
#檢查字串裡面有無指定的關鍵字
|
|
|
6069 |
#回傳結果::
|
|
|
6070 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
6071 |
#$result["error"],錯誤訊息
|
|
|
6072 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
6073 |
#必填參數:
|
|
|
6074 |
$conf["search"]["findKeyWord"]["keyWord"]="PRIMARY KEY";#想要搜尋的關鍵字
|
|
|
6075 |
$conf["search"]["findKeyWord"]["string"]=$unClassifyString;#要被搜尋的字串內容
|
|
|
6076 |
#可省略參數:
|
|
|
6077 |
#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
6078 |
$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
|
|
|
6079 |
unset($conf["search"]["findKeyWord"]);
|
| 226 |
liveuser |
6080 |
|
| 3 |
liveuser |
6081 |
#如果尋找關鍵字失敗
|
|
|
6082 |
if($searchResult["status"]=="false"){
|
| 226 |
liveuser |
6083 |
|
| 3 |
liveuser |
6084 |
#設置執行不正常
|
|
|
6085 |
$result["status"]="false";
|
| 226 |
liveuser |
6086 |
|
| 3 |
liveuser |
6087 |
#設置錯誤訊息
|
|
|
6088 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
6089 |
|
| 3 |
liveuser |
6090 |
#回傳結果
|
|
|
6091 |
return $result;
|
| 226 |
liveuser |
6092 |
|
| 3 |
liveuser |
6093 |
}#if end
|
| 226 |
liveuser |
6094 |
|
| 3 |
liveuser |
6095 |
#如果有找到 PRIMARY KEY
|
| 226 |
liveuser |
6096 |
if($searchResult["founded"]=="true"){
|
|
|
6097 |
|
| 3 |
liveuser |
6098 |
#函式說明:
|
|
|
6099 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
6100 |
#回傳的參數:
|
|
|
6101 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
6102 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
6103 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
6104 |
#必填參數:
|
|
|
6105 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$unClassifyString;#要處理的字串。
|
|
|
6106 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="PRIMARY KEY ";#爲以哪個符號作爲分割
|
|
|
6107 |
$primaryKeyString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
6108 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
6109 |
|
| 3 |
liveuser |
6110 |
#如果分割字串失敗
|
|
|
6111 |
if($primaryKeyString["status"]=="false"){
|
| 226 |
liveuser |
6112 |
|
| 3 |
liveuser |
6113 |
#設置執行不正常
|
|
|
6114 |
$result["status"]="false";
|
| 226 |
liveuser |
6115 |
|
| 3 |
liveuser |
6116 |
#設置錯誤訊息
|
|
|
6117 |
$result["error"]=$primaryKeyString;
|
| 226 |
liveuser |
6118 |
|
| 3 |
liveuser |
6119 |
#回傳結果
|
|
|
6120 |
return $result;
|
| 226 |
liveuser |
6121 |
|
| 3 |
liveuser |
6122 |
}#if end
|
| 226 |
liveuser |
6123 |
|
| 3 |
liveuser |
6124 |
#取得主鍵的欄位名稱
|
|
|
6125 |
$primaryKey=$primaryKeyString["dataArray"][1];
|
| 226 |
liveuser |
6126 |
|
|
|
6127 |
#將「,」、「`」、「(」、「)」去掉
|
| 3 |
liveuser |
6128 |
#函式說明:
|
|
|
6129 |
#處理字串避免網頁出錯
|
|
|
6130 |
#回傳結果::
|
|
|
6131 |
#$result,爲處理好的字串。
|
|
|
6132 |
#必填參數:
|
|
|
6133 |
$conf["stringProcess"]["correctCharacter"]["stringIn"]=$primaryKey;#爲要處理的字串
|
|
|
6134 |
#可省略參數:
|
|
|
6135 |
$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",","`","(",")");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
6136 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
6137 |
#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
6138 |
$getPrimaryKey=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
|
|
|
6139 |
unset($conf["stringProcess"]["correctCharacter"]);
|
| 226 |
liveuser |
6140 |
|
| 3 |
liveuser |
6141 |
#如果 處理字串失敗
|
|
|
6142 |
if($getPrimaryKey["status"]=="false"){
|
| 226 |
liveuser |
6143 |
|
| 3 |
liveuser |
6144 |
#設置執行不正常
|
|
|
6145 |
$result["status"]="false";
|
| 226 |
liveuser |
6146 |
|
| 3 |
liveuser |
6147 |
#設置錯誤訊息
|
|
|
6148 |
$result["error"]=$getPrimaryKey;
|
| 226 |
liveuser |
6149 |
|
| 3 |
liveuser |
6150 |
#回傳結果
|
|
|
6151 |
return $result;
|
| 226 |
liveuser |
6152 |
|
| 3 |
liveuser |
6153 |
}#if end
|
| 226 |
liveuser |
6154 |
|
| 3 |
liveuser |
6155 |
#取得主鍵欄位名稱
|
|
|
6156 |
$result["primaryKey"]=$getPrimaryKey["content"];
|
| 226 |
liveuser |
6157 |
|
| 3 |
liveuser |
6158 |
#後續省略
|
|
|
6159 |
continue;
|
| 226 |
liveuser |
6160 |
|
| 3 |
liveuser |
6161 |
}#if end
|
| 226 |
liveuser |
6162 |
|
| 3 |
liveuser |
6163 |
#尋找是否有 KEY 關鍵字
|
|
|
6164 |
#函式說明:
|
|
|
6165 |
#檢查字串裡面有無指定的關鍵字
|
|
|
6166 |
#回傳結果::
|
|
|
6167 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
6168 |
#$result["error"],錯誤訊息
|
|
|
6169 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
6170 |
#必填參數:
|
|
|
6171 |
$conf["search"]["findKeyWord"]["keyWord"]=" KEY ";#想要搜尋的關鍵字
|
|
|
6172 |
$conf["search"]["findKeyWord"]["string"]=$unClassifyString;#要被搜尋的字串內容
|
|
|
6173 |
#可省略參數:
|
|
|
6174 |
#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
6175 |
$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
|
|
|
6176 |
unset($conf["search"]["findKeyWord"]);
|
| 226 |
liveuser |
6177 |
|
| 3 |
liveuser |
6178 |
#如果尋找關鍵字失敗
|
|
|
6179 |
if($searchResult["status"]=="false"){
|
| 226 |
liveuser |
6180 |
|
| 3 |
liveuser |
6181 |
#設置執行不正常
|
|
|
6182 |
$result["status"]="false";
|
| 226 |
liveuser |
6183 |
|
| 3 |
liveuser |
6184 |
#設置錯誤訊息
|
|
|
6185 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
6186 |
|
| 3 |
liveuser |
6187 |
#回傳結果
|
|
|
6188 |
return $result;
|
| 226 |
liveuser |
6189 |
|
| 3 |
liveuser |
6190 |
}#if end
|
| 226 |
liveuser |
6191 |
|
| 3 |
liveuser |
6192 |
#如果有找到 " KEY "
|
|
|
6193 |
if($searchResult["founded"]=="true"){
|
| 226 |
liveuser |
6194 |
|
| 3 |
liveuser |
6195 |
# 用 " KEY " 來分割
|
|
|
6196 |
#函式說明:
|
|
|
6197 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
6198 |
#回傳的參數:
|
|
|
6199 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
6200 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
6201 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
6202 |
#必填參數:
|
|
|
6203 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$unClassifyString;#要處理的字串。
|
|
|
6204 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" KEY ";#爲以哪個符號作爲分割
|
|
|
6205 |
$keyString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
6206 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
6207 |
|
| 3 |
liveuser |
6208 |
#如果分割字串失敗
|
|
|
6209 |
if($keyString["status"]=="false"){
|
| 226 |
liveuser |
6210 |
|
| 3 |
liveuser |
6211 |
#設置執行不正常
|
|
|
6212 |
$result["status"]="false";
|
| 226 |
liveuser |
6213 |
|
| 3 |
liveuser |
6214 |
#設置錯誤訊息
|
|
|
6215 |
$result["error"]=$keyString;
|
| 226 |
liveuser |
6216 |
|
| 3 |
liveuser |
6217 |
#回傳結果
|
|
|
6218 |
return $result;
|
| 226 |
liveuser |
6219 |
|
| 3 |
liveuser |
6220 |
}#if end
|
| 226 |
liveuser |
6221 |
|
| 3 |
liveuser |
6222 |
#函式說明:
|
|
|
6223 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
6224 |
#回傳的參數:
|
|
|
6225 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
6226 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
6227 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
6228 |
#必填參數:
|
|
|
6229 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$keyString["dataArray"][0];#要處理的字串。
|
|
|
6230 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="`";#爲以哪個符號作爲分割
|
|
|
6231 |
$keyString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
6232 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
6233 |
|
| 3 |
liveuser |
6234 |
#debug
|
|
|
6235 |
#var_dump($keyString);
|
| 226 |
liveuser |
6236 |
|
| 3 |
liveuser |
6237 |
#如果分割字串失敗
|
|
|
6238 |
if($keyString["status"]=="false"){
|
| 226 |
liveuser |
6239 |
|
| 3 |
liveuser |
6240 |
#設置執行不正常
|
|
|
6241 |
$result["status"]="false";
|
| 226 |
liveuser |
6242 |
|
| 3 |
liveuser |
6243 |
#設置錯誤訊息
|
|
|
6244 |
$result["error"]=$keyString;
|
| 226 |
liveuser |
6245 |
|
| 3 |
liveuser |
6246 |
#回傳結果
|
|
|
6247 |
return $result;
|
| 226 |
liveuser |
6248 |
|
| 3 |
liveuser |
6249 |
}#if end
|
| 226 |
liveuser |
6250 |
|
| 3 |
liveuser |
6251 |
#取得索引的欄位名稱
|
|
|
6252 |
$thisKeyColumnName=$keyString["dataArray"][2];
|
| 226 |
liveuser |
6253 |
|
| 3 |
liveuser |
6254 |
#取得要回傳的key欄位名稱
|
|
|
6255 |
$result["key"][]=$thisKeyColumnName;
|
| 226 |
liveuser |
6256 |
|
| 3 |
liveuser |
6257 |
#用index key欄位的名稱來儲存index key的欄位
|
|
|
6258 |
$result["key"][$thisKeyColumnName]=$thisKeyColumnName;
|
| 226 |
liveuser |
6259 |
|
| 3 |
liveuser |
6260 |
#取得用於識別 key 的 Constraint
|
|
|
6261 |
$keyConstraintName=$keyString["dataArray"][0];
|
| 226 |
liveuser |
6262 |
|
|
|
6263 |
#將「`」去掉
|
| 3 |
liveuser |
6264 |
#函式說明:
|
|
|
6265 |
#處理字串避免網頁出錯
|
|
|
6266 |
#回傳結果::
|
|
|
6267 |
#$result,爲處理好的字串。
|
|
|
6268 |
#必填參數:
|
|
|
6269 |
$conf["stringProcess"]["correctCharacter"]["stringIn"]=$keyConstraintName;#爲要處理的字串
|
|
|
6270 |
#可省略參數:
|
|
|
6271 |
$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array("`");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
6272 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
6273 |
#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
6274 |
$thisKeyConstraintName=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
|
|
|
6275 |
unset($conf["stringProcess"]["correctCharacter"]);
|
| 226 |
liveuser |
6276 |
|
| 3 |
liveuser |
6277 |
#如果處理字串失敗
|
|
|
6278 |
if($thisKeyConstraintName["status"]=="false"){
|
| 226 |
liveuser |
6279 |
|
| 3 |
liveuser |
6280 |
#設置執行不正常
|
|
|
6281 |
$result["status"]="false";
|
| 226 |
liveuser |
6282 |
|
| 3 |
liveuser |
6283 |
#設置錯誤訊息
|
|
|
6284 |
$result["error"]=$thisKeyConstraintName;
|
| 226 |
liveuser |
6285 |
|
| 3 |
liveuser |
6286 |
#回傳結果
|
|
|
6287 |
return $result;
|
| 226 |
liveuser |
6288 |
|
| 3 |
liveuser |
6289 |
}#if end
|
| 226 |
liveuser |
6290 |
|
| 3 |
liveuser |
6291 |
#儲存 key 的名稱
|
|
|
6292 |
$result["keyConstraintName"][]=$thisKeyConstraintName["content"];
|
| 226 |
liveuser |
6293 |
|
| 3 |
liveuser |
6294 |
#將 $result["keyConstraintName"] 用 欄位的名稱去儲存
|
|
|
6295 |
$result["keyConstraintName"][$thisKeyColumnName]=$thisKeyConstraintName["content"];
|
| 226 |
liveuser |
6296 |
|
| 3 |
liveuser |
6297 |
#後續省略
|
|
|
6298 |
continue;
|
| 226 |
liveuser |
6299 |
|
| 3 |
liveuser |
6300 |
}#if end
|
| 226 |
liveuser |
6301 |
|
| 3 |
liveuser |
6302 |
#尋找是否有 CONSTRAINT 關鍵字
|
|
|
6303 |
#函式說明:
|
|
|
6304 |
#檢查字串裡面有無指定的關鍵字
|
|
|
6305 |
#回傳結果::
|
|
|
6306 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
6307 |
#$result["error"],錯誤訊息
|
|
|
6308 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
6309 |
#必填參數:
|
|
|
6310 |
$conf["search"]["findKeyWord"]["keyWord"]="CONSTRAINT";#想要搜尋的關鍵字
|
|
|
6311 |
$conf["search"]["findKeyWord"]["string"]=$unClassifyString;#要被搜尋的字串內容
|
|
|
6312 |
#可省略參數:
|
|
|
6313 |
#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
6314 |
$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
|
|
|
6315 |
unset($conf["search"]["findKeyWord"]);
|
| 226 |
liveuser |
6316 |
|
| 3 |
liveuser |
6317 |
#如果尋找關鍵字失敗
|
|
|
6318 |
if($searchResult["status"]=="false"){
|
| 226 |
liveuser |
6319 |
|
| 3 |
liveuser |
6320 |
#設置執行不正常
|
|
|
6321 |
$result["status"]="false";
|
| 226 |
liveuser |
6322 |
|
| 3 |
liveuser |
6323 |
#設置錯誤訊息
|
|
|
6324 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
6325 |
|
| 3 |
liveuser |
6326 |
#回傳結果
|
|
|
6327 |
return $result;
|
| 226 |
liveuser |
6328 |
|
| 3 |
liveuser |
6329 |
}#if end
|
| 226 |
liveuser |
6330 |
|
| 3 |
liveuser |
6331 |
#如果有找到 "CONSTRAINT"
|
|
|
6332 |
if($searchResult["founded"]=="true"){
|
| 226 |
liveuser |
6333 |
|
| 3 |
liveuser |
6334 |
#取得 CONSTRAINT 的名稱
|
| 226 |
liveuser |
6335 |
|
| 3 |
liveuser |
6336 |
#用 " " 來分割字串
|
|
|
6337 |
#函式說明:
|
|
|
6338 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
6339 |
#回傳的參數:
|
|
|
6340 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
6341 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
6342 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
6343 |
#必填參數:
|
|
|
6344 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$unClassifyString;#要處理的字串。
|
|
|
6345 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
6346 |
$foreignKeyConstraintString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
6347 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
6348 |
|
| 3 |
liveuser |
6349 |
#如果分割字串失敗
|
|
|
6350 |
if($foreignKeyConstraintString["status"]=="false"){
|
| 226 |
liveuser |
6351 |
|
| 3 |
liveuser |
6352 |
#設置執行不正常
|
|
|
6353 |
$result["status"]="false";
|
| 226 |
liveuser |
6354 |
|
| 3 |
liveuser |
6355 |
#設置錯誤訊息
|
|
|
6356 |
$result["error"]=$foreignKeyConstraintString;
|
| 226 |
liveuser |
6357 |
|
| 3 |
liveuser |
6358 |
#回傳結果
|
|
|
6359 |
return $result;
|
| 226 |
liveuser |
6360 |
|
|
|
6361 |
}#if end
|
|
|
6362 |
|
| 3 |
liveuser |
6363 |
#將 $foreignKeyString[0] 的非必要字元踢除
|
| 226 |
liveuser |
6364 |
#將「,」、「`」、「(」、「)」去掉
|
| 3 |
liveuser |
6365 |
#函式說明:
|
|
|
6366 |
#處理字串避免網頁出錯
|
|
|
6367 |
#回傳結果::
|
|
|
6368 |
#$result,爲處理好的字串。
|
|
|
6369 |
#必填參數:
|
|
|
6370 |
$conf["stringProcess"]["correctCharacter"]["stringIn"]=$foreignKeyConstraintString["dataArray"][1];#爲要處理的字串
|
|
|
6371 |
#可省略參數:
|
|
|
6372 |
$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array("`");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
6373 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
6374 |
#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
6375 |
$foreignConstraintName=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
|
| 226 |
liveuser |
6376 |
unset($conf["stringProcess"]["correctCharacter"]);
|
|
|
6377 |
|
| 3 |
liveuser |
6378 |
#如果處理 CONSTRAINT 字串失敗
|
|
|
6379 |
if($foreignConstraintName["status"]=="false"){
|
| 226 |
liveuser |
6380 |
|
| 3 |
liveuser |
6381 |
#設置執行不正常
|
|
|
6382 |
$result["status"]="false";
|
| 226 |
liveuser |
6383 |
|
| 3 |
liveuser |
6384 |
#設置錯誤訊息
|
|
|
6385 |
$result["error"]=$foreignConstraintName;
|
| 226 |
liveuser |
6386 |
|
| 3 |
liveuser |
6387 |
#回傳結果
|
|
|
6388 |
return $result;
|
| 226 |
liveuser |
6389 |
|
|
|
6390 |
}#if end
|
|
|
6391 |
|
| 3 |
liveuser |
6392 |
#儲存 foreignKey 的 CONSTRAINT 名稱
|
| 226 |
liveuser |
6393 |
$result["foreignKey"]["constraintName"][]=$foreignConstraintName["content"];
|
|
|
6394 |
|
| 3 |
liveuser |
6395 |
#尋找 "FOREIGN KEY"
|
|
|
6396 |
#函式說明:
|
|
|
6397 |
#檢查字串裡面有無指定的關鍵字
|
|
|
6398 |
#回傳結果::
|
|
|
6399 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
6400 |
#$result["error"],錯誤訊息
|
|
|
6401 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
6402 |
#必填參數:
|
|
|
6403 |
$conf["search"]["findKeyWord"]["keyWord"]="FOREIGN KEY";#想要搜尋的關鍵字
|
|
|
6404 |
$conf["search"]["findKeyWord"]["string"]=$unClassifyString;#要被搜尋的字串內容
|
|
|
6405 |
#可省略參數:
|
|
|
6406 |
#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
6407 |
$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
|
|
|
6408 |
unset($conf["search"]["findKeyWord"]);
|
| 226 |
liveuser |
6409 |
|
| 3 |
liveuser |
6410 |
#如果尋找關鍵字失敗
|
|
|
6411 |
if($searchResult["status"]=="false"){
|
| 226 |
liveuser |
6412 |
|
| 3 |
liveuser |
6413 |
#設置執行不正常
|
|
|
6414 |
$result["status"]="false";
|
| 226 |
liveuser |
6415 |
|
| 3 |
liveuser |
6416 |
#設置錯誤訊息
|
|
|
6417 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
6418 |
|
| 3 |
liveuser |
6419 |
#回傳結果
|
|
|
6420 |
return $result;
|
| 226 |
liveuser |
6421 |
|
| 3 |
liveuser |
6422 |
}#if end
|
| 226 |
liveuser |
6423 |
|
| 3 |
liveuser |
6424 |
#如果有找到 "FOREIGN KEY"
|
|
|
6425 |
if($searchResult["founded"]=="true"){
|
| 226 |
liveuser |
6426 |
|
| 3 |
liveuser |
6427 |
#用 "FOREIGN KEY " 來分割字串
|
|
|
6428 |
#函式說明:
|
|
|
6429 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
6430 |
#回傳的參數:
|
|
|
6431 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
6432 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
6433 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
6434 |
#必填參數:
|
|
|
6435 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$unClassifyString;#要處理的字串。
|
|
|
6436 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="FOREIGN KEY ";#爲以哪個符號作爲分割
|
|
|
6437 |
$foreignKeyString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
6438 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
6439 |
|
| 3 |
liveuser |
6440 |
#如果分割字串失敗
|
|
|
6441 |
if($foreignKeyString["status"]=="false"){
|
| 226 |
liveuser |
6442 |
|
| 3 |
liveuser |
6443 |
#設置執行不正常
|
|
|
6444 |
$result["status"]="false";
|
| 226 |
liveuser |
6445 |
|
| 3 |
liveuser |
6446 |
#設置錯誤訊息
|
|
|
6447 |
$result["error"]=$foreignKeyString;
|
| 226 |
liveuser |
6448 |
|
| 3 |
liveuser |
6449 |
#回傳結果
|
|
|
6450 |
return $result;
|
| 226 |
liveuser |
6451 |
|
|
|
6452 |
}#if end
|
|
|
6453 |
|
| 3 |
liveuser |
6454 |
#用 " " 來分割字串
|
|
|
6455 |
#函式說明:
|
|
|
6456 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
6457 |
#回傳的參數:
|
|
|
6458 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
6459 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
6460 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
6461 |
#必填參數:
|
|
|
6462 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$foreignKeyString["dataArray"][1];#要處理的字串。
|
|
|
6463 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
6464 |
$foreignKeyString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
6465 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
6466 |
|
| 3 |
liveuser |
6467 |
#如果分割字串失敗
|
|
|
6468 |
if($foreignKeyString["status"]=="false"){
|
| 226 |
liveuser |
6469 |
|
| 3 |
liveuser |
6470 |
#設置執行不正常
|
|
|
6471 |
$result["status"]="false";
|
| 226 |
liveuser |
6472 |
|
| 3 |
liveuser |
6473 |
#設置錯誤訊息
|
|
|
6474 |
$result["error"]=$foreignKeyString;
|
| 226 |
liveuser |
6475 |
|
| 3 |
liveuser |
6476 |
#回傳結果
|
|
|
6477 |
return $result;
|
| 226 |
liveuser |
6478 |
|
|
|
6479 |
}#if end
|
|
|
6480 |
|
| 3 |
liveuser |
6481 |
#將 $foreignKeyString[0] 的非必要字元踢除
|
| 226 |
liveuser |
6482 |
#將「,」、「`」、「(」、「)」去掉
|
| 3 |
liveuser |
6483 |
#函式說明:
|
|
|
6484 |
#處理字串避免網頁出錯
|
|
|
6485 |
#回傳結果::
|
|
|
6486 |
#$result,爲處理好的字串。
|
|
|
6487 |
#必填參數:
|
|
|
6488 |
$conf["stringProcess"]["correctCharacter"]["stringIn"]=$foreignKeyString["dataArray"][0];#爲要處理的字串
|
|
|
6489 |
#可省略參數:
|
|
|
6490 |
$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",","`","(",")");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
6491 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
6492 |
#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
6493 |
$thisForeignKeyColumnName=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
|
|
|
6494 |
unset($conf["stringProcess"]["correctCharacter"]);
|
| 226 |
liveuser |
6495 |
|
| 3 |
liveuser |
6496 |
#如果 處理字串失敗
|
|
|
6497 |
if($thisForeignKeyColumnName["status"]=="false"){
|
| 226 |
liveuser |
6498 |
|
| 3 |
liveuser |
6499 |
#設置執行不正常
|
|
|
6500 |
$result["status"]="false";
|
| 226 |
liveuser |
6501 |
|
| 3 |
liveuser |
6502 |
#設置錯誤訊息
|
|
|
6503 |
$result["error"]=$thisForeignKeyColumnName;
|
| 226 |
liveuser |
6504 |
|
| 3 |
liveuser |
6505 |
#回傳結果
|
|
|
6506 |
return $result;
|
| 226 |
liveuser |
6507 |
|
| 3 |
liveuser |
6508 |
}#if end
|
| 226 |
liveuser |
6509 |
|
| 3 |
liveuser |
6510 |
#儲存外鍵欄位的名稱
|
|
|
6511 |
$result["foreignKey"]["columnName"][]=$thisForeignKeyColumnName["content"];
|
| 226 |
liveuser |
6512 |
|
| 3 |
liveuser |
6513 |
#用該外鍵欄位的名稱,作為key來存放外鍵欄位的名稱
|
|
|
6514 |
$result["foreignKey"]["columnName"][$thisForeignKeyColumnName["content"]]=$thisForeignKeyColumnName["content"];
|
| 226 |
liveuser |
6515 |
|
| 3 |
liveuser |
6516 |
#用 "REFERENCES " 來分割字串
|
|
|
6517 |
#函式說明:
|
|
|
6518 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
6519 |
#回傳的參數:
|
|
|
6520 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
6521 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
6522 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
6523 |
#必填參數:
|
|
|
6524 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$unClassifyString;#要處理的字串。
|
|
|
6525 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="REFERENCES ";#爲以哪個符號作爲分割
|
|
|
6526 |
$foreignKeyReferencesString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
6527 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
6528 |
|
| 3 |
liveuser |
6529 |
#如果分割字串失敗
|
|
|
6530 |
if($foreignKeyReferencesString["status"]=="false"){
|
| 226 |
liveuser |
6531 |
|
| 3 |
liveuser |
6532 |
#設置執行不正常
|
|
|
6533 |
$result["status"]="false";
|
| 226 |
liveuser |
6534 |
|
| 3 |
liveuser |
6535 |
#設置錯誤訊息
|
|
|
6536 |
$result["error"]=$foreignKeyReferencesString;
|
| 226 |
liveuser |
6537 |
|
| 3 |
liveuser |
6538 |
#回傳結果
|
|
|
6539 |
return $result;
|
| 226 |
liveuser |
6540 |
|
| 3 |
liveuser |
6541 |
}#if end
|
| 226 |
liveuser |
6542 |
|
| 3 |
liveuser |
6543 |
#用 " " 來分割字串
|
|
|
6544 |
#函式說明:
|
|
|
6545 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
6546 |
#回傳的參數:
|
|
|
6547 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
6548 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
6549 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
6550 |
#必填參數:
|
|
|
6551 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$foreignKeyReferencesString["dataArray"][1];#要處理的字串。
|
|
|
6552 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ";#爲以哪個符號作爲分割
|
|
|
6553 |
$foreignKeyReferencesString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
6554 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
6555 |
|
| 3 |
liveuser |
6556 |
#如果分割字串失敗
|
|
|
6557 |
if($foreignKeyReferencesString["status"]=="false"){
|
| 226 |
liveuser |
6558 |
|
| 3 |
liveuser |
6559 |
#設置執行不正常
|
|
|
6560 |
$result["status"]="false";
|
| 226 |
liveuser |
6561 |
|
| 3 |
liveuser |
6562 |
#設置錯誤訊息
|
|
|
6563 |
$result["error"]=$foreignKeyReferencesString;
|
| 226 |
liveuser |
6564 |
|
| 3 |
liveuser |
6565 |
#回傳結果
|
|
|
6566 |
return $result;
|
| 226 |
liveuser |
6567 |
|
| 3 |
liveuser |
6568 |
}#if end
|
| 226 |
liveuser |
6569 |
|
| 3 |
liveuser |
6570 |
#將 $foreignKeyString[0] 的非必要字元踢除
|
| 226 |
liveuser |
6571 |
#將「,」、「`」、「(」、「)」去掉
|
| 3 |
liveuser |
6572 |
#函式說明:
|
|
|
6573 |
#處理字串避免網頁出錯
|
|
|
6574 |
#回傳結果::
|
|
|
6575 |
#$result,爲處理好的字串。
|
|
|
6576 |
#必填參數:
|
|
|
6577 |
$conf["stringProcess"]["correctCharacter"]["stringIn"]=$foreignKeyReferencesString["dataArray"][1];#爲要處理的字串
|
|
|
6578 |
#可省略參數:
|
|
|
6579 |
$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",","`","(",")");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
6580 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
6581 |
#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
6582 |
$tempReferencesColumn=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
|
|
|
6583 |
unset($conf["stringProcess"]["correctCharacter"]);
|
| 226 |
liveuser |
6584 |
|
| 3 |
liveuser |
6585 |
#如果 處理字串失敗
|
|
|
6586 |
if($tempReferencesColumn["status"]=="false"){
|
| 226 |
liveuser |
6587 |
|
| 3 |
liveuser |
6588 |
#設置執行不正常
|
|
|
6589 |
$result["status"]="false";
|
| 226 |
liveuser |
6590 |
|
| 3 |
liveuser |
6591 |
#設置錯誤訊息
|
|
|
6592 |
$result["error"]=$tempReferencesColumn;
|
| 226 |
liveuser |
6593 |
|
| 3 |
liveuser |
6594 |
#回傳結果
|
|
|
6595 |
return $result;
|
| 226 |
liveuser |
6596 |
|
| 3 |
liveuser |
6597 |
}#if end
|
| 226 |
liveuser |
6598 |
|
| 3 |
liveuser |
6599 |
#取得參照的欄位名稱
|
|
|
6600 |
$result["foreignKey"]["referencesColumn"][]=$tempReferencesColumn["content"];
|
| 226 |
liveuser |
6601 |
|
| 3 |
liveuser |
6602 |
#用欄位名稱來儲存參照的資料表
|
|
|
6603 |
$result["foreignKey"]["referencesColumn"][$thisForeignKeyColumnName["content"]]=$tempReferencesColumn["content"];
|
| 226 |
liveuser |
6604 |
|
| 3 |
liveuser |
6605 |
#將 $foreignKeyString[0] 的非必要字元踢除
|
| 226 |
liveuser |
6606 |
#將「,」、「`」、「(」、「)」去掉
|
| 3 |
liveuser |
6607 |
#函式說明:
|
|
|
6608 |
#處理字串避免網頁出錯
|
|
|
6609 |
#回傳結果::
|
|
|
6610 |
#$result,爲處理好的字串。
|
|
|
6611 |
#必填參數:
|
|
|
6612 |
$conf["stringProcess"]["correctCharacter"]["stringIn"]=$foreignKeyReferencesString["dataArray"][0];#爲要處理的字串
|
|
|
6613 |
#可省略參數:
|
|
|
6614 |
$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array("`");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
6615 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
6616 |
#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
6617 |
$tempReferencesTable=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
|
|
|
6618 |
unset($conf["stringProcess"]["correctCharacter"]);
|
| 226 |
liveuser |
6619 |
|
| 3 |
liveuser |
6620 |
#如果處理字串失敗
|
|
|
6621 |
if($tempReferencesTable["status"]=="false"){
|
| 226 |
liveuser |
6622 |
|
| 3 |
liveuser |
6623 |
#設置執行不正常
|
|
|
6624 |
$result["status"]="false";
|
| 226 |
liveuser |
6625 |
|
| 3 |
liveuser |
6626 |
#設置錯誤訊息
|
|
|
6627 |
$result["error"]=$tempReferencesTable;
|
| 226 |
liveuser |
6628 |
|
| 3 |
liveuser |
6629 |
#回傳結果
|
|
|
6630 |
return $result;
|
| 226 |
liveuser |
6631 |
|
|
|
6632 |
}#if end
|
|
|
6633 |
|
| 3 |
liveuser |
6634 |
#取得參照的資料表
|
|
|
6635 |
$result["foreignKey"]["referencesTable"][]=$tempReferencesTable["content"];
|
| 226 |
liveuser |
6636 |
|
| 3 |
liveuser |
6637 |
#用欄位名稱來儲存參照的欄位
|
|
|
6638 |
$result["foreignKey"]["referencesTable"][$thisForeignKeyColumnName["content"]]=$tempReferencesTable["content"];
|
| 226 |
liveuser |
6639 |
|
| 3 |
liveuser |
6640 |
#如果有 "ON UPDATE" 存在
|
|
|
6641 |
#函式說明:
|
|
|
6642 |
#檢查字串裡面有無指定的關鍵字
|
|
|
6643 |
#回傳結果::
|
|
|
6644 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
6645 |
#$result["error"],錯誤訊息
|
|
|
6646 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
6647 |
#必填參數:
|
|
|
6648 |
$conf["search"]["findKeyWord"]["keyWord"]="ON UPDATE";#想要搜尋的關鍵字
|
|
|
6649 |
$conf["search"]["findKeyWord"]["string"]=$unClassifyString;#要被搜尋的字串內容
|
|
|
6650 |
#可省略參數:
|
|
|
6651 |
#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
6652 |
$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
|
|
|
6653 |
unset($conf["search"]["findKeyWord"]);
|
| 226 |
liveuser |
6654 |
|
| 3 |
liveuser |
6655 |
#如果尋找關鍵字失敗
|
|
|
6656 |
if($searchResult["status"]=="false"){
|
| 226 |
liveuser |
6657 |
|
| 3 |
liveuser |
6658 |
#設置執行不正常
|
|
|
6659 |
$result["status"]="false";
|
| 226 |
liveuser |
6660 |
|
| 3 |
liveuser |
6661 |
#設置錯誤訊息
|
|
|
6662 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
6663 |
|
| 3 |
liveuser |
6664 |
#回傳結果
|
|
|
6665 |
return $result;
|
| 226 |
liveuser |
6666 |
|
| 3 |
liveuser |
6667 |
}#if end
|
| 226 |
liveuser |
6668 |
|
| 3 |
liveuser |
6669 |
#如果有找到 "ON UPDATE"
|
|
|
6670 |
if($searchResult["founded"]=="true"){
|
| 226 |
liveuser |
6671 |
|
| 3 |
liveuser |
6672 |
#用 "ON UPDATE " 來分割字串
|
|
|
6673 |
#函式說明:
|
|
|
6674 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
6675 |
#回傳的參數:
|
|
|
6676 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
6677 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
6678 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
6679 |
#必填參數:
|
|
|
6680 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$unClassifyString;#要處理的字串。
|
|
|
6681 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="ON UPDATE ";#爲以哪個符號作爲分割
|
|
|
6682 |
$foreignKeyOnUpdateString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
6683 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
6684 |
|
| 3 |
liveuser |
6685 |
#如果分割字串失敗
|
|
|
6686 |
if($foreignKeyOnUpdateString["status"]=="false"){
|
| 226 |
liveuser |
6687 |
|
| 3 |
liveuser |
6688 |
#設置執行不正常
|
|
|
6689 |
$result["status"]="false";
|
| 226 |
liveuser |
6690 |
|
| 3 |
liveuser |
6691 |
#設置錯誤訊息
|
|
|
6692 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
6693 |
|
| 3 |
liveuser |
6694 |
#回傳結果
|
|
|
6695 |
return $result;
|
| 226 |
liveuser |
6696 |
|
| 3 |
liveuser |
6697 |
}#if end
|
| 226 |
liveuser |
6698 |
|
| 3 |
liveuser |
6699 |
#檢查裏面是否含有 " ON DELETE " 字樣
|
|
|
6700 |
#函式說明:
|
|
|
6701 |
#檢查字串裡面有無指定的關鍵字
|
|
|
6702 |
#回傳結果::
|
|
|
6703 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
6704 |
#$result["error"],錯誤訊息
|
|
|
6705 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
6706 |
#必填參數:
|
|
|
6707 |
$conf["search"]["findKeyWord"]["keyWord"]=" ON DELETE ";#想要搜尋的關鍵字
|
|
|
6708 |
$conf["search"]["findKeyWord"]["string"]=$foreignKeyOnUpdateString["dataArray"][1];#要被搜尋的字串內容
|
|
|
6709 |
#可省略參數:
|
|
|
6710 |
#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
6711 |
$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
|
|
|
6712 |
unset($conf["search"]["findKeyWord"]);
|
| 226 |
liveuser |
6713 |
|
| 3 |
liveuser |
6714 |
#如果尋找關鍵字失敗
|
|
|
6715 |
if($searchResult["status"]=="false"){
|
| 226 |
liveuser |
6716 |
|
| 3 |
liveuser |
6717 |
#設置執行不正常
|
|
|
6718 |
$result["status"]="false";
|
| 226 |
liveuser |
6719 |
|
| 3 |
liveuser |
6720 |
#設置錯誤訊息
|
|
|
6721 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
6722 |
|
| 3 |
liveuser |
6723 |
#回傳結果
|
|
|
6724 |
return $result;
|
| 226 |
liveuser |
6725 |
|
| 3 |
liveuser |
6726 |
}#if end
|
| 226 |
liveuser |
6727 |
|
| 3 |
liveuser |
6728 |
#如果裏面含有 "ON DELETE " 字樣
|
|
|
6729 |
if($searchResult["founded"]=="true"){
|
| 226 |
liveuser |
6730 |
|
| 3 |
liveuser |
6731 |
#我們只要取得 "ON DELETE " 前面的內容
|
|
|
6732 |
#用"ON UPDATE "來分割
|
|
|
6733 |
#函式說明:
|
|
|
6734 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
6735 |
#回傳的參數:
|
|
|
6736 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
6737 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
6738 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
6739 |
#必填參數:
|
|
|
6740 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$foreignKeyOnUpdateString["dataArray"][1];#要處理的字串。
|
|
|
6741 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ON DELETE ";#爲以哪個符號作爲分割
|
|
|
6742 |
$foreignKeyOnDeleteString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
6743 |
unset($conf["stringProcess"]["spiltString"]);
|
|
|
6744 |
#var_dump($foreignKeyOnDeleteString);
|
| 226 |
liveuser |
6745 |
|
| 3 |
liveuser |
6746 |
#如果分割字串失敗
|
|
|
6747 |
if($foreignKeyOnDeleteString["status"]=="false"){
|
| 226 |
liveuser |
6748 |
|
| 3 |
liveuser |
6749 |
#設置執行不正常
|
|
|
6750 |
$result["status"]="false";
|
| 226 |
liveuser |
6751 |
|
| 3 |
liveuser |
6752 |
#設置錯誤訊息
|
|
|
6753 |
$result["error"]=$foreignKeyOnDeleteString;
|
| 226 |
liveuser |
6754 |
|
| 3 |
liveuser |
6755 |
#回傳結果
|
|
|
6756 |
return $result;
|
| 226 |
liveuser |
6757 |
|
| 3 |
liveuser |
6758 |
}#if end
|
| 226 |
liveuser |
6759 |
|
| 3 |
liveuser |
6760 |
$foreignKeyOnUpdateString=$foreignKeyOnUpdateString["dataArray"][0];
|
| 226 |
liveuser |
6761 |
|
| 3 |
liveuser |
6762 |
#將 $foreignKeyOnUpdateString 的非必要字元踢除
|
| 226 |
liveuser |
6763 |
#將「,」、「`」、「(」、「)」去掉
|
| 3 |
liveuser |
6764 |
#函式說明:
|
|
|
6765 |
#處理字串避免網頁出錯
|
|
|
6766 |
#回傳結果::
|
|
|
6767 |
#$result,爲處理好的字串。
|
|
|
6768 |
#必填參數:
|
|
|
6769 |
$conf["stringProcess"]["correctCharacter"]["stringIn"]=$foreignKeyOnUpdateString;#爲要處理的字串
|
|
|
6770 |
#可省略參數:
|
|
|
6771 |
$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
6772 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
6773 |
#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
6774 |
$tempOnUpdateAction=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
|
|
|
6775 |
unset($conf["stringProcess"]["correctCharacter"]);
|
| 226 |
liveuser |
6776 |
|
| 3 |
liveuser |
6777 |
#如果 處理字串 失敗
|
|
|
6778 |
if($tempOnUpdateAction["status"]=="false"){
|
| 226 |
liveuser |
6779 |
|
| 3 |
liveuser |
6780 |
#設置執行不正常
|
|
|
6781 |
$result["status"]="false";
|
| 226 |
liveuser |
6782 |
|
| 3 |
liveuser |
6783 |
#設置錯誤訊息
|
|
|
6784 |
$result["error"]=$tempOnUpdateAction;
|
| 226 |
liveuser |
6785 |
|
| 3 |
liveuser |
6786 |
#回傳結果
|
|
|
6787 |
return $result;
|
| 226 |
liveuser |
6788 |
|
| 3 |
liveuser |
6789 |
}#if end
|
| 226 |
liveuser |
6790 |
|
| 3 |
liveuser |
6791 |
#紀錄 ON UPDATE 的動作字串
|
|
|
6792 |
$result["foreignKey"]["onUpdateAction"][]=$tempOnUpdateAction["content"];
|
| 226 |
liveuser |
6793 |
|
| 3 |
liveuser |
6794 |
#用 freign key 的名稱來紀錄外鍵更新的動作
|
|
|
6795 |
$result["foreignKey"]["onUpdateAction"][$thisForeignKeyColumnName]=$tempOnUpdateAction["content"];
|
| 226 |
liveuser |
6796 |
|
| 3 |
liveuser |
6797 |
}#if end
|
|
|
6798 |
|
|
|
6799 |
#反之 沒有 "ON DELETE " 字樣
|
| 226 |
liveuser |
6800 |
else{
|
|
|
6801 |
|
| 3 |
liveuser |
6802 |
#var_dump($foreignKeyOnUpdateString["dataArray"][1]);
|
| 226 |
liveuser |
6803 |
|
| 3 |
liveuser |
6804 |
#將 $foreignKeyOnUpdateString 的非必要字元踢除
|
| 226 |
liveuser |
6805 |
#將「,」、「`」、「(」、「)」去掉
|
| 3 |
liveuser |
6806 |
#函式說明:
|
|
|
6807 |
#處理字串避免網頁出錯
|
|
|
6808 |
#回傳結果::
|
|
|
6809 |
#$result,爲處理好的字串。
|
|
|
6810 |
#必填參數:
|
|
|
6811 |
$conf["stringProcess"]["correctCharacter"]["stringIn"]=$foreignKeyOnUpdateString["dataArray"][1];#爲要處理的字串
|
|
|
6812 |
#可省略參數:
|
|
|
6813 |
$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
6814 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
6815 |
#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
6816 |
$tempOnUpdateAction=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
|
|
|
6817 |
unset($conf["stringProcess"]["correctCharacter"]);
|
| 226 |
liveuser |
6818 |
|
| 3 |
liveuser |
6819 |
#如果處理字串失敗
|
|
|
6820 |
if($tempOnUpdateAction["status"]=="false"){
|
| 226 |
liveuser |
6821 |
|
| 3 |
liveuser |
6822 |
#設置執行不正常
|
|
|
6823 |
$result["status"]="false";
|
| 226 |
liveuser |
6824 |
|
| 3 |
liveuser |
6825 |
#設置錯誤訊息
|
|
|
6826 |
$result["error"]=$tempOnUpdateAction;
|
| 226 |
liveuser |
6827 |
|
| 3 |
liveuser |
6828 |
#回傳結果
|
|
|
6829 |
return $result;
|
| 226 |
liveuser |
6830 |
|
| 3 |
liveuser |
6831 |
}#if end
|
| 226 |
liveuser |
6832 |
|
| 3 |
liveuser |
6833 |
#紀錄外鍵更新的動作
|
|
|
6834 |
$result["foreignKey"]["onUpdateAction"][]=$tempOnUpdateAction["content"];
|
| 226 |
liveuser |
6835 |
|
| 3 |
liveuser |
6836 |
#用 freign key 的名稱來紀錄外鍵更新的動作
|
|
|
6837 |
$result["foreignKey"]["onUpdateAction"][$thisForeignKeyColumnName["content"]]=$tempOnUpdateAction["content"];
|
| 226 |
liveuser |
6838 |
|
| 3 |
liveuser |
6839 |
}#else end
|
| 226 |
liveuser |
6840 |
|
| 3 |
liveuser |
6841 |
}#if end
|
| 226 |
liveuser |
6842 |
|
| 3 |
liveuser |
6843 |
#如果有 "ON DELETE" 存在
|
|
|
6844 |
#函式說明:
|
|
|
6845 |
#檢查字串裡面有無指定的關鍵字
|
|
|
6846 |
#回傳結果::
|
|
|
6847 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
6848 |
#$result["error"],錯誤訊息
|
|
|
6849 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
6850 |
#必填參數:
|
|
|
6851 |
$conf["search"]["findKeyWord"]["keyWord"]="ON DELETE";#想要搜尋的關鍵字
|
|
|
6852 |
$conf["search"]["findKeyWord"]["string"]=$unClassifyString;#要被搜尋的字串內容
|
|
|
6853 |
#可省略參數:
|
|
|
6854 |
#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
6855 |
$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
|
|
|
6856 |
unset($conf["search"]["findKeyWord"]);
|
| 226 |
liveuser |
6857 |
|
| 3 |
liveuser |
6858 |
#如果尋找關鍵字失敗
|
|
|
6859 |
if($searchResult["status"]=="false"){
|
| 226 |
liveuser |
6860 |
|
| 3 |
liveuser |
6861 |
#設置執行不正常
|
|
|
6862 |
$result["status"]="false";
|
| 226 |
liveuser |
6863 |
|
| 3 |
liveuser |
6864 |
#設置錯誤訊息
|
|
|
6865 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
6866 |
|
| 3 |
liveuser |
6867 |
#回傳結果
|
|
|
6868 |
return $result;
|
| 226 |
liveuser |
6869 |
|
| 3 |
liveuser |
6870 |
}#if end
|
| 226 |
liveuser |
6871 |
|
| 3 |
liveuser |
6872 |
#如果有找到 "ON DELETE"
|
| 226 |
liveuser |
6873 |
if($searchResult["founded"]=="true"){
|
|
|
6874 |
|
| 3 |
liveuser |
6875 |
#用 "ON DELETE " 來分割字串
|
|
|
6876 |
#函式說明:
|
|
|
6877 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
6878 |
#回傳的參數:
|
|
|
6879 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
6880 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
6881 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
6882 |
#必填參數:
|
|
|
6883 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$unClassifyString;#要處理的字串。
|
|
|
6884 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="ON DELETE ";#爲以哪個符號作爲分割
|
|
|
6885 |
$foreignKeyOnDeleteString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
6886 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
6887 |
|
| 3 |
liveuser |
6888 |
#如果分割字串失敗
|
|
|
6889 |
if($foreignKeyOnDeleteString["status"]=="false"){
|
| 226 |
liveuser |
6890 |
|
| 3 |
liveuser |
6891 |
#設置執行不正常
|
|
|
6892 |
$result["status"]="false";
|
| 226 |
liveuser |
6893 |
|
| 3 |
liveuser |
6894 |
#設置錯誤訊息
|
|
|
6895 |
$result["error"]=$foreignKeyOnDeleteString;
|
| 226 |
liveuser |
6896 |
|
| 3 |
liveuser |
6897 |
#回傳結果
|
|
|
6898 |
return $result;
|
| 226 |
liveuser |
6899 |
|
| 3 |
liveuser |
6900 |
}#if end
|
| 226 |
liveuser |
6901 |
|
| 3 |
liveuser |
6902 |
#檢查裏面是否含有 " ON UPDATE " 字樣
|
|
|
6903 |
#函式說明:
|
|
|
6904 |
#檢查字串裡面有無指定的關鍵字
|
|
|
6905 |
#回傳結果::
|
|
|
6906 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
6907 |
#$result["error"],錯誤訊息
|
|
|
6908 |
#$result["founded"],是否找到關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
6909 |
#必填參數:
|
|
|
6910 |
$conf["search"]["findKeyWord"]["keyWord"]="ON UPDATE ";#想要搜尋的關鍵字
|
|
|
6911 |
$conf["search"]["findKeyWord"]["string"]=$foreignKeyOnDeleteString["dataArray"][1];#要被搜尋的字串內容
|
|
|
6912 |
#可省略參數:
|
|
|
6913 |
#$conf["search"]["findKeyWord"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
6914 |
$searchResult=search::findKeyWord($conf["search"]["findKeyWord"]);
|
|
|
6915 |
unset($conf["search"]["findKeyWord"]);
|
| 226 |
liveuser |
6916 |
|
| 3 |
liveuser |
6917 |
#如果分割字串失敗
|
|
|
6918 |
if($searchResult["status"]=="false"){
|
| 226 |
liveuser |
6919 |
|
| 3 |
liveuser |
6920 |
#設置執行不正常
|
|
|
6921 |
$result["status"]="false";
|
| 226 |
liveuser |
6922 |
|
| 3 |
liveuser |
6923 |
#設置錯誤訊息
|
|
|
6924 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
6925 |
|
| 3 |
liveuser |
6926 |
#回傳結果
|
|
|
6927 |
return $result;
|
| 226 |
liveuser |
6928 |
|
| 3 |
liveuser |
6929 |
}#if end
|
| 226 |
liveuser |
6930 |
|
| 3 |
liveuser |
6931 |
#如果裏面含有 "ON UPDATE " 字樣
|
|
|
6932 |
if($searchResult["founded"]=="true"){
|
| 226 |
liveuser |
6933 |
|
| 3 |
liveuser |
6934 |
#我們只要取得 "ON UPDATE " 前面的內容
|
|
|
6935 |
#用"ON UPDATE "來分割
|
|
|
6936 |
#函式說明:
|
|
|
6937 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
6938 |
#回傳的參數:
|
|
|
6939 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
6940 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
6941 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
6942 |
#必填參數:
|
|
|
6943 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$foreignKeyOnDeleteString["dataArray"][1];#要處理的字串。
|
|
|
6944 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]=" ON UPDATE ";#爲以哪個符號作爲分割
|
|
|
6945 |
$foreignKeyOnDeleteString=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
6946 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
6947 |
|
| 3 |
liveuser |
6948 |
#如果分割字串失敗
|
|
|
6949 |
if($searchResult["status"]=="false"){
|
| 226 |
liveuser |
6950 |
|
| 3 |
liveuser |
6951 |
#設置執行不正常
|
|
|
6952 |
$result["status"]="false";
|
| 226 |
liveuser |
6953 |
|
| 3 |
liveuser |
6954 |
#設置錯誤訊息
|
|
|
6955 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
6956 |
|
| 3 |
liveuser |
6957 |
#回傳結果
|
|
|
6958 |
return $result;
|
| 226 |
liveuser |
6959 |
|
| 3 |
liveuser |
6960 |
}#if end
|
| 226 |
liveuser |
6961 |
|
| 3 |
liveuser |
6962 |
$foreignKeyOnDeleteString=$foreignKeyOnDeleteString["dataArray"][0];
|
| 226 |
liveuser |
6963 |
|
| 3 |
liveuser |
6964 |
#將 $foreignKeyString[0] 的非必要字元踢除
|
| 226 |
liveuser |
6965 |
#將「,」、「`」、「(」、「)」去掉
|
| 3 |
liveuser |
6966 |
#函式說明:
|
|
|
6967 |
#處理字串避免網頁出錯
|
|
|
6968 |
#回傳結果::
|
|
|
6969 |
#$result,爲處理好的字串。
|
|
|
6970 |
#必填參數:
|
|
|
6971 |
$conf["stringProcess"]["correctCharacter"]["stringIn"]=$foreignKeyOnDeleteString;#爲要處理的字串
|
|
|
6972 |
#可省略參數:
|
|
|
6973 |
$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
6974 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
6975 |
#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
6976 |
$tempOneleteAction=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
|
|
|
6977 |
unset($conf["stringProcess"]["correctCharacter"]);
|
| 226 |
liveuser |
6978 |
|
| 3 |
liveuser |
6979 |
#如果處理字串失敗
|
|
|
6980 |
if($tempOneleteAction["status"]=="false"){
|
| 226 |
liveuser |
6981 |
|
| 3 |
liveuser |
6982 |
#設置執行不正常
|
|
|
6983 |
$result["status"]="false";
|
| 226 |
liveuser |
6984 |
|
| 3 |
liveuser |
6985 |
#設置錯誤訊息
|
|
|
6986 |
$result["error"]=$tempOneleteAction;
|
| 226 |
liveuser |
6987 |
|
| 3 |
liveuser |
6988 |
#回傳結果
|
|
|
6989 |
return $result;
|
| 226 |
liveuser |
6990 |
|
| 3 |
liveuser |
6991 |
}#if end
|
| 226 |
liveuser |
6992 |
|
| 3 |
liveuser |
6993 |
#儲存外鍵移除後的動作
|
|
|
6994 |
$result["foreignKey"]["onDeleteAction"][]=$tempOneleteAction["content"];
|
| 226 |
liveuser |
6995 |
|
| 3 |
liveuser |
6996 |
#用 freign key 的名稱來紀錄外鍵移除後的動作
|
|
|
6997 |
$result["foreignKey"]["onDeleteAction"][$thisForeignKeyColumnName["content"]]=$tempOneleteAction["content"];
|
| 226 |
liveuser |
6998 |
|
| 3 |
liveuser |
6999 |
}#if end
|
| 226 |
liveuser |
7000 |
|
| 3 |
liveuser |
7001 |
#反之裏面沒有 "ON UPDATE " 字樣
|
|
|
7002 |
else{
|
| 226 |
liveuser |
7003 |
|
| 3 |
liveuser |
7004 |
#將 $foreignKeyString[0] 的非必要字元踢除
|
| 226 |
liveuser |
7005 |
#將「,」、「`」、「(」、「)」去掉
|
| 3 |
liveuser |
7006 |
#函式說明:
|
|
|
7007 |
#處理字串避免網頁出錯
|
|
|
7008 |
#回傳結果::
|
|
|
7009 |
#$result,爲處理好的字串。
|
|
|
7010 |
#必填參數:
|
|
|
7011 |
$conf["stringProcess"]["correctCharacter"]["stringIn"]=$foreignKeyOnDeleteString["dataArray"][1];#爲要處理的字串
|
|
|
7012 |
#可省略參數:
|
|
|
7013 |
$conf["stringProcess"]["correctCharacter"]["selectedCharacter"]=array(",");#爲被選擇要處理的字串/字元,須爲陣列值。
|
|
|
7014 |
#若不設定則預設爲要將這些字串作替換("<",">",";","=","//","'","$","%","&","|","/*","*\/","#")。
|
|
|
7015 |
#$conf["stringProcess"]["correctCharacter"]["changeTo"]=array();#爲被選擇的字元要換成什麼字串/字元,須爲陣列值。若不設定,則預設爲更換成""(空字串)。
|
|
|
7016 |
$tempOneleteAction=stringProcess::correctCharacter($conf["stringProcess"]["correctCharacter"]);
|
|
|
7017 |
unset($conf["stringProcess"]["correctCharacter"]);
|
| 226 |
liveuser |
7018 |
|
| 3 |
liveuser |
7019 |
#如果處理字串失敗
|
|
|
7020 |
if($tempOneleteAction["status"]=="false"){
|
| 226 |
liveuser |
7021 |
|
| 3 |
liveuser |
7022 |
#設置執行不正常
|
|
|
7023 |
$result["status"]="false";
|
| 226 |
liveuser |
7024 |
|
| 3 |
liveuser |
7025 |
#設置錯誤訊息
|
|
|
7026 |
$result["error"]=$tempOneleteAction;
|
| 226 |
liveuser |
7027 |
|
| 3 |
liveuser |
7028 |
#回傳結果
|
|
|
7029 |
return $result;
|
| 226 |
liveuser |
7030 |
|
| 3 |
liveuser |
7031 |
}#if end
|
| 226 |
liveuser |
7032 |
|
| 3 |
liveuser |
7033 |
#取得 外鍵移除後的動作
|
|
|
7034 |
$result["foreignKey"]["OnDeleteAction"][]=$tempOneleteAction["content"];
|
| 226 |
liveuser |
7035 |
|
| 3 |
liveuser |
7036 |
#用 freign key 的名稱來紀錄外鍵移除後的動作
|
|
|
7037 |
$result["foreignKey"]["onDeleteAction"][$thisForeignKeyColumnName]=$tempOneleteAction["content"];
|
| 226 |
liveuser |
7038 |
|
| 3 |
liveuser |
7039 |
}#else end
|
| 226 |
liveuser |
7040 |
|
| 3 |
liveuser |
7041 |
}#if end
|
| 226 |
liveuser |
7042 |
|
| 3 |
liveuser |
7043 |
}#if end
|
| 226 |
liveuser |
7044 |
|
| 3 |
liveuser |
7045 |
}#if end
|
| 226 |
liveuser |
7046 |
|
| 3 |
liveuser |
7047 |
}#foreach end
|
| 226 |
liveuser |
7048 |
|
| 3 |
liveuser |
7049 |
#如果儲存索引鍵資訊的變數存在
|
|
|
7050 |
if(isset($result["key"])){
|
| 226 |
liveuser |
7051 |
|
| 3 |
liveuser |
7052 |
#如果索引鍵的數量大於0
|
|
|
7053 |
if(count($result["key"])>0){
|
| 226 |
liveuser |
7054 |
|
| 3 |
liveuser |
7055 |
#設置 $result["key"]["exist"] 為 "true";
|
|
|
7056 |
$result["key"]["exist"]="true";
|
| 226 |
liveuser |
7057 |
|
| 3 |
liveuser |
7058 |
}#if end
|
| 226 |
liveuser |
7059 |
|
|
|
7060 |
#反之沒有索引鍵
|
| 3 |
liveuser |
7061 |
else{
|
| 226 |
liveuser |
7062 |
|
| 3 |
liveuser |
7063 |
#設置 $result["key"]["exist"] 為 "false";
|
|
|
7064 |
$result["key"]["exist"]="false";
|
| 226 |
liveuser |
7065 |
|
| 3 |
liveuser |
7066 |
}#else end
|
| 226 |
liveuser |
7067 |
|
| 3 |
liveuser |
7068 |
}#if end
|
| 226 |
liveuser |
7069 |
|
| 3 |
liveuser |
7070 |
#如果 $result["foreignKey"]["constraintName"] 存在
|
|
|
7071 |
if(isset($result["foreignKey"]["constraintName"])){
|
| 226 |
liveuser |
7072 |
|
| 3 |
liveuser |
7073 |
#如果 $result["foreignKey"]["constraintName"] 數量大於 0
|
|
|
7074 |
if(count($result["foreignKey"]["constraintName"])>0){
|
| 226 |
liveuser |
7075 |
|
|
|
7076 |
#針對每個 $result["foreignKey"]["constraintName"][$k]
|
| 3 |
liveuser |
7077 |
for($i=0;$i<count($result["foreignKey"]["columnName"])/2;$i++){
|
| 226 |
liveuser |
7078 |
|
| 3 |
liveuser |
7079 |
#指派 $result["foreignKey"]["constraintName"][$k] 的內容同時指派給 $result["foreignKey"]["constraintName"][$result["foreignKey"]["columnName"][$k]]
|
|
|
7080 |
$result["foreignKey"]["constraintName"][$result["foreignKey"]["columnName"][$i]]=$result["foreignKey"]["constraintName"][$i];
|
| 226 |
liveuser |
7081 |
|
| 3 |
liveuser |
7082 |
}#if end
|
| 226 |
liveuser |
7083 |
|
| 3 |
liveuser |
7084 |
#將 $result["foreignKey"]["exist"] 設為 "true"
|
|
|
7085 |
$result["foreignKey"]["exist"]="true";
|
| 226 |
liveuser |
7086 |
|
| 3 |
liveuser |
7087 |
}#if end
|
| 226 |
liveuser |
7088 |
|
| 3 |
liveuser |
7089 |
#反之 $result["foreignKey"]["exist"] 數量等於 0
|
|
|
7090 |
else{
|
| 226 |
liveuser |
7091 |
|
| 3 |
liveuser |
7092 |
#將 $result["foreignKey"]["exist"] 設為 "fasle"
|
|
|
7093 |
$result["foreignKey"]["exist"]="false";
|
| 226 |
liveuser |
7094 |
|
| 3 |
liveuser |
7095 |
}#else end
|
| 226 |
liveuser |
7096 |
|
|
|
7097 |
}#if end
|
|
|
7098 |
|
| 3 |
liveuser |
7099 |
#反之 $result["foreignKey"]["constraintName"] 不存在
|
|
|
7100 |
else{
|
| 226 |
liveuser |
7101 |
|
| 3 |
liveuser |
7102 |
#將 $result["foreignKey"]["exist"] 設為 "fasle"
|
|
|
7103 |
$result["foreignKey"]["exist"]="false";
|
| 226 |
liveuser |
7104 |
|
| 3 |
liveuser |
7105 |
}#else end
|
| 226 |
liveuser |
7106 |
|
| 3 |
liveuser |
7107 |
#執行到這邊代表執行成功
|
| 226 |
liveuser |
7108 |
|
| 3 |
liveuser |
7109 |
#設置成功訊息
|
|
|
7110 |
$result["status"]="true";
|
| 226 |
liveuser |
7111 |
|
| 3 |
liveuser |
7112 |
#回傳結果
|
|
|
7113 |
return $result;
|
| 226 |
liveuser |
7114 |
|
| 3 |
liveuser |
7115 |
}#function getTableColumnDetailInfo end
|
|
|
7116 |
|
|
|
7117 |
/*
|
|
|
7118 |
#函式說明:
|
|
|
7119 |
#移除資料表單1欄位的外鍵
|
|
|
7120 |
#回傳結果:
|
|
|
7121 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗
|
|
|
7122 |
#$result["function"],當前執行的函數名稱.
|
|
|
7123 |
#$result["error"],錯誤訊息陣列
|
|
|
7124 |
#$result["sql"],執行的sql字串.
|
|
|
7125 |
#必填參數:
|
|
|
7126 |
#$conf["dbAddress"],字串,爲mysql-Server的位置
|
|
|
7127 |
$conf["dbAddress"]=$dbAddress;
|
|
|
7128 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
|
|
|
7129 |
$conf["dbAccount"]=$dbAccount;
|
|
|
7130 |
#$conf["selectedDataBaseName"],字串,爲目標資料表所屬的資料庫.
|
|
|
7131 |
$conf["selectedDataBaseName"]="";
|
|
|
7132 |
#$conf["selectedDataTableName"],字串,爲目標資料表所屬的資料庫.
|
|
|
7133 |
$conf["selectedDataTableName"]="";
|
|
|
7134 |
#$conf["erasedForeignKeyColumnConstraintName"],字串,要移除外鍵欄位的CONSTRAINT名稱.
|
|
|
7135 |
$conf["erasedForeignKeyColumnConstraintName"]="";
|
| 226 |
liveuser |
7136 |
#可省略參數:
|
| 3 |
liveuser |
7137 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
7138 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
7139 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
|
|
|
7140 |
#$conf["dbPort"]="3306";
|
|
|
7141 |
#參考資料:
|
|
|
7142 |
#無.
|
|
|
7143 |
#備註:
|
|
|
7144 |
#無.
|
| 226 |
liveuser |
7145 |
*/
|
| 3 |
liveuser |
7146 |
public static function eraseForeignKey($conf){
|
| 226 |
liveuser |
7147 |
|
| 3 |
liveuser |
7148 |
#初始化要回傳的內容
|
|
|
7149 |
$result=array();
|
|
|
7150 |
|
|
|
7151 |
#取得當前執行的函數名稱
|
|
|
7152 |
$result["function"]=__FUNCTION__;
|
|
|
7153 |
|
|
|
7154 |
#如果 $conf 不為陣列
|
|
|
7155 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
7156 |
|
| 3 |
liveuser |
7157 |
#設置執行失敗
|
|
|
7158 |
$result["status"]="false";
|
| 226 |
liveuser |
7159 |
|
| 3 |
liveuser |
7160 |
#設置執行錯誤訊息
|
|
|
7161 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
7162 |
|
|
|
7163 |
#如果傳入的參數為 null
|
|
|
7164 |
if($conf==null){
|
| 226 |
liveuser |
7165 |
|
| 3 |
liveuser |
7166 |
#設置執行錯誤訊息
|
|
|
7167 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
7168 |
|
| 3 |
liveuser |
7169 |
}#if end
|
|
|
7170 |
|
|
|
7171 |
#回傳結果
|
|
|
7172 |
return $result;
|
| 226 |
liveuser |
7173 |
|
| 3 |
liveuser |
7174 |
}#if end
|
| 226 |
liveuser |
7175 |
|
| 3 |
liveuser |
7176 |
#函式說明:
|
|
|
7177 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
7178 |
#回傳結果:
|
|
|
7179 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
7180 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
7181 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
7182 |
#必填參數:
|
|
|
7183 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
7184 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName","erasedForeignKeyColumnConstraintName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
7185 |
#可省略參數:
|
| 226 |
liveuser |
7186 |
#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
7187 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
7188 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
7189 |
unset($conf["variableCheck"]["isexistMuti"]);
|
| 226 |
liveuser |
7190 |
|
| 3 |
liveuser |
7191 |
#如果檢查不通過
|
|
|
7192 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
7193 |
|
| 3 |
liveuser |
7194 |
#設置執行失敗的訊息
|
|
|
7195 |
$result["status"]="false";
|
| 226 |
liveuser |
7196 |
|
| 3 |
liveuser |
7197 |
#設置錯誤訊息
|
|
|
7198 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
7199 |
|
| 3 |
liveuser |
7200 |
#回傳結果
|
|
|
7201 |
return $result;
|
| 226 |
liveuser |
7202 |
|
| 3 |
liveuser |
7203 |
}#if end
|
| 226 |
liveuser |
7204 |
|
| 3 |
liveuser |
7205 |
#移除foreignKey的語法
|
|
|
7206 |
$sql="ALTER TABLE ".$conf["selectedDataBaseName"].".".$conf["selectedDataTableName"]." DROP FOREIGN KEY ".$conf["erasedForeignKeyColumnConstraintName"];
|
| 226 |
liveuser |
7207 |
|
| 3 |
liveuser |
7208 |
#函式說明:
|
|
|
7209 |
#執行mysql查詢的指令
|
|
|
7210 |
#回傳結果::
|
|
|
7211 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
7212 |
#$result["error"],錯誤訊息的陣列
|
|
|
7213 |
#查詢號的解果,需要解析。
|
|
|
7214 |
#必填參數:
|
|
|
7215 |
$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
7216 |
$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
7217 |
$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
|
| 226 |
liveuser |
7218 |
#可省略參數:
|
|
|
7219 |
|
| 3 |
liveuser |
7220 |
#如果有設定密碼
|
|
|
7221 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
7222 |
|
| 3 |
liveuser |
7223 |
$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
7224 |
|
| 3 |
liveuser |
7225 |
}#if end
|
| 226 |
liveuser |
7226 |
|
|
|
7227 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
7228 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
7229 |
|
| 3 |
liveuser |
7230 |
#設定 $conf["dbPort"]
|
|
|
7231 |
$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
7232 |
|
|
|
7233 |
}#if end
|
|
|
7234 |
|
| 3 |
liveuser |
7235 |
$queryResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
|
|
|
7236 |
unset($conf["db"]["execMysqlQuery"]);
|
| 226 |
liveuser |
7237 |
|
| 3 |
liveuser |
7238 |
#取得執行的sql語法
|
|
|
7239 |
$result["sql"]=$queryResult["queryString"];
|
| 226 |
liveuser |
7240 |
|
| 3 |
liveuser |
7241 |
#如果執行sql語法錯誤
|
|
|
7242 |
if($queryResult["status"]=="false"){
|
| 226 |
liveuser |
7243 |
|
| 3 |
liveuser |
7244 |
#設置執行失敗的識別
|
|
|
7245 |
$result["status"]="false";
|
| 226 |
liveuser |
7246 |
|
| 3 |
liveuser |
7247 |
#設置執行錯誤資訊
|
|
|
7248 |
$result["error"]=$queryResult;
|
| 226 |
liveuser |
7249 |
|
| 3 |
liveuser |
7250 |
#回傳結果
|
|
|
7251 |
return $result;
|
| 226 |
liveuser |
7252 |
|
| 3 |
liveuser |
7253 |
}#if end
|
| 226 |
liveuser |
7254 |
|
| 3 |
liveuser |
7255 |
#執行到這邊代表執行無誤
|
| 226 |
liveuser |
7256 |
|
| 3 |
liveuser |
7257 |
#設置執行成功的識別
|
|
|
7258 |
$result["status"]="true";
|
| 226 |
liveuser |
7259 |
|
| 3 |
liveuser |
7260 |
#回傳結果
|
|
|
7261 |
return $result;
|
| 226 |
liveuser |
7262 |
|
| 3 |
liveuser |
7263 |
}#function eraseForeignKey end
|
|
|
7264 |
|
|
|
7265 |
/*
|
|
|
7266 |
#函式說明:
|
|
|
7267 |
#移除資料表單1欄位的索引鍵
|
|
|
7268 |
#回傳結果:
|
|
|
7269 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗
|
|
|
7270 |
#$result["error"],錯誤訊息陣列
|
|
|
7271 |
#$result["sql"],執行的sql字串.
|
|
|
7272 |
#必填參數:
|
|
|
7273 |
$conf["dbAddress"],字串,爲mysql-Server的位置.
|
|
|
7274 |
$conf["dbAddress"]=$dbAddress;
|
|
|
7275 |
$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號.
|
|
|
7276 |
$conf["dbAccount"]=$dbAccount;
|
|
|
7277 |
$conf["selectedDataBaseName"],字串,爲目標資料表所屬的資料庫.
|
|
|
7278 |
$conf["selectedDataBaseName"]="";
|
|
|
7279 |
$conf["selectedDataTableName"],字串,爲目標資料表所屬的資料庫.
|
|
|
7280 |
$conf["selectedDataTableName"]="";
|
|
|
7281 |
$conf["erasedIndexKeyColumnConstraintName"],字串,要移除外鍵欄位的CONSTRAINT名稱.
|
|
|
7282 |
$conf["erasedIndexKeyColumnConstraintName"]="";
|
| 226 |
liveuser |
7283 |
#可省略參數:
|
| 3 |
liveuser |
7284 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
7285 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
7286 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
|
|
|
7287 |
#$conf["dbPort"]="3306";
|
|
|
7288 |
#參考資料:
|
|
|
7289 |
#無.
|
|
|
7290 |
#備註:
|
|
|
7291 |
#無.
|
| 226 |
liveuser |
7292 |
*/
|
| 3 |
liveuser |
7293 |
public static function eraseIndexKey($conf){
|
| 226 |
liveuser |
7294 |
|
| 3 |
liveuser |
7295 |
#初始化要回傳的內容
|
|
|
7296 |
$result=array();
|
|
|
7297 |
|
|
|
7298 |
#取得當前執行的函數名稱
|
|
|
7299 |
$result["function"]=__FUNCTION__;
|
|
|
7300 |
|
|
|
7301 |
#如果 $conf 不為陣列
|
|
|
7302 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
7303 |
|
| 3 |
liveuser |
7304 |
#設置執行失敗
|
|
|
7305 |
$result["status"]="false";
|
| 226 |
liveuser |
7306 |
|
| 3 |
liveuser |
7307 |
#設置執行錯誤訊息
|
|
|
7308 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
7309 |
|
|
|
7310 |
#如果傳入的參數為 null
|
|
|
7311 |
if($conf==null){
|
| 226 |
liveuser |
7312 |
|
| 3 |
liveuser |
7313 |
#設置執行錯誤訊息
|
|
|
7314 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
7315 |
|
| 3 |
liveuser |
7316 |
}#if end
|
|
|
7317 |
|
|
|
7318 |
#回傳結果
|
|
|
7319 |
return $result;
|
| 226 |
liveuser |
7320 |
|
| 3 |
liveuser |
7321 |
}#if end
|
| 226 |
liveuser |
7322 |
|
| 3 |
liveuser |
7323 |
#函式說明:
|
|
|
7324 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
7325 |
#回傳結果:
|
|
|
7326 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
7327 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
7328 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
7329 |
#必填參數:
|
|
|
7330 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
7331 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName","erasedIndexKeyColumnConstraintName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
7332 |
#可省略參數:
|
| 226 |
liveuser |
7333 |
#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
7334 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
7335 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
7336 |
unset($conf["variableCheck"]["isexistMuti"]);
|
| 226 |
liveuser |
7337 |
|
| 3 |
liveuser |
7338 |
#檢查有誤
|
|
|
7339 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
7340 |
|
| 3 |
liveuser |
7341 |
#設置執行失敗的訊息
|
|
|
7342 |
$result["status"]="false";
|
| 226 |
liveuser |
7343 |
|
| 3 |
liveuser |
7344 |
#設置錯誤訊息
|
|
|
7345 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
7346 |
|
| 3 |
liveuser |
7347 |
#回傳結果
|
|
|
7348 |
return $result;
|
| 226 |
liveuser |
7349 |
|
| 3 |
liveuser |
7350 |
}#if end
|
| 226 |
liveuser |
7351 |
|
| 3 |
liveuser |
7352 |
#如果檢查不通過
|
|
|
7353 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
7354 |
|
| 3 |
liveuser |
7355 |
#設置執行失敗的訊息
|
|
|
7356 |
$result["status"]="false";
|
| 226 |
liveuser |
7357 |
|
| 3 |
liveuser |
7358 |
#設置錯誤訊息
|
|
|
7359 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
7360 |
|
| 3 |
liveuser |
7361 |
#回傳結果
|
|
|
7362 |
return $result;
|
| 226 |
liveuser |
7363 |
|
| 3 |
liveuser |
7364 |
}#if end
|
| 226 |
liveuser |
7365 |
|
| 3 |
liveuser |
7366 |
#移除Key的語法
|
|
|
7367 |
$sql="ALTER TABLE ".$conf["selectedDataBaseName"].".".$conf["selectedDataTableName"]." DROP INDEX `".$conf["erasedIndexKeyColumnConstraintName"]."`";
|
| 226 |
liveuser |
7368 |
|
| 3 |
liveuser |
7369 |
#函式說明:
|
|
|
7370 |
#執行mysql查詢的指令
|
|
|
7371 |
#回傳結果::
|
|
|
7372 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
7373 |
#$result["error"],錯誤訊息的陣列
|
|
|
7374 |
#查詢號的解果,需要解析。
|
|
|
7375 |
#必填參數:
|
|
|
7376 |
$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
7377 |
$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
7378 |
$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
|
| 226 |
liveuser |
7379 |
#可省略參數:
|
|
|
7380 |
|
| 3 |
liveuser |
7381 |
#如果有設定密碼
|
|
|
7382 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
7383 |
|
| 3 |
liveuser |
7384 |
$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
7385 |
|
| 3 |
liveuser |
7386 |
}#if end
|
| 226 |
liveuser |
7387 |
|
|
|
7388 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
7389 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
7390 |
|
| 3 |
liveuser |
7391 |
#設定 $conf["dbPort"]
|
|
|
7392 |
$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
7393 |
|
|
|
7394 |
}#if end
|
|
|
7395 |
|
| 3 |
liveuser |
7396 |
$queryResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
|
|
|
7397 |
unset($conf["db"]["execMysqlQuery"]);
|
| 226 |
liveuser |
7398 |
|
| 3 |
liveuser |
7399 |
#取得執行的sql語法
|
|
|
7400 |
$result["sql"]=$queryResult["queryString"];
|
| 226 |
liveuser |
7401 |
|
| 3 |
liveuser |
7402 |
#如果執行sql語法錯誤
|
|
|
7403 |
if($queryResult["status"]=="false"){
|
| 226 |
liveuser |
7404 |
|
| 3 |
liveuser |
7405 |
#設置執行失敗的識別
|
|
|
7406 |
$result["status"]="false";
|
| 226 |
liveuser |
7407 |
|
| 3 |
liveuser |
7408 |
#設置執行錯誤資訊
|
|
|
7409 |
$result["error"]=$queryResult;
|
| 226 |
liveuser |
7410 |
|
| 3 |
liveuser |
7411 |
#回傳結果
|
|
|
7412 |
return $result;
|
| 226 |
liveuser |
7413 |
|
| 3 |
liveuser |
7414 |
}#if end
|
| 226 |
liveuser |
7415 |
|
| 3 |
liveuser |
7416 |
#執行到這邊代表執行無誤
|
| 226 |
liveuser |
7417 |
|
| 3 |
liveuser |
7418 |
#設置執行失敗的識別
|
|
|
7419 |
$result["status"]="true";
|
| 226 |
liveuser |
7420 |
|
| 3 |
liveuser |
7421 |
#回傳結果
|
|
|
7422 |
return $result;
|
| 226 |
liveuser |
7423 |
|
| 3 |
liveuser |
7424 |
}#function eraseIndexKey end
|
|
|
7425 |
|
|
|
7426 |
/*
|
|
|
7427 |
#函式說明:
|
|
|
7428 |
#移除資料表的欄位
|
|
|
7429 |
#回傳結果:
|
|
|
7430 |
#$result["status"],若成功則爲"true",失敗則爲,"false"
|
|
|
7431 |
#$result["error"],錯誤訊息.
|
|
|
7432 |
#$result["function"],當前執行的函數名稱.
|
|
|
7433 |
#必填參數:
|
|
|
7434 |
#$conf["dbAddress"],字串,爲mysql-Server的位置.
|
|
|
7435 |
$conf["dbAddress"]=$dbAddress;
|
|
|
7436 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號.
|
|
|
7437 |
$conf["dbAccount"]=$dbAccount;
|
|
|
7438 |
#$conf["selectedDataBaseName"],字串,爲目標資料表所屬的資料庫.
|
|
|
7439 |
$conf["selectedDataBaseName"]="";
|
|
|
7440 |
#$conf["selectedDataTableName"],字串,爲目標資料表所屬的資料庫.
|
|
|
7441 |
$conf["selectedDataTableName"]="";
|
|
|
7442 |
#$conf["removedColumnName"],字串,要移除的欄位名稱.
|
|
|
7443 |
$conf["removedColumnName"]="";
|
| 226 |
liveuser |
7444 |
#可省略參數:
|
| 3 |
liveuser |
7445 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
7446 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
7447 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
|
|
|
7448 |
#$conf["dbPort"]="3306";
|
|
|
7449 |
#參考資料:
|
|
|
7450 |
#無.
|
|
|
7451 |
#備註:
|
|
|
7452 |
#無.
|
|
|
7453 |
*/
|
|
|
7454 |
public static function dropColumn($conf){
|
| 226 |
liveuser |
7455 |
|
| 3 |
liveuser |
7456 |
#初始化要回傳的內容
|
|
|
7457 |
$result=array();
|
|
|
7458 |
|
|
|
7459 |
#取得當前執行的函數名稱
|
|
|
7460 |
$result["function"]=__FUNCTION__;
|
|
|
7461 |
|
|
|
7462 |
#如果 $conf 不為陣列
|
|
|
7463 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
7464 |
|
| 3 |
liveuser |
7465 |
#設置執行失敗
|
|
|
7466 |
$result["status"]="false";
|
| 226 |
liveuser |
7467 |
|
| 3 |
liveuser |
7468 |
#設置執行錯誤訊息
|
|
|
7469 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
7470 |
|
|
|
7471 |
#如果傳入的參數為 null
|
|
|
7472 |
if($conf==null){
|
| 226 |
liveuser |
7473 |
|
| 3 |
liveuser |
7474 |
#設置執行錯誤訊息
|
|
|
7475 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
7476 |
|
| 3 |
liveuser |
7477 |
}#if end
|
|
|
7478 |
|
|
|
7479 |
#回傳結果
|
|
|
7480 |
return $result;
|
| 226 |
liveuser |
7481 |
|
| 3 |
liveuser |
7482 |
}#if end
|
| 226 |
liveuser |
7483 |
|
| 3 |
liveuser |
7484 |
#函式說明:
|
|
|
7485 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
7486 |
#回傳結果:
|
|
|
7487 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
7488 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
7489 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
7490 |
#必填參數:
|
|
|
7491 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
7492 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName","removedColumnName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
7493 |
#可省略參數:
|
| 226 |
liveuser |
7494 |
$conf["variableType"]=array("string","string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
7495 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
7496 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
7497 |
unset($conf["variableCheck"]["isexistMuti"]);
|
| 226 |
liveuser |
7498 |
|
| 3 |
liveuser |
7499 |
#如果檢查失敗
|
|
|
7500 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
7501 |
|
| 3 |
liveuser |
7502 |
#設置執行失敗的訊息
|
|
|
7503 |
$result["status"]="false";
|
| 226 |
liveuser |
7504 |
|
| 3 |
liveuser |
7505 |
#設置錯誤訊息
|
|
|
7506 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
7507 |
|
| 3 |
liveuser |
7508 |
#回傳結果
|
|
|
7509 |
return $result;
|
| 226 |
liveuser |
7510 |
|
| 3 |
liveuser |
7511 |
}#if end
|
| 226 |
liveuser |
7512 |
|
| 3 |
liveuser |
7513 |
#如果檢查不通過
|
|
|
7514 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
7515 |
|
| 3 |
liveuser |
7516 |
#設置執行失敗的訊息
|
|
|
7517 |
$result["status"]="false";
|
| 226 |
liveuser |
7518 |
|
| 3 |
liveuser |
7519 |
#設置錯誤訊息
|
|
|
7520 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
7521 |
|
| 3 |
liveuser |
7522 |
#回傳結果
|
|
|
7523 |
return $result;
|
| 226 |
liveuser |
7524 |
|
| 3 |
liveuser |
7525 |
}#if end
|
| 226 |
liveuser |
7526 |
|
| 3 |
liveuser |
7527 |
#函式說明:
|
|
|
7528 |
#取得資料表所有欄位的詳細資訊
|
|
|
7529 |
#回傳的內容:
|
|
|
7530 |
#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
|
|
|
7531 |
#$result["error"],錯誤訊息陣列
|
|
|
7532 |
#$result["sql"],執行的sql語法
|
|
|
7533 |
#$result["oriInput"],原始的資料表欄位資訊
|
|
|
7534 |
#$result["everyLine"],逐行的欄位資訊
|
|
|
7535 |
#$result["tableName"],當前查詢的資料表名稱
|
|
|
7536 |
#$result["engine"],資料表使用的儲存引擎
|
|
|
7537 |
#$result["charset"],資料表預設的編碼
|
|
|
7538 |
#$result["columnName"][$i],各欄位的名稱陣列,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
7539 |
#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
7540 |
#$result["columnNotNull"][$i],各欄位是否可以不爲null,"true"爲可以不爲null;"false"爲可以爲"null",$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
7541 |
#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
7542 |
#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
7543 |
#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
7544 |
#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
7545 |
#$result["columnCollate"][$i],各欄位使用的Collate,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
7546 |
#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
|
|
|
7547 |
#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
|
|
|
7548 |
#$result["keyConstraintName"][$j],該資料表用於識別索引鍵的CONSTRAINT名稱陣列,$j爲0開始的數字,也可以使用欄位的名稱。
|
|
|
7549 |
#$result["primaryKey"],該資料表的主鍵
|
|
|
7550 |
#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
|
|
|
7551 |
#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲0開始的數字,也可以使用欄位的名稱。
|
|
|
7552 |
#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列,$k爲0開始的數字,也可以使用欄位的名稱。
|
|
|
7553 |
#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲0開始的數字
|
|
|
7554 |
#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲0開始的數字
|
|
|
7555 |
#$result["columnOnUpdateAction"][$i],當參照的欄位資料更新時,會怎麼同步,$i爲0開始的數字,"沒有指定"為沒有設定
|
|
|
7556 |
#$result["columnOnDeleteAction"][$i],當參照的欄位資料移除時,會怎麼同步,$i爲0開始的數字,"沒有指定"為沒有設定
|
|
|
7557 |
#必填參數:
|
|
|
7558 |
$conf["db"]["getTableColumnDetailInfo"]["dbAddress"]=$conf["dbAddress"];#資料庫的網路位置
|
|
|
7559 |
$conf["db"]["getTableColumnDetailInfo"]["dbAccount"]=$conf["dbAccount"];#連線到資料庫要用的帳號
|
|
|
7560 |
$conf["db"]["getTableColumnDetailInfo"]["selectedDataBase"]=$conf["selectedDataBaseName"];#連線到資料庫要選擇的資料庫
|
|
|
7561 |
$conf["db"]["getTableColumnDetailInfo"]["selectedDataTable"]=$conf["selectedDataTableName"];#連線到資料庫要檢視的資料表
|
|
|
7562 |
#可省略參數:
|
| 226 |
liveuser |
7563 |
|
| 3 |
liveuser |
7564 |
#如果 $conf["dbPassword"] 有設置
|
|
|
7565 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
7566 |
|
| 3 |
liveuser |
7567 |
$conf["db"]["getTableColumnDetailInfo"]["dbPassword"]=$conf["dbPassword"];#連線到資料庫要用的密碼
|
| 226 |
liveuser |
7568 |
|
| 3 |
liveuser |
7569 |
}#if end
|
| 226 |
liveuser |
7570 |
|
|
|
7571 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
7572 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
7573 |
|
| 3 |
liveuser |
7574 |
#設定 $conf["dbPort"]
|
|
|
7575 |
$conf["db"]["getTableColumnDetailInfo"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
7576 |
|
|
|
7577 |
}#if end
|
|
|
7578 |
|
| 3 |
liveuser |
7579 |
$tableDetail=db::getTableColumnDetailInfo($conf["db"]["getTableColumnDetailInfo"]);
|
|
|
7580 |
unset($conf["db"]["getTableColumnDetailInfo"]);
|
| 226 |
liveuser |
7581 |
|
| 3 |
liveuser |
7582 |
#如果取得資料表結構詳細資料失敗
|
|
|
7583 |
if($tableDetail["status"]=="false"){
|
| 226 |
liveuser |
7584 |
|
| 3 |
liveuser |
7585 |
#設置執行失敗的訊息
|
|
|
7586 |
$result["status"]="false";
|
| 226 |
liveuser |
7587 |
|
| 3 |
liveuser |
7588 |
#設置錯誤訊息
|
|
|
7589 |
$result["error"]=$tableDetail;
|
| 226 |
liveuser |
7590 |
|
| 3 |
liveuser |
7591 |
#回傳結果
|
|
|
7592 |
return $result;
|
| 226 |
liveuser |
7593 |
|
| 3 |
liveuser |
7594 |
}#if end
|
| 226 |
liveuser |
7595 |
|
| 3 |
liveuser |
7596 |
#var_dump($tableDetail["foreignKey"]);
|
| 226 |
liveuser |
7597 |
|
| 3 |
liveuser |
7598 |
#判斷該欄位是否爲 foreign key
|
|
|
7599 |
if(isset($tableDetail["foreignKey"]["columnName"][$conf["removedColumnName"]])){
|
| 226 |
liveuser |
7600 |
|
|
|
7601 |
#代表該欄位等於 foreign key
|
|
|
7602 |
|
| 3 |
liveuser |
7603 |
#先移除foreign key...
|
|
|
7604 |
#函式說明:
|
|
|
7605 |
#移除資料表單1欄位的外鍵
|
|
|
7606 |
#回傳結果:
|
|
|
7607 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗
|
|
|
7608 |
#$result["error"],錯誤訊息陣列
|
|
|
7609 |
#必填參數:
|
|
|
7610 |
$conf["db"]["eraseForeignKey"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
7611 |
$conf["db"]["eraseForeignKey"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
7612 |
$conf["db"]["eraseForeignKey"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
|
|
|
7613 |
$conf["db"]["eraseForeignKey"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
|
|
|
7614 |
$conf["db"]["eraseForeignKey"]["erasedForeignKeyColumnConstraintName"]=$tableDetail["foreignKey"]["constraintName"][$conf["removedColumnName"]];#要移除外鍵欄位的CONSTRAINT名稱
|
| 226 |
liveuser |
7615 |
#可省略參數:
|
|
|
7616 |
|
| 3 |
liveuser |
7617 |
#如果 $conf["dbPassword"] 有設置
|
|
|
7618 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
7619 |
|
| 3 |
liveuser |
7620 |
$conf["db"]["eraseForeignKey"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
7621 |
|
| 3 |
liveuser |
7622 |
}#if end
|
| 226 |
liveuser |
7623 |
|
|
|
7624 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
7625 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
7626 |
|
| 3 |
liveuser |
7627 |
#設定 $conf["dbPort"]
|
|
|
7628 |
$conf["db"]["eraseForeignKey"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
7629 |
|
|
|
7630 |
}#if end
|
|
|
7631 |
|
| 3 |
liveuser |
7632 |
$eraseForeignKeyResult=db::eraseForeignKey($conf["db"]["eraseForeignKey"]);
|
|
|
7633 |
unset($conf["db"]["eraseForeignKey"]);
|
| 226 |
liveuser |
7634 |
|
| 3 |
liveuser |
7635 |
#var_dump($eraseForeignKeyResult);
|
| 226 |
liveuser |
7636 |
|
| 3 |
liveuser |
7637 |
#如果執行失敗
|
|
|
7638 |
if($eraseForeignKeyResult["status"]=="false"){
|
| 226 |
liveuser |
7639 |
|
| 3 |
liveuser |
7640 |
#var_dump($eraseForeignKeyResult);
|
| 226 |
liveuser |
7641 |
|
| 3 |
liveuser |
7642 |
#設置錯誤識別
|
|
|
7643 |
$result["status"]="fasle";
|
| 226 |
liveuser |
7644 |
|
| 3 |
liveuser |
7645 |
#設置錯誤提示
|
|
|
7646 |
$result["error"]=$eraseForeignKeyResult;
|
| 226 |
liveuser |
7647 |
|
| 3 |
liveuser |
7648 |
#回傳結果
|
|
|
7649 |
return $result;
|
| 226 |
liveuser |
7650 |
|
| 3 |
liveuser |
7651 |
}#if end
|
| 226 |
liveuser |
7652 |
|
| 3 |
liveuser |
7653 |
}#if end
|
| 226 |
liveuser |
7654 |
|
| 3 |
liveuser |
7655 |
#如果要移除欄位是index
|
|
|
7656 |
if(isset($tableDetail["key"][$conf["removedColumnName"]])){
|
| 226 |
liveuser |
7657 |
|
| 3 |
liveuser |
7658 |
#移除索引鍵
|
|
|
7659 |
#函式說明:
|
|
|
7660 |
#移除資料表單1欄位的索引鍵
|
|
|
7661 |
#回傳結果:
|
|
|
7662 |
#$result["status"],"true",代表執行成功;"false"代表執行失敗
|
|
|
7663 |
#$result["error"],錯誤訊息陣列
|
|
|
7664 |
#必填參數:
|
|
|
7665 |
$conf["db"]["eraseIndexKey"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
7666 |
$conf["db"]["eraseIndexKey"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
7667 |
$conf["db"]["eraseIndexKey"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲目標資料表所屬的資料庫
|
|
|
7668 |
$conf["db"]["eraseIndexKey"]["selectedDataTableName"]=$conf["selectedDataTableName"];#爲目標資料表所屬的資料庫
|
|
|
7669 |
$conf["db"]["eraseIndexKey"]["erasedIndexKeyColumnConstraintName"]=$tableDetail["keyConstraintName"][$conf["removedColumnName"]];#要移除索引鍵欄位的CONSTRAINT名稱
|
| 226 |
liveuser |
7670 |
#可省略參數:
|
|
|
7671 |
|
| 3 |
liveuser |
7672 |
#如果 $conf["dbPassword"] 有設置
|
|
|
7673 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
7674 |
|
| 3 |
liveuser |
7675 |
$conf["db"]["eraseIndexKey"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
7676 |
|
| 3 |
liveuser |
7677 |
}#if end
|
| 226 |
liveuser |
7678 |
|
|
|
7679 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
7680 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
7681 |
|
| 3 |
liveuser |
7682 |
#設定 $conf["dbPort"]
|
|
|
7683 |
$conf["db"]["eraseIndexKey"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
7684 |
|
| 3 |
liveuser |
7685 |
}#if end
|
| 226 |
liveuser |
7686 |
|
| 3 |
liveuser |
7687 |
$eraseIndexKeyResult=db::eraseIndexKey($conf["db"]["eraseIndexKey"]);
|
|
|
7688 |
unset($conf["db"]["eraseIndexKey"]);
|
| 226 |
liveuser |
7689 |
|
| 3 |
liveuser |
7690 |
#如果執行失敗
|
|
|
7691 |
if($eraseIndexKeyResult["status"]=="false"){
|
| 226 |
liveuser |
7692 |
|
| 3 |
liveuser |
7693 |
#var_dump($eraseIndexKeyResult);
|
| 226 |
liveuser |
7694 |
|
| 3 |
liveuser |
7695 |
#設置錯誤識別
|
|
|
7696 |
$result["status"]="fasle";
|
| 226 |
liveuser |
7697 |
|
| 3 |
liveuser |
7698 |
#設置錯誤提示
|
|
|
7699 |
$result["error"]=$eraseIndexKeyResult;
|
| 226 |
liveuser |
7700 |
|
| 3 |
liveuser |
7701 |
#回傳結果
|
|
|
7702 |
return $result;
|
| 226 |
liveuser |
7703 |
|
| 3 |
liveuser |
7704 |
}#if end
|
| 226 |
liveuser |
7705 |
|
|
|
7706 |
}#if end
|
|
|
7707 |
|
| 3 |
liveuser |
7708 |
#組合sql語言
|
|
|
7709 |
$sql="alter table ".$conf["selectedDataBaseName"].".".$conf["selectedDataTableName"]." drop `".$conf["removedColumnName"]."`;";
|
| 226 |
liveuser |
7710 |
|
| 3 |
liveuser |
7711 |
#函式說明:
|
|
|
7712 |
#執行mysql指令
|
|
|
7713 |
#回傳結果::
|
|
|
7714 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
7715 |
#$result["error"],錯誤訊息的陣列
|
|
|
7716 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
7717 |
#查詢號的解果,需要解析。
|
|
|
7718 |
#必填參數:
|
|
|
7719 |
$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
7720 |
$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
7721 |
$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
|
| 226 |
liveuser |
7722 |
#可省略參數:
|
|
|
7723 |
|
| 3 |
liveuser |
7724 |
#如果有設定連線密碼
|
|
|
7725 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
7726 |
|
| 3 |
liveuser |
7727 |
#就套用密碼
|
|
|
7728 |
$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
7729 |
|
| 3 |
liveuser |
7730 |
}#if end
|
| 226 |
liveuser |
7731 |
|
|
|
7732 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
7733 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
7734 |
|
| 3 |
liveuser |
7735 |
#設定 $conf["dbPort"]
|
|
|
7736 |
$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
7737 |
|
| 3 |
liveuser |
7738 |
}#if end
|
| 226 |
liveuser |
7739 |
|
| 3 |
liveuser |
7740 |
$queryResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
|
|
|
7741 |
unset($conf["db"]["execMysqlQuery"]);
|
| 226 |
liveuser |
7742 |
|
| 3 |
liveuser |
7743 |
#如果執行失敗
|
|
|
7744 |
if($queryResult["status"]=="false"){
|
| 226 |
liveuser |
7745 |
|
| 3 |
liveuser |
7746 |
#設置執行失敗
|
|
|
7747 |
$result["status"]="false";
|
| 226 |
liveuser |
7748 |
|
| 3 |
liveuser |
7749 |
#取得錯誤訊息
|
|
|
7750 |
$result["error"]=$queryResult;
|
| 226 |
liveuser |
7751 |
|
| 3 |
liveuser |
7752 |
#回傳結果
|
|
|
7753 |
return $result;
|
| 226 |
liveuser |
7754 |
|
| 3 |
liveuser |
7755 |
}#if end
|
| 226 |
liveuser |
7756 |
|
| 3 |
liveuser |
7757 |
#設置執行成功
|
|
|
7758 |
$result["status"]="true";
|
| 226 |
liveuser |
7759 |
|
| 3 |
liveuser |
7760 |
#回傳結果
|
|
|
7761 |
return $result;
|
| 226 |
liveuser |
7762 |
|
| 3 |
liveuser |
7763 |
}#function dropColumn end
|
|
|
7764 |
|
|
|
7765 |
/*
|
|
|
7766 |
#函式說明:
|
|
|
7767 |
#清空資料表儲存的資料
|
|
|
7768 |
#回傳結果::
|
|
|
7769 |
#$result["status"],執行成功與否,"true"代表執行成功;"fasle"代表執行失敗
|
|
|
7770 |
#$result["error"],錯誤訊息
|
|
|
7771 |
#$result["function"],當前執行的涵式.
|
|
|
7772 |
#必填參數:
|
|
|
7773 |
$conf["dbAddress"]="字串,爲mysql-Server的位置
|
|
|
7774 |
$conf["dbAddress"]=$dbAddress;
|
|
|
7775 |
$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
|
|
|
7776 |
$conf["dbAccount"]=$dbAccount;
|
|
|
7777 |
$conf["dbName"]=$dbName;#爲目標資料表所屬的資料庫
|
|
|
7778 |
$conf["dtName"]="";#爲要移除的資料表名稱
|
| 226 |
liveuser |
7779 |
#可省略參數:
|
| 3 |
liveuser |
7780 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
7781 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
7782 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
|
|
|
7783 |
#$conf["dbPort"]="3306";
|
|
|
7784 |
#參考資料:
|
|
|
7785 |
#https://dev.mysql.com/doc/refman/5.0/en/truncate-table.html
|
|
|
7786 |
#備註:
|
|
|
7787 |
#無.
|
|
|
7788 |
*/
|
|
|
7789 |
public static function emptyTable($conf){
|
| 226 |
liveuser |
7790 |
|
| 3 |
liveuser |
7791 |
#初始化要回傳的內容
|
|
|
7792 |
$result=array();
|
|
|
7793 |
|
|
|
7794 |
#取得當前執行的函數名稱
|
|
|
7795 |
$result["function"]=__FUNCTION__;
|
|
|
7796 |
|
|
|
7797 |
#如果 $conf 不為陣列
|
|
|
7798 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
7799 |
|
| 3 |
liveuser |
7800 |
#設置執行失敗
|
|
|
7801 |
$result["status"]="false";
|
| 226 |
liveuser |
7802 |
|
| 3 |
liveuser |
7803 |
#設置執行錯誤訊息
|
|
|
7804 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
7805 |
|
|
|
7806 |
#如果傳入的參數為 null
|
|
|
7807 |
if($conf==null){
|
| 226 |
liveuser |
7808 |
|
| 3 |
liveuser |
7809 |
#設置執行錯誤訊息
|
|
|
7810 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
7811 |
|
| 3 |
liveuser |
7812 |
}#if end
|
|
|
7813 |
|
|
|
7814 |
#回傳結果
|
|
|
7815 |
return $result;
|
| 226 |
liveuser |
7816 |
|
| 3 |
liveuser |
7817 |
}#if end
|
| 226 |
liveuser |
7818 |
|
| 3 |
liveuser |
7819 |
#函式說明:
|
|
|
7820 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
7821 |
#回傳結果:
|
|
|
7822 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
7823 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
7824 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
7825 |
#必填參數:
|
|
|
7826 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
7827 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","dbName","dtName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
7828 |
#可省略參數:
|
| 226 |
liveuser |
7829 |
#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
7830 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
7831 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
7832 |
unset($conf["variableCheck"]);
|
|
|
7833 |
|
|
|
7834 |
#如果檢查不通過
|
|
|
7835 |
if($checkResult["status"]=="false"){
|
|
|
7836 |
|
|
|
7837 |
#設置錯誤識別
|
|
|
7838 |
$result["status"]="fasle";
|
| 226 |
liveuser |
7839 |
|
| 3 |
liveuser |
7840 |
#設置錯誤訊息
|
|
|
7841 |
$result["error"]=$checkResult;
|
|
|
7842 |
|
|
|
7843 |
#回傳結果
|
|
|
7844 |
return $result;
|
|
|
7845 |
|
|
|
7846 |
}#if end
|
|
|
7847 |
|
|
|
7848 |
#如果檢查不通過
|
|
|
7849 |
if($checkResult["passed"]=="false"){
|
|
|
7850 |
|
|
|
7851 |
#設置錯誤識別
|
|
|
7852 |
$result["status"]="fasle";
|
| 226 |
liveuser |
7853 |
|
| 3 |
liveuser |
7854 |
#設置錯誤訊息
|
|
|
7855 |
$result["error"]=$checkResult;
|
|
|
7856 |
|
|
|
7857 |
#回傳結果
|
|
|
7858 |
return $result;
|
|
|
7859 |
|
|
|
7860 |
}#if end
|
| 226 |
liveuser |
7861 |
|
| 3 |
liveuser |
7862 |
#設定要執行的sql語法
|
|
|
7863 |
$sql="TRUNCATE TABLE ".$conf["dbName"].".".$conf["dtName"].";";
|
| 226 |
liveuser |
7864 |
|
| 3 |
liveuser |
7865 |
#函式說明:
|
|
|
7866 |
#執行mysql指令
|
|
|
7867 |
#回傳結果::
|
|
|
7868 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
7869 |
#$result["error"],錯誤訊息的陣列
|
|
|
7870 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
7871 |
#$result["queryString"],mysql查詢的語言
|
|
|
7872 |
#查詢號的解果,需要解析。
|
|
|
7873 |
#必填參數:
|
|
|
7874 |
$conf["db.execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
7875 |
$conf["db.execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
7876 |
$conf["db.execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
|
| 226 |
liveuser |
7877 |
#可省略參數:
|
|
|
7878 |
|
| 3 |
liveuser |
7879 |
#如果 $conf["dbPassword"] 有設置
|
|
|
7880 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
7881 |
|
| 3 |
liveuser |
7882 |
$conf["db.execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
7883 |
|
| 3 |
liveuser |
7884 |
}#if end
|
| 226 |
liveuser |
7885 |
|
|
|
7886 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
7887 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
7888 |
|
| 3 |
liveuser |
7889 |
#設定 $conf["dbPort"]
|
|
|
7890 |
$conf["db.execMysqlQuery"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
7891 |
|
|
|
7892 |
}#if end
|
|
|
7893 |
|
| 3 |
liveuser |
7894 |
$queryResult=db::execMysqlQuery($conf["db.execMysqlQuery"]);
|
|
|
7895 |
unset($conf["db.execMysqlQuery"]);
|
| 226 |
liveuser |
7896 |
|
| 3 |
liveuser |
7897 |
#如果 $queryResult["status"] 為 "false"
|
|
|
7898 |
if($queryResult["status"]=="false"){
|
| 226 |
liveuser |
7899 |
|
| 3 |
liveuser |
7900 |
#函式說明:
|
|
|
7901 |
#透過一筆筆將資料表刪除後,重設識別欄位的自動增量欄位起始值為1
|
|
|
7902 |
#回傳結果:
|
|
|
7903 |
#$result["status"],執行是否正常,"true"代表執行正常,"false"代表執行失敗.
|
|
|
7904 |
#$result["error"],錯誤訊息.
|
|
|
7905 |
#$result["function"],當前執行的函數名稱.
|
|
|
7906 |
#$result["sql"],執行的sql語法陣列.
|
|
|
7907 |
#必填參數:
|
|
|
7908 |
#$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbAddress"],字串,連線到資料庫的位置.
|
|
|
7909 |
$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbAddress"]=$conf["dbAddress"];
|
|
|
7910 |
#$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbAccount"],字串,連線到資料庫的帳號.
|
|
|
7911 |
$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbAccount"]=$conf["dbAccount"];
|
|
|
7912 |
#$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbName"],字串,要連線到哪個資料庫.
|
|
|
7913 |
$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbName"]=$conf["dbName"];
|
|
|
7914 |
#$conf["db.eraseDataInTableThenResetAutoIncrement"]["dtName"],字串,要重設重設識別欄位的自動增量為0的資料表名稱.
|
|
|
7915 |
$conf["db.eraseDataInTableThenResetAutoIncrement"]["dtName"]=$conf["dtName"];
|
|
|
7916 |
#可省略參數:
|
| 226 |
liveuser |
7917 |
|
| 3 |
liveuser |
7918 |
#如果 $conf["dbPassword"] 有設置
|
|
|
7919 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
7920 |
|
| 3 |
liveuser |
7921 |
#$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbPassword"],字串,連線到資料庫的密碼.
|
|
|
7922 |
$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbPassword"]=$conf["dbPassword"];
|
| 226 |
liveuser |
7923 |
|
| 3 |
liveuser |
7924 |
}#if end
|
| 226 |
liveuser |
7925 |
|
|
|
7926 |
#如果有設定 $conf["dbPort"]
|
| 3 |
liveuser |
7927 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
7928 |
|
| 3 |
liveuser |
7929 |
#設定 $conf["dbPort"]
|
|
|
7930 |
$conf["db.eraseDataInTableThenResetAutoIncrement"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
7931 |
|
|
|
7932 |
}#if end
|
|
|
7933 |
|
| 3 |
liveuser |
7934 |
#參考資料:
|
|
|
7935 |
#http://dev.mysql.com/doc/refman/5.0/en/alter-table.html
|
|
|
7936 |
#參考語法:
|
|
|
7937 |
#ALTER TABLE dbName.dtName AUTO_INCREMENT = 1;
|
|
|
7938 |
$eraseDataInTableThenResetAutoIncrementResult=db::eraseDataInTableThenResetAutoIncrement($conf["db.eraseDataInTableThenResetAutoIncrement"]);
|
|
|
7939 |
unset($conf["db.eraseDataInTableThenResetAutoIncrement"]);
|
| 226 |
liveuser |
7940 |
|
| 3 |
liveuser |
7941 |
#如果 透過一筆筆將資料表刪除後,重設識別欄位的自動增量欄位起始值為1 失敗
|
|
|
7942 |
if($eraseDataInTableThenResetAutoIncrementResult["status"]=="false"){
|
| 226 |
liveuser |
7943 |
|
| 3 |
liveuser |
7944 |
#設置錯誤識別
|
|
|
7945 |
$result["status"]="false";
|
| 226 |
liveuser |
7946 |
|
| 3 |
liveuser |
7947 |
#設置錯誤訊息
|
|
|
7948 |
$result["error"]=$eraseDataInTableThenResetAutoIncrementResult;
|
|
|
7949 |
|
|
|
7950 |
#回傳結果
|
|
|
7951 |
return $result;
|
| 226 |
liveuser |
7952 |
|
| 3 |
liveuser |
7953 |
}#if end
|
| 226 |
liveuser |
7954 |
|
|
|
7955 |
}#if end
|
|
|
7956 |
|
| 3 |
liveuser |
7957 |
#值行到這邊代表執行成功
|
|
|
7958 |
$result["status"]="true";
|
| 226 |
liveuser |
7959 |
|
| 3 |
liveuser |
7960 |
#回傳結果
|
|
|
7961 |
return $result;
|
| 226 |
liveuser |
7962 |
|
| 3 |
liveuser |
7963 |
}#function emptyTable end
|
|
|
7964 |
|
|
|
7965 |
/*
|
|
|
7966 |
#函式說明:
|
| 226 |
liveuser |
7967 |
#更改資料庫的名稱
|
| 3 |
liveuser |
7968 |
#回傳結果::
|
|
|
7969 |
#$result["status"],"true"代表執行成功
|
|
|
7970 |
#$result["function"],當前執行的函數名稱.
|
|
|
7971 |
#$result["error"],錯誤訊息陣列.
|
|
|
7972 |
#必填參數:
|
|
|
7973 |
#$conf["editedDatabaseName"],爲要更改的資料庫名稱.
|
|
|
7974 |
$conf["editedDatabaseName"]=$editedDbName;
|
|
|
7975 |
#$conf["newDatabaseName"],新的資料庫名稱
|
|
|
7976 |
$conf["newDatabaseName"]="";
|
|
|
7977 |
#$conf["dbAccount"],爲用於連入資料庫server時要使用的帳號
|
|
|
7978 |
$conf["dbAccount"]=$dbAccount;
|
|
|
7979 |
#$conf["dbAddress"],爲資料庫server的位置
|
|
|
7980 |
$conf["dbAddress"]=$dbAddress;
|
|
|
7981 |
#$conf["fileArgu"],字串,__FILE__的內容.
|
|
|
7982 |
$conf["fileArgu"]=__FILE__;
|
|
|
7983 |
#可省略參數:
|
|
|
7984 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
7985 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
7986 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
|
|
|
7987 |
#$conf["dbPort"]="3306";
|
|
|
7988 |
#參考資料:
|
|
|
7989 |
#http://stackoverflow.com/questions/1708651/how-can-i-change-case-of-database-name-in-mysql
|
|
|
7990 |
#備註:
|
|
|
7991 |
#無.
|
|
|
7992 |
*/
|
|
|
7993 |
public static function editDatabaseName($conf){
|
| 226 |
liveuser |
7994 |
|
| 3 |
liveuser |
7995 |
#初始化要回傳的內容
|
|
|
7996 |
$result=array();
|
|
|
7997 |
|
|
|
7998 |
#取得當前執行的函數名稱
|
|
|
7999 |
$result["function"]=__FUNCTION__;
|
|
|
8000 |
|
|
|
8001 |
#如果 $conf 不為陣列
|
|
|
8002 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
8003 |
|
| 3 |
liveuser |
8004 |
#設置執行失敗
|
|
|
8005 |
$result["status"]="false";
|
| 226 |
liveuser |
8006 |
|
| 3 |
liveuser |
8007 |
#設置執行錯誤訊息
|
|
|
8008 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
8009 |
|
|
|
8010 |
#如果傳入的參數為 null
|
|
|
8011 |
if($conf==null){
|
| 226 |
liveuser |
8012 |
|
| 3 |
liveuser |
8013 |
#設置執行錯誤訊息
|
|
|
8014 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
8015 |
|
| 3 |
liveuser |
8016 |
}#if end
|
|
|
8017 |
|
|
|
8018 |
#回傳結果
|
|
|
8019 |
return $result;
|
| 226 |
liveuser |
8020 |
|
| 3 |
liveuser |
8021 |
}#if end
|
| 226 |
liveuser |
8022 |
|
| 3 |
liveuser |
8023 |
#函式說明:
|
|
|
8024 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
8025 |
#回傳結果:
|
|
|
8026 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
8027 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
8028 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
8029 |
#必填參數:
|
|
|
8030 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
8031 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("fileArgu","editedDatabaseName","newDatabaseName","dbAccount","dbAddress");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
8032 |
#可省略參數:
|
| 226 |
liveuser |
8033 |
#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
8034 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
8035 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
8036 |
unset($conf["variableCheck"]["isexistMuti"]);
|
|
|
8037 |
|
|
|
8038 |
#如果檢查失敗
|
|
|
8039 |
if($checkResult["status"]=="false"){
|
|
|
8040 |
|
|
|
8041 |
#設置錯誤識別
|
|
|
8042 |
$result["status"]="false";
|
|
|
8043 |
|
|
|
8044 |
#設置錯誤訊息
|
|
|
8045 |
$result["error"]=$checkResult;
|
|
|
8046 |
|
|
|
8047 |
#回傳錯誤訊息
|
|
|
8048 |
return $result;
|
|
|
8049 |
|
|
|
8050 |
}#if end
|
|
|
8051 |
|
|
|
8052 |
#如果檢查不通過
|
|
|
8053 |
if($checkResult["passed"]=="false"){
|
|
|
8054 |
|
|
|
8055 |
#設置錯誤識別
|
|
|
8056 |
$result["status"]="false";
|
|
|
8057 |
|
|
|
8058 |
#設置錯誤訊息
|
|
|
8059 |
$result["error"]=$checkResult;
|
|
|
8060 |
|
|
|
8061 |
#回傳錯誤訊息
|
|
|
8062 |
return $result;
|
|
|
8063 |
|
|
|
8064 |
}#if end
|
| 226 |
liveuser |
8065 |
|
| 3 |
liveuser |
8066 |
#檢查要修改名稱的資料庫是否爲系統資料庫
|
|
|
8067 |
#函式說明:
|
|
|
8068 |
#檢查一個數值是否與陣列裏面的元素相同
|
|
|
8069 |
#回傳結果::
|
|
|
8070 |
#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
|
|
|
8071 |
#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
|
|
|
8072 |
#$result["error"],錯誤訊息
|
|
|
8073 |
#$result["function"],當前執行的函數名稱
|
|
|
8074 |
#$result["equalVarName"],相等的變數名稱或key.
|
|
|
8075 |
#$result["equalVarValue"],相等的變數數值內容.
|
|
|
8076 |
#必填參數:
|
|
|
8077 |
$conf["search"]["getEqualVar"]["conditionElement"]=$conf["editedDatabaseName"];#條件元素,要等於的元素內容。
|
|
|
8078 |
$conf["search"]["getEqualVar"]["compareElements"]=array("information_schema","mysql","performance_schema");#要比對的陣列變數內容。
|
|
|
8079 |
$searchResult=search::getEqualVar($conf["search"]["getEqualVar"]);
|
|
|
8080 |
unset($conf["search"]["getEqualVar"]);
|
|
|
8081 |
|
|
|
8082 |
#如果檢查失敗
|
|
|
8083 |
if($searchResult["status"]=="false"){
|
| 226 |
liveuser |
8084 |
|
| 3 |
liveuser |
8085 |
#設置錯誤識別
|
|
|
8086 |
$result["status"]="false";
|
| 226 |
liveuser |
8087 |
|
| 3 |
liveuser |
8088 |
#設置錯誤訊息
|
|
|
8089 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
8090 |
|
| 3 |
liveuser |
8091 |
#回傳結果
|
|
|
8092 |
return $result;
|
| 226 |
liveuser |
8093 |
|
| 3 |
liveuser |
8094 |
}#if end
|
|
|
8095 |
|
|
|
8096 |
#如果要移除的資料庫爲系統資料庫
|
|
|
8097 |
if($searchResult["founded"]=="true"){
|
| 226 |
liveuser |
8098 |
|
| 3 |
liveuser |
8099 |
#設置錯誤識別
|
|
|
8100 |
$result["status"]="false";
|
| 226 |
liveuser |
8101 |
|
| 3 |
liveuser |
8102 |
#設置錯誤訊息
|
|
|
8103 |
$result["error"][]="您不能更改系統資料庫";
|
| 226 |
liveuser |
8104 |
|
| 3 |
liveuser |
8105 |
#回傳結果
|
|
|
8106 |
return $result;
|
| 226 |
liveuser |
8107 |
|
| 3 |
liveuser |
8108 |
}#if end
|
| 226 |
liveuser |
8109 |
|
| 3 |
liveuser |
8110 |
#如果 $conf["dbPassword"] 不存在
|
|
|
8111 |
if(!isset($conf["dbPassword"])){
|
| 226 |
liveuser |
8112 |
|
| 3 |
liveuser |
8113 |
#設爲空值
|
|
|
8114 |
$conf["dbPassword"]="";
|
| 226 |
liveuser |
8115 |
|
| 3 |
liveuser |
8116 |
}#if end
|
| 226 |
liveuser |
8117 |
|
| 3 |
liveuser |
8118 |
#反之有設定
|
|
|
8119 |
else{
|
| 226 |
liveuser |
8120 |
|
| 3 |
liveuser |
8121 |
#設定連線用的密碼
|
|
|
8122 |
$formatedPassword="--password=".$conf["dbPassword"];
|
| 226 |
liveuser |
8123 |
|
| 3 |
liveuser |
8124 |
}#else end
|
| 226 |
liveuser |
8125 |
|
| 3 |
liveuser |
8126 |
#檢查新名字的資料庫是否存在
|
|
|
8127 |
#函式說明:
|
|
|
8128 |
#檢查該資料庫是否存在,結果會回傳一個陣列。
|
|
|
8129 |
#回傳結果:
|
|
|
8130 |
#$result["status"],執行正常則回傳"true",執行失敗則回傳"false".
|
|
|
8131 |
#$result["error"],錯誤訊息
|
|
|
8132 |
#$result["exist"],有為"true",無為"false".
|
|
|
8133 |
#必填的參數
|
|
|
8134 |
$conf["db"]["checkDataBaseExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
8135 |
$conf["db"]["checkDataBaseExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
8136 |
$conf["db"]["checkDataBaseExists"]["checkDataBaseName"]=$conf["newDatabaseName"];#爲要檢查是否存在的資料庫名稱
|
|
|
8137 |
#可省略參數
|
| 226 |
liveuser |
8138 |
|
| 3 |
liveuser |
8139 |
#如果 $conf["dbPassword"] 存在
|
|
|
8140 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
8141 |
|
| 3 |
liveuser |
8142 |
#設置密碼
|
|
|
8143 |
$conf["db"]["checkDataBaseExists"]["dbPassword"]=$conf["dbPassword"];
|
| 226 |
liveuser |
8144 |
|
| 3 |
liveuser |
8145 |
}#if end
|
| 226 |
liveuser |
8146 |
|
| 3 |
liveuser |
8147 |
#如果 $conf["dbPort"] 存在
|
|
|
8148 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
8149 |
|
| 3 |
liveuser |
8150 |
#設置密碼
|
|
|
8151 |
$conf["db"]["checkDataBaseExists"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
8152 |
|
|
|
8153 |
}#if end
|
|
|
8154 |
|
| 3 |
liveuser |
8155 |
$checkResult=db::checkDataBaseExists($conf["db"]["checkDataBaseExists"]);
|
|
|
8156 |
unset($conf["db"]["checkDataBaseExists"]);
|
| 226 |
liveuser |
8157 |
|
| 3 |
liveuser |
8158 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
8159 |
if($checkResult["status"]==="false"){
|
| 226 |
liveuser |
8160 |
|
| 3 |
liveuser |
8161 |
#設置錯誤識別
|
|
|
8162 |
$result["status"]="false";
|
| 226 |
liveuser |
8163 |
|
| 3 |
liveuser |
8164 |
#設置錯誤訊息
|
|
|
8165 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
8166 |
|
| 3 |
liveuser |
8167 |
#回傳結果
|
|
|
8168 |
return $result;
|
| 226 |
liveuser |
8169 |
|
| 3 |
liveuser |
8170 |
}#if end
|
| 226 |
liveuser |
8171 |
|
| 3 |
liveuser |
8172 |
#如果跟現有的資料庫名稱一樣
|
|
|
8173 |
if($checkResult["exist"]==="true"){
|
| 226 |
liveuser |
8174 |
|
| 3 |
liveuser |
8175 |
#設置錯誤訊息
|
|
|
8176 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
8177 |
|
| 3 |
liveuser |
8178 |
#設置錯誤識別
|
|
|
8179 |
$result["status"]="false";
|
| 226 |
liveuser |
8180 |
|
| 3 |
liveuser |
8181 |
#回傳結果
|
|
|
8182 |
return $result;
|
| 226 |
liveuser |
8183 |
|
| 3 |
liveuser |
8184 |
}#if end
|
| 226 |
liveuser |
8185 |
|
|
|
8186 |
#如果沒有跟現有的資料庫名稱一樣
|
| 3 |
liveuser |
8187 |
if($checkResult["exist"]==="false"){
|
| 226 |
liveuser |
8188 |
|
| 3 |
liveuser |
8189 |
#建立新的資料庫
|
|
|
8190 |
#函式說明:
|
|
|
8191 |
#建立資料庫,會回傳一個陣列。
|
|
|
8192 |
#回傳結果:
|
|
|
8193 |
#$result["status"],若成功則爲"true",失敗則爲"false".
|
| 226 |
liveuser |
8194 |
#$result["error"],錯誤訊息
|
| 3 |
liveuser |
8195 |
#必填參數:
|
|
|
8196 |
$conf["db"]["createDatabase"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
8197 |
$conf["db"]["createDatabase"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
8198 |
$conf["db"]["createDatabase"]["newDatabaseName"]=$conf["newDatabaseName"];#爲要新增的資料庫名稱
|
|
|
8199 |
#可省略參數:
|
| 226 |
liveuser |
8200 |
|
| 3 |
liveuser |
8201 |
#如果 $conf["dbPassword"] 存在
|
|
|
8202 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
8203 |
|
| 3 |
liveuser |
8204 |
#設置密碼
|
|
|
8205 |
$conf["db"]["createDatabase"]["dbPassword"]=$conf["dbPassword"];
|
| 226 |
liveuser |
8206 |
|
| 3 |
liveuser |
8207 |
}#if end
|
| 226 |
liveuser |
8208 |
|
| 3 |
liveuser |
8209 |
#如果 $conf["dbPort"] 存在
|
|
|
8210 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
8211 |
|
| 3 |
liveuser |
8212 |
#設置密碼
|
|
|
8213 |
$conf["db"]["createDatabase"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
8214 |
|
|
|
8215 |
}#if end
|
|
|
8216 |
|
| 3 |
liveuser |
8217 |
$createNewDbResult=db::createDatabase($conf["db"]["createDatabase"]);
|
|
|
8218 |
unset($conf["db"]["createDatabase"]);
|
| 226 |
liveuser |
8219 |
|
| 3 |
liveuser |
8220 |
#如果新資料庫建立失敗
|
|
|
8221 |
if($createNewDbResult["status"]=="false"){
|
| 226 |
liveuser |
8222 |
|
| 3 |
liveuser |
8223 |
#設置錯誤識別
|
|
|
8224 |
$result["status"]="false";
|
| 226 |
liveuser |
8225 |
|
| 3 |
liveuser |
8226 |
#設置錯誤訊息
|
|
|
8227 |
$result["error"]=$createNewDbResult;
|
| 226 |
liveuser |
8228 |
|
| 3 |
liveuser |
8229 |
#回傳結果
|
|
|
8230 |
return $result;
|
| 226 |
liveuser |
8231 |
|
| 3 |
liveuser |
8232 |
}#if end
|
| 226 |
liveuser |
8233 |
|
| 3 |
liveuser |
8234 |
#將舊的資料庫內容完整複製到新的資料庫
|
|
|
8235 |
#函式說明:
|
|
|
8236 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
8237 |
#回傳結果:
|
|
|
8238 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8239 |
#$result["error"],錯誤訊息陣列.
|
|
|
8240 |
#$result["function"],當前執行的函數名稱.
|
|
|
8241 |
#$result["argu"],使用的參數.
|
|
|
8242 |
#$result["cmd"],執行的指令內容.
|
|
|
8243 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
8244 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
8245 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
8246 |
#$result["running"],是否還在執行.
|
|
|
8247 |
#$result["pid"],pid.
|
|
|
8248 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
8249 |
#$result["escape"],陣列,儲存出新排序過且已經escape過的指令(key為"cmd")與參數(key為"argu").
|
|
|
8250 |
#必填參數:
|
|
|
8251 |
#$conf["command"],字串,要執行的指令.
|
|
|
8252 |
$conf["external::callShell"]["command"]="mysqldump";
|
|
|
8253 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
8254 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
|
|
8255 |
#可省略參數:
|
|
|
8256 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
8257 |
$conf["external::callShell"]["argu"]=array("-u".$conf["dbAccount"],$formatedPassword,$conf["editedDatabaseName"],"|","mysql","-u".$conf["dbAccount"],$formatedPassword,$conf["newDatabaseName"]);
|
|
|
8258 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
8259 |
#$conf["arguIsAddr"]=array();
|
|
|
8260 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
8261 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
8262 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
8263 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
8264 |
#$conf["enablePrintDescription"]="true";
|
|
|
8265 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
8266 |
#$conf["printDescription"]="";
|
|
|
8267 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".如果參數為"< 、<< 、> 、>> 、| 、2>&1"之一則不會過濾.
|
|
|
8268 |
#$conf["escapeshellarg"]="false";
|
|
|
8269 |
#$conf["thereIsShellVar"],陣列字串,指令搭配的參數"argu",若含有「\'」,則取代為「"」.每個argu參數都要有對應的元素."true"代表要置換.
|
|
|
8270 |
#$conf["thereIsShellVar"]=array();
|
|
|
8271 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
8272 |
#$conf["username"]="";
|
|
|
8273 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
8274 |
#$conf["password"]="";
|
|
|
8275 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
8276 |
#$conf["useScript"]="";
|
|
|
8277 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
8278 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
8279 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
8280 |
#$conf["inBackGround"]="";
|
|
|
8281 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
8282 |
#$conf["getErr"]="false";
|
|
|
8283 |
#$conf["doNotRun"],字串,"true"代表不執行指令,預設為"false"會執行指令.
|
|
|
8284 |
#$conf["doNotRun"]="false";
|
|
|
8285 |
#參考資料:
|
|
|
8286 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
8287 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
8288 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
8289 |
#備註:
|
|
|
8290 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
8291 |
#若使用的 command、argu 參數,含有 ~ 則會被視為字串,若有需要其於 shell 中代表的家目錄位置,可用 fileAccess::tildeToPath 來進行轉換.
|
|
|
8292 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
8293 |
unset($conf["external::callShell"]);
|
| 226 |
liveuser |
8294 |
|
| 3 |
liveuser |
8295 |
#若執行shell失敗
|
|
|
8296 |
if($callShell["status"]=="false"){
|
| 226 |
liveuser |
8297 |
|
| 3 |
liveuser |
8298 |
#設置錯誤識別
|
|
|
8299 |
$result["status"]="false";
|
| 226 |
liveuser |
8300 |
|
| 3 |
liveuser |
8301 |
#設置錯誤訊息
|
|
|
8302 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
8303 |
|
| 3 |
liveuser |
8304 |
#回傳結果
|
| 226 |
liveuser |
8305 |
return $result;
|
|
|
8306 |
|
| 3 |
liveuser |
8307 |
}#if end
|
| 226 |
liveuser |
8308 |
|
| 3 |
liveuser |
8309 |
#將舊的資料庫丟棄
|
|
|
8310 |
#函式說明:
|
|
|
8311 |
#移除資料庫,會回傳一個陣列。
|
|
|
8312 |
#回傳結果:
|
|
|
8313 |
#$result["status"],若成功則爲0,失敗則爲1。
|
|
|
8314 |
#$result["error"],錯誤訊息
|
|
|
8315 |
#必填參數:
|
|
|
8316 |
$conf["db"]["dropDatabase"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
8317 |
$conf["db"]["dropDatabase"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
8318 |
$conf["db"]["dropDatabase"]["dropedDatabaseName"]=$conf["editedDatabaseName"];#爲要移除的資料庫名稱
|
| 226 |
liveuser |
8319 |
#可省略參數:
|
|
|
8320 |
|
| 3 |
liveuser |
8321 |
#如果 $conf["dbPassword"] 存在
|
|
|
8322 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
8323 |
|
| 3 |
liveuser |
8324 |
#設置密碼
|
|
|
8325 |
$conf["db"]["dropDatabase"]["dbPassword"]=$conf["dbPassword"];
|
| 226 |
liveuser |
8326 |
|
| 3 |
liveuser |
8327 |
}#if end
|
| 226 |
liveuser |
8328 |
|
| 3 |
liveuser |
8329 |
#如果 $conf["dbPort"] 存在
|
|
|
8330 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
8331 |
|
| 3 |
liveuser |
8332 |
#設置密碼
|
|
|
8333 |
$conf["db"]["dropDatabase"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
8334 |
|
|
|
8335 |
}#if end
|
|
|
8336 |
|
| 3 |
liveuser |
8337 |
$dropDbResult=db::dropDatabase($conf["db"]["dropDatabase"]);
|
|
|
8338 |
unset($conf["db"]["dropDatabase"]);
|
| 226 |
liveuser |
8339 |
|
| 3 |
liveuser |
8340 |
#如果舊資料庫丟棄失敗
|
|
|
8341 |
if($dropDbResult["status"]=="false"){
|
| 226 |
liveuser |
8342 |
|
| 3 |
liveuser |
8343 |
#設置錯誤識別
|
|
|
8344 |
$result["status"]="false";
|
| 226 |
liveuser |
8345 |
|
| 3 |
liveuser |
8346 |
#設置錯誤訊息
|
|
|
8347 |
$result["error"][]="舊名稱資料庫丟棄失敗";
|
| 226 |
liveuser |
8348 |
|
| 3 |
liveuser |
8349 |
#回傳結果
|
|
|
8350 |
return $result;
|
| 226 |
liveuser |
8351 |
|
|
|
8352 |
}#if end
|
|
|
8353 |
|
| 3 |
liveuser |
8354 |
}#if end
|
| 226 |
liveuser |
8355 |
|
| 3 |
liveuser |
8356 |
#執行到這邊代表執行正確
|
|
|
8357 |
$result["status"]="true";
|
| 226 |
liveuser |
8358 |
|
| 3 |
liveuser |
8359 |
#回傳結果
|
|
|
8360 |
return $result;
|
| 226 |
liveuser |
8361 |
|
| 3 |
liveuser |
8362 |
}#function editDatabaseName
|
|
|
8363 |
|
|
|
8364 |
/*
|
|
|
8365 |
#函式說明:
|
| 226 |
liveuser |
8366 |
#更改資料表的名稱.
|
| 3 |
liveuser |
8367 |
#回傳結果:
|
|
|
8368 |
#$result["status"],"true"代表執行成功;若失敗會回傳錯誤訊息.
|
|
|
8369 |
#$resuly["function"],當前執行的函數名稱.
|
|
|
8370 |
#$result["error"],錯誤訊息.
|
|
|
8371 |
#$result["sql"],執行的sql字串.
|
|
|
8372 |
#必填參數:
|
|
|
8373 |
#$conf["editedDataBaseName"],爲要更改的資料表所屬的資料庫名稱.
|
|
|
8374 |
$conf["editedDataBaseName"]="";
|
|
|
8375 |
#$conf["editedDataTableName"],爲要更改的資料表原始名稱.
|
|
|
8376 |
$conf["editedDataTableName"]="";
|
|
|
8377 |
#$conf["newDataTableName"],新的資料庫名稱.
|
|
|
8378 |
$conf["newDataTableName"]="";
|
|
|
8379 |
#$conf["dbAccount"],爲用於連入資料庫server時要使用的帳號.
|
|
|
8380 |
$conf["dbAccount"]=$dbAccount;
|
|
|
8381 |
#conf["dbAddress"],爲資料庫server的位置.
|
|
|
8382 |
$conf["dbAddress"]=$dbAddress;
|
|
|
8383 |
#可省略參數:
|
|
|
8384 |
#$conf["dbPassword"],爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
8385 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
8386 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
|
|
|
8387 |
#$conf["dbPort"]="3306";
|
|
|
8388 |
#參考資料:
|
|
|
8389 |
#無.
|
|
|
8390 |
#備註:
|
|
|
8391 |
#無.
|
|
|
8392 |
*/
|
|
|
8393 |
public static function editDataTableName($conf){
|
| 226 |
liveuser |
8394 |
|
| 3 |
liveuser |
8395 |
#初始化要回傳的內容
|
|
|
8396 |
$result=array();
|
|
|
8397 |
|
|
|
8398 |
#取得當前執行的函數名稱
|
|
|
8399 |
$result["function"]=__FUNCTION__;
|
|
|
8400 |
|
|
|
8401 |
#如果 $conf 不為陣列
|
|
|
8402 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
8403 |
|
| 3 |
liveuser |
8404 |
#設置執行失敗
|
|
|
8405 |
$result["status"]="false";
|
| 226 |
liveuser |
8406 |
|
| 3 |
liveuser |
8407 |
#設置執行錯誤訊息
|
|
|
8408 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
8409 |
|
|
|
8410 |
#如果傳入的參數為 null
|
|
|
8411 |
if($conf==null){
|
| 226 |
liveuser |
8412 |
|
| 3 |
liveuser |
8413 |
#設置執行錯誤訊息
|
|
|
8414 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
8415 |
|
| 3 |
liveuser |
8416 |
}#if end
|
|
|
8417 |
|
|
|
8418 |
#回傳結果
|
|
|
8419 |
return $result;
|
| 226 |
liveuser |
8420 |
|
| 3 |
liveuser |
8421 |
}#if end
|
| 226 |
liveuser |
8422 |
|
| 3 |
liveuser |
8423 |
#函式說明:
|
|
|
8424 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
8425 |
#回傳結果:
|
|
|
8426 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
8427 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
8428 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
8429 |
#必填參數:
|
|
|
8430 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
8431 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("editedDataBaseName","editedDataTableName","newDataTableName","dbAccount","dbAddress");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
8432 |
#可省略參數:
|
| 226 |
liveuser |
8433 |
$conf["variableType"]=array("string","string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
8434 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
8435 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
8436 |
unset($conf["variableCheck"]["isexistMuti"]);
|
| 226 |
liveuser |
8437 |
|
| 3 |
liveuser |
8438 |
#如果 $checkResult["passed"]等於"false".
|
|
|
8439 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
8440 |
|
| 3 |
liveuser |
8441 |
#代表參數有錯
|
| 226 |
liveuser |
8442 |
|
| 3 |
liveuser |
8443 |
#設置錯誤識別
|
|
|
8444 |
$result["status"]="false";
|
| 226 |
liveuser |
8445 |
|
| 3 |
liveuser |
8446 |
#設置錯誤訊息
|
|
|
8447 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
8448 |
|
| 3 |
liveuser |
8449 |
#回傳結果
|
|
|
8450 |
return $result;
|
| 226 |
liveuser |
8451 |
|
| 3 |
liveuser |
8452 |
}#if end
|
| 226 |
liveuser |
8453 |
|
| 3 |
liveuser |
8454 |
#設定要執行的sql語法
|
|
|
8455 |
$sql="rename table ".$conf["editedDataBaseName"].".".$conf["editedDataTableName"]." to ".$conf["editedDataBaseName"].".".$conf["newDataTableName"].";";
|
| 226 |
liveuser |
8456 |
|
| 3 |
liveuser |
8457 |
#函式說明:
|
|
|
8458 |
#執行mysql指令
|
|
|
8459 |
#回傳結果::
|
|
|
8460 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
8461 |
#$result["error"],錯誤訊息的陣列
|
|
|
8462 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
8463 |
#$result["queryString"],mysql查詢的語言
|
|
|
8464 |
#查詢號的解果,需要解析。
|
|
|
8465 |
#必填參數:
|
|
|
8466 |
$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
8467 |
$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
8468 |
$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
|
| 226 |
liveuser |
8469 |
#可省略參數:
|
|
|
8470 |
|
| 3 |
liveuser |
8471 |
#如果 $conf["dbPassword"] 有設定
|
|
|
8472 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
8473 |
|
| 3 |
liveuser |
8474 |
$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
8475 |
|
| 3 |
liveuser |
8476 |
}#if end
|
| 226 |
liveuser |
8477 |
|
| 3 |
liveuser |
8478 |
#如果 $conf["dbPort"] 有設定
|
|
|
8479 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
8480 |
|
| 3 |
liveuser |
8481 |
$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port.
|
| 226 |
liveuser |
8482 |
|
|
|
8483 |
}#if end
|
|
|
8484 |
|
| 3 |
liveuser |
8485 |
$db["execMysqlQuery"]=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
|
|
|
8486 |
unset($conf["db"]["execMysqlQuery"]);
|
| 226 |
liveuser |
8487 |
|
| 3 |
liveuser |
8488 |
#如果 $db["execMysqlQuery"]["status"] 等於 "false".
|
|
|
8489 |
if($db["execMysqlQuery"]["status"]=="false"){
|
| 226 |
liveuser |
8490 |
|
| 3 |
liveuser |
8491 |
#設置執行錯誤的識別
|
|
|
8492 |
$result["status"]="false";
|
| 226 |
liveuser |
8493 |
|
| 3 |
liveuser |
8494 |
#設置錯誤訊息
|
|
|
8495 |
$result["error"]=$db["execMysqlQuery"]["error"];
|
| 226 |
liveuser |
8496 |
|
| 3 |
liveuser |
8497 |
#回傳結果
|
|
|
8498 |
return $result;
|
| 226 |
liveuser |
8499 |
|
| 3 |
liveuser |
8500 |
}#if end
|
| 226 |
liveuser |
8501 |
|
| 3 |
liveuser |
8502 |
#取得執行的sql語法
|
|
|
8503 |
$result["sql"]=$db["execMysqlQuery"]["queryString"];
|
| 226 |
liveuser |
8504 |
|
| 3 |
liveuser |
8505 |
#執行到這邊代表執行成功
|
|
|
8506 |
$result["status"]="true";
|
| 226 |
liveuser |
8507 |
|
| 3 |
liveuser |
8508 |
#回傳結果
|
|
|
8509 |
return $result;
|
| 226 |
liveuser |
8510 |
|
| 3 |
liveuser |
8511 |
}#function editDataTableName end
|
|
|
8512 |
|
|
|
8513 |
/*
|
|
|
8514 |
#函式說明:
|
|
|
8515 |
#移除資料庫,會回傳一個陣列。
|
|
|
8516 |
#回傳結果:
|
|
|
8517 |
#$result["status"],若成功則爲"true",失敗則爲,"false"
|
|
|
8518 |
#$result["error"],錯誤訊息.
|
|
|
8519 |
#$result["function"],當前執行的函數名稱.
|
|
|
8520 |
#必填參數:
|
|
|
8521 |
$conf["dbAddress"]=$dbAddress;#爲mysql-Server的位置
|
|
|
8522 |
$conf["dbAccount"]=$dbAccount;#爲用於連入mysql-Server時要使用的帳號
|
|
|
8523 |
$conf["dropedDatabaseName"]=$dbName;#爲要移除的資料庫名稱
|
| 226 |
liveuser |
8524 |
#可省略參數:
|
| 3 |
liveuser |
8525 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
8526 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
8527 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
|
|
|
8528 |
#$conf["dbPort"]="3306";
|
|
|
8529 |
#參考資料:
|
|
|
8530 |
#無.
|
|
|
8531 |
#備註:
|
|
|
8532 |
#無.
|
|
|
8533 |
*/
|
|
|
8534 |
public static function dropDatabase($conf){
|
|
|
8535 |
|
|
|
8536 |
#初始化要回傳的內容
|
|
|
8537 |
$result=array();
|
|
|
8538 |
|
|
|
8539 |
#取得當前執行的函數名稱
|
|
|
8540 |
$result["function"]=__FUNCTION__;
|
|
|
8541 |
|
|
|
8542 |
#如果 $conf 不為陣列
|
|
|
8543 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
8544 |
|
| 3 |
liveuser |
8545 |
#設置執行失敗
|
|
|
8546 |
$result["status"]="false";
|
| 226 |
liveuser |
8547 |
|
| 3 |
liveuser |
8548 |
#設置執行錯誤訊息
|
|
|
8549 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
8550 |
|
|
|
8551 |
#如果傳入的參數為 null
|
|
|
8552 |
if($conf==null){
|
| 226 |
liveuser |
8553 |
|
| 3 |
liveuser |
8554 |
#設置執行錯誤訊息
|
|
|
8555 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
8556 |
|
| 3 |
liveuser |
8557 |
}#if end
|
|
|
8558 |
|
|
|
8559 |
#回傳結果
|
|
|
8560 |
return $result;
|
| 226 |
liveuser |
8561 |
|
| 3 |
liveuser |
8562 |
}#if end
|
|
|
8563 |
|
|
|
8564 |
#函式說明:
|
|
|
8565 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
8566 |
#回傳結果:
|
|
|
8567 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
8568 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
8569 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
8570 |
#必填參數:
|
|
|
8571 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
8572 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","dropedDatabaseName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
8573 |
#可省略參數:
|
| 226 |
liveuser |
8574 |
$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
8575 |
#$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
8576 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
8577 |
unset($conf["variableCheck"]["isexistMuti"]);
|
|
|
8578 |
|
|
|
8579 |
#如果 $checkResult["passed"] 等於 "fasle"
|
|
|
8580 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
8581 |
|
| 3 |
liveuser |
8582 |
#設置錯誤識別
|
|
|
8583 |
$result["status"]="false";
|
| 226 |
liveuser |
8584 |
|
| 3 |
liveuser |
8585 |
#設置錯誤訊息
|
|
|
8586 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
8587 |
|
| 3 |
liveuser |
8588 |
#回傳結果
|
|
|
8589 |
return $result;
|
| 226 |
liveuser |
8590 |
|
| 3 |
liveuser |
8591 |
}#if end
|
|
|
8592 |
|
|
|
8593 |
#檢查要移除的資料庫爲系統資料庫
|
|
|
8594 |
#函式說明:
|
|
|
8595 |
#檢查一個數值是否與陣列裏面的元素相同
|
|
|
8596 |
#回傳結果::
|
|
|
8597 |
#$result["status"],"true"表示有找到相同的,"false"表示沒有找到相同的。
|
|
|
8598 |
#$result["equalVarName"],相等的變數內容。
|
|
|
8599 |
#$result["equalVarPosition"],相同的元素內容其位置爲該陣列元素的第幾個位置。
|
|
|
8600 |
#必填參數:
|
|
|
8601 |
$conf["search"]["getEqualVar"]["conditionElement"]=$conf["dropedDatabaseName"];#條件元素,要等於的元素內容。
|
|
|
8602 |
$conf["search"]["getEqualVar"]["compareElements"]=array("information_schema","mysql","performance_schema");#要比對的陣列變數內容。
|
|
|
8603 |
$searchResult=search::getEqualVar($conf["search"]["getEqualVar"]);
|
|
|
8604 |
unset($conf["search"]["getEqualVar"]);
|
|
|
8605 |
|
|
|
8606 |
#如果檢查失敗
|
|
|
8607 |
if($searchResult["status"]=="false"){
|
| 226 |
liveuser |
8608 |
|
| 3 |
liveuser |
8609 |
#設置失敗代碼
|
|
|
8610 |
$result["status"]="false";
|
| 226 |
liveuser |
8611 |
|
| 3 |
liveuser |
8612 |
#設置錯誤訊息
|
|
|
8613 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
8614 |
|
| 3 |
liveuser |
8615 |
#回傳結果
|
|
|
8616 |
return $result;
|
| 226 |
liveuser |
8617 |
|
| 3 |
liveuser |
8618 |
}#if end
|
|
|
8619 |
|
|
|
8620 |
#如果要移除的資料庫爲系統資料庫
|
|
|
8621 |
if($searchResult["founded"]=="true"){
|
| 226 |
liveuser |
8622 |
|
| 3 |
liveuser |
8623 |
#設置失敗代碼
|
|
|
8624 |
$result["status"]="false";
|
| 226 |
liveuser |
8625 |
|
| 3 |
liveuser |
8626 |
#設置錯誤訊息
|
|
|
8627 |
$result["error"]="您不能丟棄系統資料庫";
|
| 226 |
liveuser |
8628 |
|
| 3 |
liveuser |
8629 |
#回傳結果
|
|
|
8630 |
return $result;
|
| 226 |
liveuser |
8631 |
|
| 3 |
liveuser |
8632 |
}#if end
|
|
|
8633 |
|
|
|
8634 |
#丟棄資料庫的sql語法
|
|
|
8635 |
$sql="DROP DATABASE ".$conf["dropedDatabaseName"];
|
|
|
8636 |
|
|
|
8637 |
#執行sql語法
|
|
|
8638 |
#函式說明:
|
|
|
8639 |
#執行mysql指令
|
|
|
8640 |
#回傳結果::
|
|
|
8641 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
8642 |
#$result["error"],錯誤訊息的陣列
|
|
|
8643 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
8644 |
#$result["queryString"],mysql查詢的語言
|
|
|
8645 |
#查詢號的解果,需要解析。
|
|
|
8646 |
#必填參數:
|
|
|
8647 |
$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
8648 |
$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
8649 |
$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
|
| 226 |
liveuser |
8650 |
#可省略參數:
|
|
|
8651 |
|
| 3 |
liveuser |
8652 |
#如果 $conf["dbPassword"] 有設定
|
|
|
8653 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
8654 |
|
| 3 |
liveuser |
8655 |
$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
8656 |
|
| 3 |
liveuser |
8657 |
}#if end
|
| 226 |
liveuser |
8658 |
|
|
|
8659 |
|
| 3 |
liveuser |
8660 |
#如果 $conf["dbPort"] 有設定
|
|
|
8661 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
8662 |
|
| 3 |
liveuser |
8663 |
$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
8664 |
|
| 3 |
liveuser |
8665 |
}#if end
|
| 226 |
liveuser |
8666 |
|
| 3 |
liveuser |
8667 |
$db["execMysqlQuery"]=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
|
|
|
8668 |
unset($conf["db"]["execMysqlQuery"]);
|
|
|
8669 |
|
|
|
8670 |
#如果 $db["execMysqlQuery"]["status"] 等於 "false"
|
|
|
8671 |
if($db["execMysqlQuery"]["status"]=="false"){
|
| 226 |
liveuser |
8672 |
|
| 3 |
liveuser |
8673 |
#設置錯誤識別
|
|
|
8674 |
$result["status"]="false";
|
| 226 |
liveuser |
8675 |
|
| 3 |
liveuser |
8676 |
#設置錯誤訊息
|
|
|
8677 |
$result["error"]=$db["execMysqlQuery"];
|
| 226 |
liveuser |
8678 |
|
| 3 |
liveuser |
8679 |
#回傳結果
|
|
|
8680 |
return $result;
|
| 226 |
liveuser |
8681 |
|
| 3 |
liveuser |
8682 |
}#if end
|
|
|
8683 |
|
|
|
8684 |
#執行到這邊代表執行正常
|
|
|
8685 |
$result["status"]="true";
|
|
|
8686 |
|
|
|
8687 |
#回傳結果
|
|
|
8688 |
return $result;
|
|
|
8689 |
|
|
|
8690 |
}#function dropDatabase end
|
|
|
8691 |
|
|
|
8692 |
/*
|
|
|
8693 |
#函式說明:
|
|
|
8694 |
#備份資料庫
|
|
|
8695 |
#回傳結果::
|
|
|
8696 |
#$result["status"],"true"代表執行正常,"false"代表執行有誤.
|
|
|
8697 |
#$result["error"],錯誤訊息陣列.
|
|
|
8698 |
#$result["sqlAddress"],sql檔案的位置.
|
|
|
8699 |
#$result["function"],當前執行的函數名稱
|
|
|
8700 |
#必填參數:
|
|
|
8701 |
#$conf["backedDatabaseName"],字串.
|
|
|
8702 |
$conf["backedDatabaseName"]=$dbName;#爲要備份的資料庫名稱.
|
|
|
8703 |
#$conf["dbAddress"],字串,資料庫的位置.
|
|
|
8704 |
$conf["dbAddress"]=$dbAddress;
|
|
|
8705 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號.
|
|
|
8706 |
$conf["dbAccount"]=$dbAccount;
|
|
|
8707 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
8708 |
$conf["fileArgu"]=__FILE__;
|
|
|
8709 |
#可省略參數:
|
|
|
8710 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
8711 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
8712 |
#$conf["storePlace"],字串,要將輸出檔案儲存到哪邊,預設爲當前目錄.
|
|
|
8713 |
#$conf["storePlace"]="";
|
|
|
8714 |
#$conf["exportFileName"],字串,要輸出的檔案名稱,預設爲其export
|
|
|
8715 |
#$conf["exportFileName"]="export";
|
|
|
8716 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設不使用.
|
|
|
8717 |
#$conf["dbPort"]="3306";
|
|
|
8718 |
#參考資料:
|
|
|
8719 |
#無.
|
|
|
8720 |
#備註:
|
|
|
8721 |
#無.
|
|
|
8722 |
*/
|
|
|
8723 |
public static function backupDatabase($conf){
|
|
|
8724 |
|
|
|
8725 |
#原始語法
|
|
|
8726 |
# mysqldump --column-statistics=0 -u account --password=Password -Pport --default-character-set=utf8 --events --routines --single-transaction --skip-lock-tables --quick databaseName > "all.sql"
|
|
|
8727 |
|
|
|
8728 |
#初始化要回傳的變數
|
|
|
8729 |
$result=array();
|
| 226 |
liveuser |
8730 |
|
| 3 |
liveuser |
8731 |
#紀錄當前執行的函數名稱
|
|
|
8732 |
$result["function"]=__FUNCTION__;
|
|
|
8733 |
|
|
|
8734 |
#如果 $conf 不為陣列
|
|
|
8735 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
8736 |
|
| 3 |
liveuser |
8737 |
#設置執行失敗
|
|
|
8738 |
$result["status"]="false";
|
| 226 |
liveuser |
8739 |
|
| 3 |
liveuser |
8740 |
#設置執行錯誤訊息
|
|
|
8741 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
8742 |
|
|
|
8743 |
#如果傳入的參數為 null
|
|
|
8744 |
if($conf==null){
|
| 226 |
liveuser |
8745 |
|
| 3 |
liveuser |
8746 |
#設置執行錯誤訊息
|
|
|
8747 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
8748 |
|
| 3 |
liveuser |
8749 |
}#if end
|
|
|
8750 |
|
|
|
8751 |
#回傳結果
|
|
|
8752 |
return $result;
|
| 226 |
liveuser |
8753 |
|
| 3 |
liveuser |
8754 |
}#if end
|
|
|
8755 |
|
|
|
8756 |
#函式說明:
|
|
|
8757 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
8758 |
#回傳結果:
|
|
|
8759 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
8760 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
8761 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
8762 |
#必填參數:
|
|
|
8763 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
8764 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("fileArgu","backedDatabaseName","dbAccount","dbAddress");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
8765 |
#可省略參數:
|
| 226 |
liveuser |
8766 |
$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
8767 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
8768 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
8769 |
unset($conf["variableCheck"]["isexistMuti"]);
|
|
|
8770 |
|
|
|
8771 |
#如果檢查失敗
|
|
|
8772 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
8773 |
|
| 3 |
liveuser |
8774 |
#設置錯誤識別
|
|
|
8775 |
$result["status"]="false";
|
| 226 |
liveuser |
8776 |
|
| 3 |
liveuser |
8777 |
#設置錯誤訊息
|
|
|
8778 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
8779 |
|
| 3 |
liveuser |
8780 |
#回傳錯誤訊息
|
|
|
8781 |
return $result;
|
| 226 |
liveuser |
8782 |
|
| 3 |
liveuser |
8783 |
}#if end
|
|
|
8784 |
|
|
|
8785 |
#如果檢查不通過
|
|
|
8786 |
if($checkResult["passed"]=="false"){
|
|
|
8787 |
|
|
|
8788 |
#設置錯誤識別
|
|
|
8789 |
$result["status"]="false";
|
| 226 |
liveuser |
8790 |
|
| 3 |
liveuser |
8791 |
#設置錯誤訊息
|
|
|
8792 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
8793 |
|
| 3 |
liveuser |
8794 |
#回傳錯誤訊息
|
|
|
8795 |
return $result;
|
|
|
8796 |
|
|
|
8797 |
}#if end
|
| 226 |
liveuser |
8798 |
|
| 3 |
liveuser |
8799 |
#檢查要備份的資料庫是否爲系統資料庫
|
|
|
8800 |
#函式說明:
|
|
|
8801 |
#檢查一個數值是否與陣列裏面的元素相同
|
|
|
8802 |
#回傳結果::
|
|
|
8803 |
#$result["status"],"true"表示有找到相同的,"false"表示沒有找到相同的。
|
|
|
8804 |
#$result["error"],錯誤訊息
|
|
|
8805 |
#$result["equalVarName"],相等的變數內容。
|
|
|
8806 |
#$result["equalVarPosition"],相同的元素內容其位置爲該陣列元素的第幾個位置。
|
|
|
8807 |
#必填參數:
|
|
|
8808 |
$conf["search"]["getEqualVar"]["conditionElement"]=$conf["backedDatabaseName"];#條件元素,要等於的元素內容。
|
|
|
8809 |
$conf["search"]["getEqualVar"]["compareElements"]=array("information_schema","mysql","performance_schema");#要比對的陣列變數內容。
|
|
|
8810 |
$searchResult=search::getEqualVar($conf["search"]["getEqualVar"]);
|
|
|
8811 |
unset($conf["search"]["getEqualVar"]);
|
|
|
8812 |
|
|
|
8813 |
#如果檢查失敗
|
|
|
8814 |
if($searchResult["status"]=="false"){
|
| 226 |
liveuser |
8815 |
|
| 3 |
liveuser |
8816 |
#設置錯誤識別
|
|
|
8817 |
$result["status"]="false";
|
| 226 |
liveuser |
8818 |
|
| 3 |
liveuser |
8819 |
#設置錯誤訊息
|
|
|
8820 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
8821 |
|
| 3 |
liveuser |
8822 |
#回傳結果
|
|
|
8823 |
return $result;
|
| 226 |
liveuser |
8824 |
|
| 3 |
liveuser |
8825 |
}#if end
|
| 226 |
liveuser |
8826 |
|
| 3 |
liveuser |
8827 |
#如果要備份的資料庫爲系統資料庫
|
|
|
8828 |
if($searchResult["founded"]=="true"){
|
| 226 |
liveuser |
8829 |
|
| 3 |
liveuser |
8830 |
#設置錯誤識別
|
|
|
8831 |
$result["status"]="false";
|
| 226 |
liveuser |
8832 |
|
| 3 |
liveuser |
8833 |
#設置錯誤訊息
|
|
|
8834 |
$result["error"]="您不能備份系統資料庫";
|
| 226 |
liveuser |
8835 |
|
| 3 |
liveuser |
8836 |
#回傳結果
|
|
|
8837 |
return $result;
|
| 226 |
liveuser |
8838 |
|
| 3 |
liveuser |
8839 |
}#if end
|
|
|
8840 |
|
|
|
8841 |
#初始化連線的密碼
|
|
|
8842 |
$dbPassword="";
|
| 226 |
liveuser |
8843 |
|
| 3 |
liveuser |
8844 |
#如果 $conf["dbPassword"] 有設置
|
|
|
8845 |
if(isset($conf["dbPassword"])){
|
|
|
8846 |
|
|
|
8847 |
#令存密碼
|
|
|
8848 |
$dbPassword=$conf["dbPassword"];
|
|
|
8849 |
|
|
|
8850 |
#設置其連線密碼
|
|
|
8851 |
$conf["dbPassword"]="-p".$conf["dbPassword"];
|
|
|
8852 |
|
|
|
8853 |
}#if end
|
|
|
8854 |
|
|
|
8855 |
#反之
|
|
|
8856 |
else{
|
|
|
8857 |
|
|
|
8858 |
#設爲空值
|
|
|
8859 |
$conf["dbPassword"]="";
|
|
|
8860 |
|
|
|
8861 |
}#else end
|
| 226 |
liveuser |
8862 |
|
| 3 |
liveuser |
8863 |
#如果 $conf["storePlace"] 沒有設置
|
|
|
8864 |
if(!isset($conf["storePlace"])){
|
|
|
8865 |
|
|
|
8866 |
#將其設爲空值
|
|
|
8867 |
$conf["storePlace"]="";
|
|
|
8868 |
|
|
|
8869 |
}#if end
|
| 226 |
liveuser |
8870 |
|
| 3 |
liveuser |
8871 |
#反之有設定且結尾不為 "/"
|
|
|
8872 |
else if($conf["storePlace"][strlen($conf["storePlace"])-1]!=="/"){
|
| 226 |
liveuser |
8873 |
|
| 3 |
liveuser |
8874 |
#在其路徑後方加上 /
|
|
|
8875 |
$conf["storePlace"]=$conf["storePlace"]."/";
|
|
|
8876 |
|
|
|
8877 |
}#if end
|
|
|
8878 |
|
|
|
8879 |
#如果 $conf["exportFileName"] 沒有設置
|
|
|
8880 |
if(!isset($conf["exportFileName"])){
|
|
|
8881 |
|
|
|
8882 |
#設置預設名稱
|
|
|
8883 |
$conf["exportFileName"]="export.sql";
|
|
|
8884 |
|
|
|
8885 |
}#if end
|
|
|
8886 |
|
|
|
8887 |
#反之有設定
|
|
|
8888 |
else{
|
|
|
8889 |
|
|
|
8890 |
#名稱結尾加上 .sql
|
|
|
8891 |
$conf["exportFileName"]=$conf["exportFileName"].".sql";
|
|
|
8892 |
|
|
|
8893 |
}#else end
|
|
|
8894 |
|
|
|
8895 |
#檢查資料庫是否存在
|
|
|
8896 |
#函式說明:
|
|
|
8897 |
#檢查該資料庫是否存在,結果會回傳一個陣列。
|
|
|
8898 |
#回傳結果:
|
|
|
8899 |
#$result["status"],設置執行錯誤.
|
|
|
8900 |
#$result["error"],錯誤訊息.
|
|
|
8901 |
#$result["exist"],有為"true",無為"false".
|
|
|
8902 |
#$result["function"],當前執行的函數名稱.
|
|
|
8903 |
#必填的參數
|
|
|
8904 |
$conf["db::checkDataBaseExists"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
8905 |
$conf["db::checkDataBaseExists"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
8906 |
$conf["db::checkDataBaseExists"]["checkDataBaseName"]=$conf["backedDatabaseName"];#爲要檢查是否存在的資料庫名稱
|
|
|
8907 |
#可省略參數
|
| 226 |
liveuser |
8908 |
|
| 3 |
liveuser |
8909 |
#如果密碼不為""
|
|
|
8910 |
if($dbPassword!=""){
|
| 226 |
liveuser |
8911 |
|
| 3 |
liveuser |
8912 |
$conf["db::checkDataBaseExists"]["dbPassword"]=$dbPassword;#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
8913 |
|
| 3 |
liveuser |
8914 |
}#if end
|
| 226 |
liveuser |
8915 |
|
| 3 |
liveuser |
8916 |
#如果有設置 $conf["dnPort"]
|
|
|
8917 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
8918 |
|
| 3 |
liveuser |
8919 |
$conf["db::checkDataBaseExists"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
8920 |
|
| 3 |
liveuser |
8921 |
}#if end
|
| 226 |
liveuser |
8922 |
|
| 3 |
liveuser |
8923 |
$checkDataBaseExists=db::checkDataBaseExists($conf["db::checkDataBaseExists"]);
|
|
|
8924 |
unset($conf["db::checkDataBaseExists"]);
|
|
|
8925 |
|
|
|
8926 |
#如果檢查資料庫是否存在失敗
|
|
|
8927 |
if($checkDataBaseExists["status"]=="false"){
|
| 226 |
liveuser |
8928 |
|
| 3 |
liveuser |
8929 |
#設置錯誤識別
|
|
|
8930 |
$result["status"]="false";
|
| 226 |
liveuser |
8931 |
|
| 3 |
liveuser |
8932 |
#設置錯誤訊息
|
|
|
8933 |
$result["error"]=$checkDataBaseExists;
|
| 226 |
liveuser |
8934 |
|
| 3 |
liveuser |
8935 |
#回傳結果
|
|
|
8936 |
return $result;
|
| 226 |
liveuser |
8937 |
|
| 3 |
liveuser |
8938 |
}#if end
|
| 226 |
liveuser |
8939 |
|
| 3 |
liveuser |
8940 |
#如果資料庫不存在
|
|
|
8941 |
if($checkDataBaseExists["exist"]=="false"){
|
| 226 |
liveuser |
8942 |
|
| 3 |
liveuser |
8943 |
#設置錯誤識別
|
|
|
8944 |
$result["status"]="false";
|
| 226 |
liveuser |
8945 |
|
| 3 |
liveuser |
8946 |
#設置錯誤訊息
|
|
|
8947 |
$result["error"]=$checkDataBaseExists;
|
| 226 |
liveuser |
8948 |
|
| 3 |
liveuser |
8949 |
#回傳結果
|
|
|
8950 |
return $result;
|
| 226 |
liveuser |
8951 |
|
| 3 |
liveuser |
8952 |
}#if end
|
|
|
8953 |
|
|
|
8954 |
#若有設置port
|
|
|
8955 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
8956 |
|
| 3 |
liveuser |
8957 |
#指定port
|
|
|
8958 |
$port="-P".$conf["dbPort"];
|
| 226 |
liveuser |
8959 |
|
| 3 |
liveuser |
8960 |
}#if end
|
| 226 |
liveuser |
8961 |
|
| 3 |
liveuser |
8962 |
#反之
|
|
|
8963 |
else{
|
|
|
8964 |
#設置為空
|
|
|
8965 |
$port="";
|
| 226 |
liveuser |
8966 |
|
| 3 |
liveuser |
8967 |
}#else end
|
|
|
8968 |
|
|
|
8969 |
#透過以下指令判斷是否支援 --column-statistics 參數
|
|
|
8970 |
#mysqldump --help | grep "\--column-statistics" | wc -l
|
|
|
8971 |
#函式說明:
|
|
|
8972 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
8973 |
#回傳結果:
|
|
|
8974 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
8975 |
#$result["error"],錯誤訊息陣列.
|
|
|
8976 |
#$result["function"],當前執行的函數名稱.
|
|
|
8977 |
#$result["argu"],使用的參數.
|
|
|
8978 |
#$result["cmd"],執行的指令內容.
|
|
|
8979 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
8980 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
8981 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
8982 |
#$result["running"],是否還在執行.
|
|
|
8983 |
#$result["pid"],pid.
|
|
|
8984 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
8985 |
#必填參數:
|
|
|
8986 |
#$conf["command"],字串,要執行的指令與.
|
|
|
8987 |
$conf["external::callShell"]["command"]="mysqldump";
|
|
|
8988 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
8989 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
|
|
8990 |
#可省略參數:
|
|
|
8991 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
8992 |
$conf["external::callShell"]["argu"]=array("--help","|","grep","\--column-statistics","|","wc","-l");
|
|
|
8993 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
8994 |
#$conf["arguIsAddr"]=array();
|
|
|
8995 |
#$conf["plainArgu"],字串陣列,哪幾個參數不要加上"".
|
|
|
8996 |
#$conf["external::callShell"]["plainArgu"]=array("true","true","true","false","true","true","true");
|
|
|
8997 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
8998 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
8999 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
9000 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
9001 |
#$conf["enablePrintDescription"]="true";
|
|
|
9002 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
9003 |
#$conf["printDescription"]="";
|
|
|
9004 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
9005 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
9006 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
9007 |
#$conf["username"]="";
|
|
|
9008 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
9009 |
#$conf["password"]="";
|
|
|
9010 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
9011 |
#$conf["useScript"]="";
|
|
|
9012 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
9013 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
9014 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
9015 |
#$conf["inBackGround"]="";
|
|
|
9016 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
9017 |
#$conf["getErr"]="false";
|
|
|
9018 |
#備註:
|
|
|
9019 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
9020 |
#參考資料:
|
|
|
9021 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
9022 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
9023 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
9024 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
9025 |
unset($conf["external::callShell"]);
|
| 226 |
liveuser |
9026 |
|
| 3 |
liveuser |
9027 |
#如果執行shell失敗
|
|
|
9028 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
9029 |
|
| 3 |
liveuser |
9030 |
#設置錯誤識別
|
|
|
9031 |
$result["status"]="false";
|
| 226 |
liveuser |
9032 |
|
| 3 |
liveuser |
9033 |
#設置錯誤訊息
|
|
|
9034 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
9035 |
|
| 3 |
liveuser |
9036 |
#回傳結果
|
|
|
9037 |
return $result;
|
| 226 |
liveuser |
9038 |
|
| 3 |
liveuser |
9039 |
}#if end
|
|
|
9040 |
|
|
|
9041 |
#初始化參數
|
|
|
9042 |
$conf["external::callShell"]["argu"]=array();
|
|
|
9043 |
|
|
|
9044 |
#如果支援 --column-statistics 參數
|
|
|
9045 |
if($callShell["output"][0]==="1"){
|
| 226 |
liveuser |
9046 |
|
| 3 |
liveuser |
9047 |
#增加參數
|
|
|
9048 |
$conf["external::callShell"]["argu"][]="--column-statistics=0";
|
| 226 |
liveuser |
9049 |
|
| 3 |
liveuser |
9050 |
}#if end
|
|
|
9051 |
|
| 226 |
liveuser |
9052 |
#輸出資料庫sql檔案
|
| 3 |
liveuser |
9053 |
#函式說明:
|
|
|
9054 |
#呼叫shell執行系統命令,並取得回傳的內容.
|
|
|
9055 |
#回傳結果:
|
|
|
9056 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
9057 |
#$result["error"],錯誤訊息陣列.
|
|
|
9058 |
#$result["function"],當前執行的函數名稱.
|
|
|
9059 |
#$result["argu"],使用的參數.
|
|
|
9060 |
#$result["cmd"],執行的指令內容.
|
|
|
9061 |
#$result["fullCmd"],如果參數 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
9062 |
#$result["output"],爲執行完二元碼後的輸出陣列,若 $conf["inBackGround"] 為 "true",則為當下的輸出.
|
|
|
9063 |
#$result["tmpFileOutput"],儲存輸出的暫存檔案名稱,若 $conf["inBackGround"] 為 "true" 則會回傳該值.
|
|
|
9064 |
#$result["running"],是否還在執行.
|
|
|
9065 |
#$result["pid"],pid.
|
|
|
9066 |
#$result["statusCode"],執行結束後的代碼.
|
|
|
9067 |
#必填參數:
|
|
|
9068 |
#$conf["command"],字串,要執行的指令與.
|
|
|
9069 |
$conf["external::callShell"]["command"]="mysqldump";
|
|
|
9070 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
9071 |
$conf["external::callShell"]["fileArgu"]=$conf["fileArgu"];
|
|
|
9072 |
#可省略參數:
|
|
|
9073 |
#$conf["argu"],陣列字串,指令搭配的參數,預設為空陣列.
|
|
|
9074 |
$conf["external::callShell"]["argu"][]="-u";
|
|
|
9075 |
$conf["external::callShell"]["argu"][]=$conf["dbAccount"];
|
|
|
9076 |
$conf["external::callShell"]["argu"][]=$conf["dbPassword"];
|
|
|
9077 |
$conf["external::callShell"]["argu"][]="-h";
|
|
|
9078 |
$conf["external::callShell"]["argu"][]=$conf["dbAddress"];
|
| 226 |
liveuser |
9079 |
|
| 3 |
liveuser |
9080 |
#如果有指定 port
|
|
|
9081 |
if($port!==""){
|
| 226 |
liveuser |
9082 |
|
| 3 |
liveuser |
9083 |
#設置port
|
|
|
9084 |
$conf["external::callShell"]["argu"][]=$port;
|
| 226 |
liveuser |
9085 |
|
| 3 |
liveuser |
9086 |
}#if end
|
|
|
9087 |
|
|
|
9088 |
$conf["external::callShell"]["argu"][]="--default-character-set=utf8";
|
|
|
9089 |
$conf["external::callShell"]["argu"][]="--events";
|
|
|
9090 |
$conf["external::callShell"]["argu"][]="--routines";
|
|
|
9091 |
$conf["external::callShell"]["argu"][]="--single-transaction";
|
|
|
9092 |
$conf["external::callShell"]["argu"][]="--skip-lock-tables";
|
|
|
9093 |
$conf["external::callShell"]["argu"][]="--quick";
|
|
|
9094 |
$conf["external::callShell"]["argu"][]=$conf["backedDatabaseName"];
|
|
|
9095 |
$conf["external::callShell"]["argu"][]=">";
|
|
|
9096 |
$conf["external::callShell"]["argu"][]=$conf["storePlace"].$conf["exportFileName"];
|
|
|
9097 |
#$conf["arguIsAddr"],陣列字串,指令搭配的哪些參數為路徑,為路徑的參數會進行轉換以便符合呼叫當前函數的位置,預設不指定,若有3個參數,其中第3個參數為路徑,則表示為array("false","false","true").
|
|
|
9098 |
#$conf["arguIsAddr"]=array();
|
|
|
9099 |
#$conf["pre"],陣列,要在本指令前執行的每個指令與參數.
|
|
|
9100 |
#$conf["pre"][$i]["cmd"],字串,要在本指令前執行的第$i+1個指令.
|
|
|
9101 |
#$conf["pre"][$i]["param"],陣列字串,要在本指令前執行的第$i+1個指令的參數.
|
|
|
9102 |
#$conf["enablePrintDescription"],字串,是否要印出$conf["printDescription"]的內容,"true"代表要,"false"代表不要,預設為"false".
|
|
|
9103 |
#$conf["enablePrintDescription"]="true";
|
|
|
9104 |
#$conf["printDescription"],字串,執行該外部程式前要印出來的的文字,預設為$conf["command"]的內容加上使用的$conf["argu"]參數.
|
|
|
9105 |
#$conf["printDescription"]="";
|
|
|
9106 |
#$conf["escapeshellarg"],字串,是否要啟用過濾參數,用了比較安全,但可能會出錯,"true"為啟用,"false"為不啟用,預設為"false".
|
|
|
9107 |
$conf["external::callShell"]["escapeshellarg"]="true";
|
|
|
9108 |
#$conf["username"],字串,要用什麼使用者來執行,預設為執行php的使用者,該參數不適用於apache環境.
|
|
|
9109 |
#$conf["username"]="";
|
|
|
9110 |
#$conf["password"],字串,root的使用者密碼,預設不使用密碼,該參數不適用於apache環境.
|
|
|
9111 |
#$conf["password"]="";
|
|
|
9112 |
#$conf["useScript"],字串,是否要啟用Linux的script指令來記錄輸出,"true"代表要,Fedora的selinux會擋住該操作;"false"代表不要,預設為"false".
|
|
|
9113 |
#$conf["useScript"]="";
|
|
|
9114 |
#$conf["logFilePath"],字串,當 $conf["useScript"] 為 "true" 時,輸出的內容要暫存到哪裡,預設為 "/tmp/.qbpwcf_tmp/external/callShell/".
|
|
|
9115 |
#$conf["logFilePath"]=".qbpwcf_tmp/external/callShell/";
|
|
|
9116 |
#$conf["inBackGround"],字串,是否要在背景執行,且不會等待程式執行結束再執行下一個指令,"true"代表是,"false"代表不要,預設為"false",如果$conf["command"]有用「;」區隔的多個指令將會出錯.
|
|
|
9117 |
#$conf["inBackGround"]="";
|
|
|
9118 |
#$conf["getErr"],字串,"true"代表將錯誤輸出變成標準輸出,反之"false"為不變動.
|
|
|
9119 |
#$conf["getErr"]="false";
|
|
|
9120 |
#備註:
|
|
|
9121 |
#不是所有指令都能用apache的身份執行,目前已知java,javac指令無法執行,使用root身份可能會被selinux阻擋.
|
|
|
9122 |
#參考資料:
|
|
|
9123 |
#exec=>http://php.net/manual/en/function.exec.php
|
|
|
9124 |
#escapeshellcmd=>http://php.net/manual/en/function.escapeshellcmd.php
|
|
|
9125 |
#escapeshellarg=>http://php.net/manual/en/function.escapeshellarg.php
|
|
|
9126 |
$callShell=external::callShell($conf["external::callShell"]);
|
|
|
9127 |
unset($conf["external::callShell"]);
|
| 226 |
liveuser |
9128 |
|
| 3 |
liveuser |
9129 |
#如果執行shell失敗
|
|
|
9130 |
if($callShell["status"]==="false"){
|
| 226 |
liveuser |
9131 |
|
| 3 |
liveuser |
9132 |
#設置錯誤識別
|
|
|
9133 |
$result["status"]="false";
|
| 226 |
liveuser |
9134 |
|
| 3 |
liveuser |
9135 |
#設置錯誤訊息
|
|
|
9136 |
$result["error"]=$callShell;
|
| 226 |
liveuser |
9137 |
|
| 3 |
liveuser |
9138 |
#回傳結果
|
|
|
9139 |
return $result;
|
| 226 |
liveuser |
9140 |
|
| 3 |
liveuser |
9141 |
}#if end
|
|
|
9142 |
|
|
|
9143 |
#設置產生的sql檔案位置
|
|
|
9144 |
$result["sqlAddress"]=$conf["storePlace"].$conf["exportFileName"];
|
|
|
9145 |
|
|
|
9146 |
#設置執行成功
|
|
|
9147 |
$result["status"]="true";
|
| 226 |
liveuser |
9148 |
|
| 3 |
liveuser |
9149 |
#回傳結果
|
|
|
9150 |
return $result;
|
|
|
9151 |
|
|
|
9152 |
}#function backupDatabase end
|
| 226 |
liveuser |
9153 |
|
| 3 |
liveuser |
9154 |
/*
|
|
|
9155 |
#函式說明:
|
|
|
9156 |
#移除表,會回傳一個陣列。
|
|
|
9157 |
#回傳結果:
|
|
|
9158 |
#$result["status"],若成功則爲"true",失敗則爲,"false"
|
|
|
9159 |
#$result["error"],錯誤訊息.
|
|
|
9160 |
#$result["function"],當前執行的函數名稱.
|
|
|
9161 |
#必填參數:
|
|
|
9162 |
$conf["dbAddress"],字串,爲mysql-Server的位置
|
|
|
9163 |
$conf["dbAddress"]=$dbAddress;
|
|
|
9164 |
$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
|
|
|
9165 |
$conf["dbAccount"]=$dbAccount;
|
|
|
9166 |
$conf["selectedDatabaseName"],字串,爲要移除的資料表位於哪個資料庫
|
|
|
9167 |
$conf["selectedDatabaseName"]=$dbName;
|
|
|
9168 |
$conf["dropedDataTableName"],字串,爲要移除的資料表名稱
|
|
|
9169 |
$conf["dropedDataTableName"]=$tableName;#爲要移除的資料表名稱
|
| 226 |
liveuser |
9170 |
#可省略參數:
|
| 3 |
liveuser |
9171 |
#$conf["dbPassword"],字串.爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
9172 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
9173 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
|
|
|
9174 |
#$conf["dbPort"]="3306";
|
|
|
9175 |
#參考資料:
|
|
|
9176 |
#無.
|
|
|
9177 |
#備註:
|
|
|
9178 |
#無.
|
|
|
9179 |
*/
|
|
|
9180 |
public static function dropDataTable($conf){
|
|
|
9181 |
|
|
|
9182 |
#初始化要回傳的內容
|
|
|
9183 |
$result=array();
|
|
|
9184 |
|
|
|
9185 |
#取得當前執行的函數名稱
|
|
|
9186 |
$result["function"]=__FUNCTION__;
|
|
|
9187 |
|
|
|
9188 |
#如果 $conf 不為陣列
|
|
|
9189 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
9190 |
|
| 3 |
liveuser |
9191 |
#設置執行失敗
|
|
|
9192 |
$result["status"]="false";
|
| 226 |
liveuser |
9193 |
|
| 3 |
liveuser |
9194 |
#設置執行錯誤訊息
|
|
|
9195 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
9196 |
|
|
|
9197 |
#如果傳入的參數為 null
|
|
|
9198 |
if($conf==null){
|
| 226 |
liveuser |
9199 |
|
| 3 |
liveuser |
9200 |
#設置執行錯誤訊息
|
|
|
9201 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
9202 |
|
| 3 |
liveuser |
9203 |
}#if end
|
|
|
9204 |
|
|
|
9205 |
#回傳結果
|
|
|
9206 |
return $result;
|
| 226 |
liveuser |
9207 |
|
| 3 |
liveuser |
9208 |
}#if end
|
|
|
9209 |
|
|
|
9210 |
#函式說明:
|
|
|
9211 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
9212 |
#回傳結果:
|
|
|
9213 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
9214 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
9215 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
9216 |
#必填參數:
|
|
|
9217 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
9218 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDatabaseName","dropedDataTableName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
9219 |
#可省略參數:
|
| 226 |
liveuser |
9220 |
$conf["variableType"]=array("string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
9221 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
9222 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
9223 |
unset($conf["variableCheck"]["isexistMuti"]);
|
|
|
9224 |
|
|
|
9225 |
#如果檢查不正常
|
|
|
9226 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
9227 |
|
| 3 |
liveuser |
9228 |
#設置執行錯誤
|
|
|
9229 |
$result["status"]="fasle";
|
| 226 |
liveuser |
9230 |
|
| 3 |
liveuser |
9231 |
#設置錯誤訊息
|
|
|
9232 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
9233 |
|
| 3 |
liveuser |
9234 |
#回傳結果:
|
|
|
9235 |
return $result;
|
| 226 |
liveuser |
9236 |
|
| 3 |
liveuser |
9237 |
}#if end
|
|
|
9238 |
|
|
|
9239 |
#如果檢查不通過
|
|
|
9240 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
9241 |
|
| 3 |
liveuser |
9242 |
#設置執行錯誤
|
|
|
9243 |
$result["status"]="fasle";
|
| 226 |
liveuser |
9244 |
|
| 3 |
liveuser |
9245 |
#設置錯誤訊息
|
|
|
9246 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
9247 |
|
| 3 |
liveuser |
9248 |
#回傳結果:
|
|
|
9249 |
return $result;
|
| 226 |
liveuser |
9250 |
|
| 3 |
liveuser |
9251 |
}#if end
|
| 226 |
liveuser |
9252 |
|
| 3 |
liveuser |
9253 |
#建立移除資料表的sql語言
|
|
|
9254 |
$sql="drop table ".$conf["selectedDatabaseName"].".".$conf["dropedDataTableName"].";";
|
| 226 |
liveuser |
9255 |
|
| 3 |
liveuser |
9256 |
#函式說明:
|
|
|
9257 |
#執行mysql查詢的指令
|
|
|
9258 |
#回傳結果::
|
|
|
9259 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
9260 |
#$result["error"],錯誤訊息的陣列
|
|
|
9261 |
#查詢號的解果,需要解析。
|
|
|
9262 |
#必填參數:
|
|
|
9263 |
$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
9264 |
$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
9265 |
$conf["db"]["execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
|
| 226 |
liveuser |
9266 |
#可省略參數:
|
|
|
9267 |
|
| 3 |
liveuser |
9268 |
#如果有設定密碼
|
|
|
9269 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
9270 |
|
| 3 |
liveuser |
9271 |
$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
9272 |
|
| 3 |
liveuser |
9273 |
}#if end
|
| 226 |
liveuser |
9274 |
|
| 3 |
liveuser |
9275 |
#如果有設定 $conf["dbPort"]
|
|
|
9276 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
9277 |
|
| 3 |
liveuser |
9278 |
#設置 $conf["dbPort"]
|
|
|
9279 |
$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
9280 |
|
| 3 |
liveuser |
9281 |
}#if end
|
| 226 |
liveuser |
9282 |
|
| 3 |
liveuser |
9283 |
$queryResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
|
|
|
9284 |
unset($conf["db"]["execMysqlQuery"]);
|
|
|
9285 |
|
|
|
9286 |
#如果移除資料表失敗
|
|
|
9287 |
if($queryResult["status"]=="false"){
|
| 226 |
liveuser |
9288 |
|
| 3 |
liveuser |
9289 |
#設置錯誤識別
|
|
|
9290 |
$result["status"]="false";
|
| 226 |
liveuser |
9291 |
|
| 3 |
liveuser |
9292 |
#設置錯誤訊息
|
|
|
9293 |
$result["error"]=$queryResult["error"];
|
| 226 |
liveuser |
9294 |
|
| 3 |
liveuser |
9295 |
#回傳結果
|
|
|
9296 |
return $result;
|
| 226 |
liveuser |
9297 |
|
| 3 |
liveuser |
9298 |
}#if end
|
|
|
9299 |
|
|
|
9300 |
#設置執行成功的訊息
|
|
|
9301 |
$result["status"]="true";
|
|
|
9302 |
|
|
|
9303 |
#回傳結果
|
|
|
9304 |
return $result;
|
|
|
9305 |
|
|
|
9306 |
}#funcotion dropDataTable end
|
|
|
9307 |
|
|
|
9308 |
/*
|
|
|
9309 |
#函式說明:
|
|
|
9310 |
#查詢所有的資料庫列表,會回傳查詢的結果
|
|
|
9311 |
#回傳結果:
|
|
|
9312 |
#$result["status"],執行是否正常,"true"為正常,"fasle"為不正常
|
|
|
9313 |
#$result["error"],爲錯誤訊息
|
|
|
9314 |
#$result["function"],當前執行的函數名稱
|
|
|
9315 |
#$result["dbName"] 爲查詢的資料庫名稱陣列,第一筆資料庫名稱爲$result["dbName"][0],第二筆資料庫名稱爲$result["dbName"][1],其餘以此類推。
|
| 226 |
liveuser |
9316 |
#$result["dbCounts"] 爲資料庫的總筆數
|
| 3 |
liveuser |
9317 |
#必填參數:
|
|
|
9318 |
$conf["dbAddress"],字串,爲mysql-Server的位置.
|
|
|
9319 |
$conf["dbAddress"]=$dbAddress;
|
|
|
9320 |
$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
|
|
|
9321 |
$conf["dbAccount"]=$dbAccount;
|
|
|
9322 |
#可省略參數:
|
|
|
9323 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
9324 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
9325 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
|
|
|
9326 |
#$conf["dbPort"]="3306";
|
|
|
9327 |
#參考資料:
|
|
|
9328 |
#無.
|
|
|
9329 |
#備註:
|
|
|
9330 |
#無.
|
|
|
9331 |
*/
|
|
|
9332 |
public static function getDataBaseList($conf){
|
|
|
9333 |
|
|
|
9334 |
#初始化要回傳的內容
|
|
|
9335 |
$result=array();
|
|
|
9336 |
|
|
|
9337 |
#取得當前執行的函數名稱
|
|
|
9338 |
$result["function"]=__FUNCTION__;
|
|
|
9339 |
|
|
|
9340 |
#如果 $conf 不為陣列
|
|
|
9341 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
9342 |
|
| 3 |
liveuser |
9343 |
#設置執行失敗
|
|
|
9344 |
$result["status"]="false";
|
| 226 |
liveuser |
9345 |
|
| 3 |
liveuser |
9346 |
#設置執行錯誤訊息
|
|
|
9347 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
9348 |
|
|
|
9349 |
#如果傳入的參數為 null
|
|
|
9350 |
if($conf==null){
|
| 226 |
liveuser |
9351 |
|
| 3 |
liveuser |
9352 |
#設置執行錯誤訊息
|
|
|
9353 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
9354 |
|
| 3 |
liveuser |
9355 |
}#if end
|
|
|
9356 |
|
|
|
9357 |
#回傳結果
|
|
|
9358 |
return $result;
|
| 226 |
liveuser |
9359 |
|
| 3 |
liveuser |
9360 |
}#if end
|
|
|
9361 |
|
|
|
9362 |
#檢查參數
|
|
|
9363 |
#函式說明:
|
|
|
9364 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
9365 |
#回傳結果:
|
|
|
9366 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
9367 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
9368 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
9369 |
#必填參數:
|
|
|
9370 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
9371 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
9372 |
#可省略參數:
|
| 226 |
liveuser |
9373 |
#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
9374 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
9375 |
#備註:
|
|
|
9376 |
#功能與checkExistAndType函式相同
|
|
|
9377 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
9378 |
unset($conf["variableCheck"]["isexistMuti"]);
|
|
|
9379 |
|
|
|
9380 |
#如果 $checkResult["passed"]等於"fasle"
|
|
|
9381 |
if($checkResult["passed"]=="fasle"){
|
| 226 |
liveuser |
9382 |
|
| 3 |
liveuser |
9383 |
#設置錯誤識別
|
|
|
9384 |
$result["status"]="fasle";
|
| 226 |
liveuser |
9385 |
|
| 3 |
liveuser |
9386 |
#設置錯誤訊息
|
|
|
9387 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
9388 |
|
| 3 |
liveuser |
9389 |
#回傳結果
|
|
|
9390 |
return $result;
|
|
|
9391 |
|
| 226 |
liveuser |
9392 |
}#if end
|
|
|
9393 |
|
| 3 |
liveuser |
9394 |
#連線到mysql-server
|
|
|
9395 |
#函式說明:
|
|
|
9396 |
#連線到mysql-server,會回傳一個陣列
|
|
|
9397 |
#回傳結果:
|
|
|
9398 |
#$result["status"],若連線成功則爲"true",連線失敗則爲"false"。
|
|
|
9399 |
#$result["connectInformation"],爲回傳的mysql連線資訊。
|
|
|
9400 |
#$result["error"],爲錯誤訊息陣列
|
|
|
9401 |
#必填參數:
|
|
|
9402 |
$conf["db"]["mysqlConnect"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置。
|
|
|
9403 |
$conf["db"]["mysqlConnect"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號。
|
|
|
9404 |
#可省略參數:
|
| 226 |
liveuser |
9405 |
|
| 3 |
liveuser |
9406 |
#如果有設置 $conf["dbPassword"]
|
|
|
9407 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
9408 |
|
| 3 |
liveuser |
9409 |
$conf["db"]["mysqlConnect"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
|
| 226 |
liveuser |
9410 |
|
| 3 |
liveuser |
9411 |
}#if end
|
| 226 |
liveuser |
9412 |
|
| 3 |
liveuser |
9413 |
#如果有設置 $conf["dbPort"]
|
|
|
9414 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
9415 |
|
| 3 |
liveuser |
9416 |
$conf["db"]["mysqlConnect"]["dbPort"]=$conf["dbPort"];#連線時用的port.
|
| 226 |
liveuser |
9417 |
|
| 3 |
liveuser |
9418 |
}#if end
|
| 226 |
liveuser |
9419 |
|
| 3 |
liveuser |
9420 |
$con=db::mysqlConnect($conf["db"]["mysqlConnect"]);
|
|
|
9421 |
unset($conf["db"]["mysqlConnect"]);
|
| 226 |
liveuser |
9422 |
|
| 3 |
liveuser |
9423 |
#如果 $con["status"] 等於 "fasle"
|
|
|
9424 |
if($con["status"]=="fasle"){
|
| 226 |
liveuser |
9425 |
|
| 3 |
liveuser |
9426 |
#設置錯誤識別
|
|
|
9427 |
$result["status"]="false";
|
| 226 |
liveuser |
9428 |
|
| 3 |
liveuser |
9429 |
#設置錯誤訊息
|
|
|
9430 |
$result["error"]=$con;
|
| 226 |
liveuser |
9431 |
|
| 3 |
liveuser |
9432 |
#回傳結果
|
|
|
9433 |
return $result;
|
| 226 |
liveuser |
9434 |
|
| 3 |
liveuser |
9435 |
}#if end
|
| 226 |
liveuser |
9436 |
|
| 3 |
liveuser |
9437 |
#執行列出資料庫列表的SQL語法
|
|
|
9438 |
#函式說明:
|
|
|
9439 |
#執行mysql指令
|
|
|
9440 |
#回傳結果::
|
|
|
9441 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
9442 |
#$result["error"],錯誤訊息的陣列
|
|
|
9443 |
#$result["function"],當前執行的涵式
|
|
|
9444 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
9445 |
#$result["queryString"],mysql查詢的語言
|
|
|
9446 |
#查詢號的解果,需要解析。
|
|
|
9447 |
#必填參數:
|
|
|
9448 |
$conf["db::execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
9449 |
$conf["db::execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
9450 |
$conf["db::execMysqlQuery"]["dbSql"]="show databases;";#要執行sql語法
|
| 226 |
liveuser |
9451 |
#可省略參數:
|
|
|
9452 |
|
| 3 |
liveuser |
9453 |
#如果存在 $conf["dbPassword"]
|
|
|
9454 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
9455 |
|
| 3 |
liveuser |
9456 |
$conf["db::execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
9457 |
|
| 3 |
liveuser |
9458 |
}#if end
|
| 226 |
liveuser |
9459 |
|
| 3 |
liveuser |
9460 |
#如果存在 $conf["dbPort"]
|
|
|
9461 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
9462 |
|
| 3 |
liveuser |
9463 |
$conf["db::execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
9464 |
|
| 3 |
liveuser |
9465 |
}#if end
|
| 226 |
liveuser |
9466 |
|
| 3 |
liveuser |
9467 |
$execMysqlQuery=db::execMysqlQuery($conf["db::execMysqlQuery"]);
|
|
|
9468 |
unset($conf["db::execMysqlQuery"]);
|
|
|
9469 |
|
|
|
9470 |
#如果執行SQL語法失敗
|
|
|
9471 |
if($execMysqlQuery["status"]=="false"){
|
| 226 |
liveuser |
9472 |
|
| 3 |
liveuser |
9473 |
#設置錯誤識別
|
|
|
9474 |
$result["status"]="false";
|
| 226 |
liveuser |
9475 |
|
| 3 |
liveuser |
9476 |
#設置錯誤訊息
|
|
|
9477 |
$result["error"]=$execMysqlQuery;
|
| 226 |
liveuser |
9478 |
|
| 3 |
liveuser |
9479 |
#回傳結果
|
|
|
9480 |
return $result;
|
| 226 |
liveuser |
9481 |
|
| 3 |
liveuser |
9482 |
}#if end
|
|
|
9483 |
|
|
|
9484 |
#設定 $i 的初始值
|
|
|
9485 |
$times=0;
|
|
|
9486 |
|
|
|
9487 |
#逐筆解析內容
|
|
|
9488 |
while($row=mysqli_fetch_assoc($execMysqlQuery["queryResource"])) {
|
| 226 |
liveuser |
9489 |
|
|
|
9490 |
#將結果存進 $fetchResult[$times]
|
| 3 |
liveuser |
9491 |
$fetchResult[$times]= $row['Database'];
|
|
|
9492 |
|
|
|
9493 |
#$times + 1 (計數用)
|
|
|
9494 |
$times++;
|
| 226 |
liveuser |
9495 |
|
| 3 |
liveuser |
9496 |
}#while end
|
|
|
9497 |
|
|
|
9498 |
#取得每筆資料內容(資料庫的名稱)
|
|
|
9499 |
$result["dbName"]=$fetchResult;
|
|
|
9500 |
|
|
|
9501 |
#取得總共的資料筆數
|
|
|
9502 |
$result["dbCounts"]=$times;
|
| 226 |
liveuser |
9503 |
|
| 3 |
liveuser |
9504 |
#執行到這邊代表執行成功
|
|
|
9505 |
$result["status"]="true";
|
| 226 |
liveuser |
9506 |
|
| 3 |
liveuser |
9507 |
#回傳查詢的結果 $result
|
|
|
9508 |
return $result;
|
|
|
9509 |
|
|
|
9510 |
}#function getDataBaseList end
|
|
|
9511 |
|
|
|
9512 |
/*
|
|
|
9513 |
#函式說明:
|
|
|
9514 |
#查詢特定資料庫裡的資料表列表,會回傳查詢的結果
|
|
|
9515 |
#回傳結果:
|
|
|
9516 |
#$result["status"],執行是否成功,"true"代表執行成功;"false"代表執行失敗。
|
|
|
9517 |
#$result["error"],執行錯誤的訊息.
|
|
|
9518 |
#$result["function"],當前執行的函式名稱.
|
|
|
9519 |
#$result["connectInformation"],爲回傳的mysql連線資訊。
|
|
|
9520 |
#$result["tableName"] 爲查詢的資料庫名稱陣列,
|
|
|
9521 |
#第一筆資料庫名稱爲$result["tableName"][0],
|
|
|
9522 |
#第二筆資料庫名稱爲$result["tableName"][1],
|
|
|
9523 |
#其餘以此類推。
|
|
|
9524 |
#$result["dataCounts"] 爲資料表的總筆數
|
|
|
9525 |
#必填參數:
|
|
|
9526 |
$conf["dbAddress"],字串,爲mysql-Server的位置
|
|
|
9527 |
$conf["dbAddress"]=$dbAddress;
|
|
|
9528 |
$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
|
|
|
9529 |
$conf["dbAccount"]=$dbAccount;
|
|
|
9530 |
$conf["selectedDataBaseName"],字串,爲指定的資料庫名稱
|
|
|
9531 |
$conf["selectedDataBaseName"]=$dbName;
|
|
|
9532 |
#可省略參數:
|
|
|
9533 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
9534 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
9535 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
|
|
|
9536 |
#$conf["dbPort"]="3306";
|
|
|
9537 |
#參考資料:
|
|
|
9538 |
#無.
|
|
|
9539 |
#備註:
|
|
|
9540 |
#原始語法,show tables FROM databaseName,代表檢視databaseName裡面的資料表清單。
|
|
|
9541 |
*/
|
|
|
9542 |
public static function getDataTableList($conf){
|
| 226 |
liveuser |
9543 |
|
| 3 |
liveuser |
9544 |
#初始化要回傳的內容
|
|
|
9545 |
$result=array();
|
|
|
9546 |
|
|
|
9547 |
#取得當前執行的函數名稱
|
|
|
9548 |
$result["function"]=__FUNCTION__;
|
|
|
9549 |
|
|
|
9550 |
#如果 $conf 不為陣列
|
|
|
9551 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
9552 |
|
| 3 |
liveuser |
9553 |
#設置執行失敗
|
|
|
9554 |
$result["status"]="false";
|
| 226 |
liveuser |
9555 |
|
| 3 |
liveuser |
9556 |
#設置執行錯誤訊息
|
|
|
9557 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
9558 |
|
|
|
9559 |
#如果傳入的參數為 null
|
|
|
9560 |
if($conf==null){
|
| 226 |
liveuser |
9561 |
|
| 3 |
liveuser |
9562 |
#設置執行錯誤訊息
|
|
|
9563 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
9564 |
|
| 3 |
liveuser |
9565 |
}#if end
|
|
|
9566 |
|
|
|
9567 |
#回傳結果
|
|
|
9568 |
return $result;
|
| 226 |
liveuser |
9569 |
|
| 3 |
liveuser |
9570 |
}#if end
|
| 226 |
liveuser |
9571 |
|
| 3 |
liveuser |
9572 |
#函式說明:
|
|
|
9573 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
9574 |
#回傳結果:
|
|
|
9575 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
9576 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
9577 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
9578 |
#必填參數:
|
|
|
9579 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
9580 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
9581 |
#可省略參數:
|
| 226 |
liveuser |
9582 |
#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
9583 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
9584 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
9585 |
unset($conf["variableCheck"]);
|
|
|
9586 |
|
|
|
9587 |
#如果檢查失敗
|
|
|
9588 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
9589 |
|
| 3 |
liveuser |
9590 |
#設置錯誤訊息識別
|
|
|
9591 |
$result["status"]="fasle";
|
| 226 |
liveuser |
9592 |
|
| 3 |
liveuser |
9593 |
#設置錯誤訊息
|
|
|
9594 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
9595 |
|
| 3 |
liveuser |
9596 |
#回傳錯誤結果
|
|
|
9597 |
return $result;
|
| 226 |
liveuser |
9598 |
|
| 3 |
liveuser |
9599 |
}#if end
|
|
|
9600 |
|
|
|
9601 |
#如果檢查不通過
|
|
|
9602 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
9603 |
|
| 3 |
liveuser |
9604 |
#設置錯誤訊息識別
|
|
|
9605 |
$result["status"]="fasle";
|
| 226 |
liveuser |
9606 |
|
| 3 |
liveuser |
9607 |
#設置錯誤訊息
|
|
|
9608 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
9609 |
|
| 3 |
liveuser |
9610 |
#回傳錯誤結果
|
|
|
9611 |
return $result;
|
| 226 |
liveuser |
9612 |
|
| 3 |
liveuser |
9613 |
}#if end
|
| 226 |
liveuser |
9614 |
|
| 3 |
liveuser |
9615 |
#要執行的 sql 語句
|
|
|
9616 |
$sql="show tables FROM ".$conf["selectedDataBaseName"].";";
|
|
|
9617 |
|
|
|
9618 |
#函式說明:
|
|
|
9619 |
#執行mysql指令
|
|
|
9620 |
#回傳結果::
|
|
|
9621 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
9622 |
#$result["error"],錯誤訊息的陣列
|
|
|
9623 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
9624 |
#$result["queryString"],mysql查詢的語言
|
|
|
9625 |
#查詢號的解果,需要解析。
|
|
|
9626 |
#必填參數:
|
|
|
9627 |
$conf["db.execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
9628 |
$conf["db.execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
9629 |
$conf["db.execMysqlQuery"]["dbSql"]=$sql;#要執行sql語法
|
| 226 |
liveuser |
9630 |
#可省略參數:
|
|
|
9631 |
|
| 3 |
liveuser |
9632 |
#如果 $conf["dbPassword"] 有設定
|
|
|
9633 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
9634 |
|
| 3 |
liveuser |
9635 |
#$conf["db.execMysqlQuery"]["dbPassword"]=$dbPassword;#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
9636 |
$conf["db.execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
|
| 226 |
liveuser |
9637 |
|
| 3 |
liveuser |
9638 |
}#if end
|
| 226 |
liveuser |
9639 |
|
| 3 |
liveuser |
9640 |
#如果 $conf["dbPort"] 有設定
|
|
|
9641 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
9642 |
|
| 3 |
liveuser |
9643 |
#設置 dbPort
|
|
|
9644 |
$conf["db.execMysqlQuery"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
9645 |
|
| 3 |
liveuser |
9646 |
}#if end
|
| 226 |
liveuser |
9647 |
|
| 3 |
liveuser |
9648 |
$queryResult=db::execMysqlQuery($conf["db.execMysqlQuery"]);
|
|
|
9649 |
unset($conf["db.execMysqlQuery"]);
|
|
|
9650 |
|
|
|
9651 |
#如果執行sql語法失敗
|
|
|
9652 |
if($queryResult["status"]=="false"){
|
| 226 |
liveuser |
9653 |
|
| 3 |
liveuser |
9654 |
#設置執行不正常
|
|
|
9655 |
$result["status"]="false";
|
| 226 |
liveuser |
9656 |
|
| 3 |
liveuser |
9657 |
#設置錯誤訊息
|
|
|
9658 |
$result["error"]=$queryResult;
|
| 226 |
liveuser |
9659 |
|
| 3 |
liveuser |
9660 |
#回傳結果
|
|
|
9661 |
return $result;
|
| 226 |
liveuser |
9662 |
|
| 3 |
liveuser |
9663 |
}#if end
|
|
|
9664 |
|
|
|
9665 |
#將查詢的結果放進$queryResult裏面
|
|
|
9666 |
$queryResult=$queryResult["queryResource"];
|
|
|
9667 |
|
|
|
9668 |
#debug
|
|
|
9669 |
#var_dump($queryResult);
|
| 226 |
liveuser |
9670 |
|
| 3 |
liveuser |
9671 |
#設定 $times 的初始值
|
|
|
9672 |
$times=0;
|
|
|
9673 |
|
|
|
9674 |
#初始化解析的內容儲存的地方
|
|
|
9675 |
$fetchResult=array();
|
|
|
9676 |
|
|
|
9677 |
#逐筆解析內容
|
|
|
9678 |
while ($row = mysqli_fetch_assoc($queryResult)) {
|
| 226 |
liveuser |
9679 |
|
|
|
9680 |
#將結果存進 $result[$i]
|
| 3 |
liveuser |
9681 |
$fetchResult[$times]= $row["Tables_in_".$conf["selectedDataBaseName"]];
|
|
|
9682 |
|
|
|
9683 |
#$times + 1 (計數用)
|
|
|
9684 |
$times++;
|
|
|
9685 |
|
|
|
9686 |
#debug
|
|
|
9687 |
#var_dump($row);
|
|
|
9688 |
|
|
|
9689 |
}#while end
|
| 226 |
liveuser |
9690 |
|
| 3 |
liveuser |
9691 |
#取得每筆資料內容(資料表的名稱)
|
|
|
9692 |
$result["tableName"]=$fetchResult;
|
|
|
9693 |
|
|
|
9694 |
#取得總共的資料筆數
|
|
|
9695 |
$result["dataCounts"]=$times;
|
|
|
9696 |
|
|
|
9697 |
#設置執行成功的識別
|
|
|
9698 |
$result["status"]="true";
|
|
|
9699 |
|
|
|
9700 |
#回傳查詢的結果 $result
|
|
|
9701 |
return $result;
|
| 226 |
liveuser |
9702 |
|
| 3 |
liveuser |
9703 |
}#function getDataTableList end
|
|
|
9704 |
|
|
|
9705 |
/*
|
|
|
9706 |
#函式說明:
|
|
|
9707 |
#取得資料表所有欄位的詳細資訊
|
|
|
9708 |
#回傳的內容:
|
|
|
9709 |
#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
|
|
|
9710 |
#$result["error"],錯誤訊息陣列
|
|
|
9711 |
#$result["function"],當前執行的函數名稱.
|
|
|
9712 |
#$result["sql"],執行的sql語法
|
|
|
9713 |
#$result["oriInput"],原始的資料表欄位資訊
|
|
|
9714 |
#$result["everyLine"],逐行的欄位資訊
|
|
|
9715 |
#$result["tableName"],當前查詢的資料表名稱
|
|
|
9716 |
#$result["engine"],資料表使用的儲存引擎
|
|
|
9717 |
#$result["charset"],資料表預設的編碼
|
|
|
9718 |
#$result["columnName"][$i],各欄位的名稱陣列,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9719 |
#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9720 |
#$result["columnVarType"][$i],各欄位變數儲存的型態,$i爲1開始的數字,也可以使用欄位的名稱.
|
|
|
9721 |
#$result["columnVarLengthLimit"][$i],個欄位變數的長度限制,若不存在其限制,則為"",$i爲1開始的數字,也可以使用欄位的名稱.
|
|
|
9722 |
#$result["columnNotNull"][$i],各欄位是否不可爲null,"true"爲不可以爲null;"false"爲可爲"null",$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9723 |
#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9724 |
#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9725 |
#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9726 |
#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9727 |
#$result["columnCollate"][$i],各欄位使用的Collate,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9728 |
#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
|
|
|
9729 |
#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
|
|
|
9730 |
#$result["keyConstraintName"][$j],該資料表用於識別索引鍵的CONSTRAINT名稱陣列,$j爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9731 |
#$result["primaryKey"],該資料表的主鍵
|
|
|
9732 |
#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
|
|
|
9733 |
#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9734 |
#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9735 |
#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲1開始的數字,,也可用欄位的名稱來找value.
|
|
|
9736 |
#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲1開始的數字,也可用欄位的名稱來找value.
|
|
|
9737 |
#$result["foreignKey"]["onUpdateAction"][$i],當參照的欄位資料更新時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
|
|
|
9738 |
#$result["foreignKey"]["onDeleteAction"][$i],當參照的欄位資料移除時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
|
|
|
9739 |
#必填參數:
|
|
|
9740 |
#$conf["dbAddress"],字串,資料庫的網路位置.
|
|
|
9741 |
$conf["dbAddress"]=$dbAddress;
|
|
|
9742 |
#$conf["dbAccount"],字串,連線到資料庫要用的帳號.
|
|
|
9743 |
$conf["dbAccount"]=$dbAccount;
|
|
|
9744 |
#$conf["selectedDataBase"],字串,連線到資料庫要選擇的資料庫.
|
|
|
9745 |
$conf["selectedDataBase"]=$dbName;
|
|
|
9746 |
#$conf["selectedDataTable"],字串,連線到資料庫要檢視的資料表.
|
|
|
9747 |
$conf["selectedDataTable"]="";
|
|
|
9748 |
#可省略參數:
|
|
|
9749 |
#$conf["dbPassword"],字串,連線到資料庫要用的密碼
|
|
|
9750 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
9751 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
|
|
|
9752 |
#$conf["dbPort"]="3306";
|
|
|
9753 |
#參考資料:
|
|
|
9754 |
#無.
|
|
|
9755 |
#備註:
|
|
|
9756 |
#查詢的功能有點弱,目前用getTableColumnDetailInfo替代
|
|
|
9757 |
*/
|
|
|
9758 |
public static function getDataTableColumn($conf){
|
| 226 |
liveuser |
9759 |
|
| 3 |
liveuser |
9760 |
return db::getTableColumnDetailInfo($conf);
|
| 226 |
liveuser |
9761 |
|
| 3 |
liveuser |
9762 |
}#function getDataTableColumn end
|
| 226 |
liveuser |
9763 |
|
| 3 |
liveuser |
9764 |
/*
|
|
|
9765 |
#函式說明:
|
|
|
9766 |
#取得資料表內特定欄位的資訊
|
|
|
9767 |
#回傳的內容:
|
|
|
9768 |
#$result["status"],"true"代表執行成功;"false"代表執行失敗.
|
|
|
9769 |
#$result["error"],錯誤訊息.
|
|
|
9770 |
#$result["function"],當前執行的函數名稱.
|
|
|
9771 |
#$result["columnInfo"]["name"],欄位的名稱.
|
|
|
9772 |
#$result["columnInfo"]["type"],欄位的儲存型態.
|
|
|
9773 |
#$result["columnInfo"]["length"],欄位的長度限制.
|
|
|
9774 |
#$result["columnInfo"]["null"],欄位是否可以為null.
|
|
|
9775 |
#$result["columnInfo"]["key"],索引鍵的名稱.
|
|
|
9776 |
#$result["columnInfo"]["keyType"],欄位的鍵屬性.
|
|
|
9777 |
#$result["columnInfo"]["foreignKeyConstraintName"],外建的名稱
|
|
|
9778 |
#$result["columnInfo"]["referencesTable"],外鍵參考的資料表.
|
|
|
9779 |
#$result["columnInfo"]["referencesColumn"],外鍵參考的資料表欄位.
|
|
|
9780 |
#$result["columnInfo"]["onUpdateAction"],當參考的欄位更新時,要怎麼因應.
|
|
|
9781 |
#$result["columnInfo"]["onDeleteAction"],當參考的欄位資料消失時,要怎麼因應.
|
|
|
9782 |
#$result["columnInfo"]["default"],欄位的預設內容.
|
|
|
9783 |
#$result["columnInfo"]["columnCharacterSet"],欄位的字元集.
|
|
|
9784 |
#$result["columnInfo"]["columnCollate"],欄位的校對編碼.
|
|
|
9785 |
#必填參數:
|
|
|
9786 |
$conf["dbAddress"],字串,爲mysql-Server的位置
|
|
|
9787 |
$conf["dbAddress"]=$dbAddress;
|
|
|
9788 |
$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
|
|
|
9789 |
$conf["dbAccount"]=$dbAccount;
|
|
|
9790 |
$conf["dbName"]=$dbName;#爲指定的資料庫名稱
|
|
|
9791 |
$conf["dtName"]="";#為要檢視的資料表名稱
|
|
|
9792 |
$conf["columnName"],字串,為要檢視的資料欄位名稱
|
|
|
9793 |
$conf["columnName"]="";#為要檢視的資料欄位名稱
|
|
|
9794 |
#可省略參數:
|
|
|
9795 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
9796 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
9797 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,預設為3306.
|
|
|
9798 |
#$conf["dbPort"]="3306";
|
|
|
9799 |
#參考資料:
|
|
|
9800 |
#無.
|
|
|
9801 |
#備註:
|
|
|
9802 |
#無.
|
|
|
9803 |
*/
|
|
|
9804 |
public static function getDataTableSpecificColumn(&$conf){
|
| 226 |
liveuser |
9805 |
|
| 3 |
liveuser |
9806 |
#初始化要回傳的內容
|
|
|
9807 |
$result=array();
|
|
|
9808 |
|
|
|
9809 |
#取得當前執行的函數名稱
|
|
|
9810 |
$result["function"]=__FUNCTION__;
|
|
|
9811 |
|
|
|
9812 |
#如果 $conf 不為陣列
|
|
|
9813 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
9814 |
|
| 3 |
liveuser |
9815 |
#設置執行失敗
|
|
|
9816 |
$result["status"]="false";
|
| 226 |
liveuser |
9817 |
|
| 3 |
liveuser |
9818 |
#設置執行錯誤訊息
|
|
|
9819 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
9820 |
|
|
|
9821 |
#如果傳入的參數為 null
|
|
|
9822 |
if($conf==null){
|
| 226 |
liveuser |
9823 |
|
| 3 |
liveuser |
9824 |
#設置執行錯誤訊息
|
|
|
9825 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
9826 |
|
| 3 |
liveuser |
9827 |
}#if end
|
|
|
9828 |
|
|
|
9829 |
#回傳結果
|
|
|
9830 |
return $result;
|
| 226 |
liveuser |
9831 |
|
| 3 |
liveuser |
9832 |
}#if end
|
| 226 |
liveuser |
9833 |
|
| 3 |
liveuser |
9834 |
#檢查參數
|
|
|
9835 |
#函式說明:
|
|
|
9836 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
9837 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
9838 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
9839 |
#$result["function"],當前執行的函式名稱.
|
|
|
9840 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
9841 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
9842 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
9843 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
9844 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
9845 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
9846 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
9847 |
#必填參數:
|
|
|
9848 |
#$conf["variableCheck::checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
9849 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
9850 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
9851 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","dbName","dtName","columnName");
|
| 226 |
liveuser |
9852 |
#$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
9853 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string");
|
|
|
9854 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
9855 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
9856 |
#可省略參數:
|
|
|
9857 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
9858 |
#$conf["canBeEmptyString"]="false";
|
|
|
9859 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
9860 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort");
|
| 226 |
liveuser |
9861 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
9862 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
9863 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
9864 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null);
|
|
|
9865 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
9866 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
9867 |
#參考資料:
|
|
|
9868 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
9869 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
9870 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
9871 |
|
|
|
9872 |
#如果檢查失敗
|
| 3 |
liveuser |
9873 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
9874 |
|
| 3 |
liveuser |
9875 |
#設置執行失敗
|
|
|
9876 |
$result["status"]="false";
|
| 226 |
liveuser |
9877 |
|
| 3 |
liveuser |
9878 |
#設置執行失敗訊息
|
|
|
9879 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
9880 |
|
| 3 |
liveuser |
9881 |
#回傳結果
|
|
|
9882 |
return $result;
|
| 226 |
liveuser |
9883 |
|
| 3 |
liveuser |
9884 |
}#if end
|
| 226 |
liveuser |
9885 |
|
| 3 |
liveuser |
9886 |
#如果檢查沒有通過
|
|
|
9887 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
9888 |
|
| 3 |
liveuser |
9889 |
#設置執行失敗
|
|
|
9890 |
$result["status"]="false";
|
| 226 |
liveuser |
9891 |
|
| 3 |
liveuser |
9892 |
#設置執行失敗訊息
|
|
|
9893 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
9894 |
|
| 3 |
liveuser |
9895 |
#回傳結果
|
|
|
9896 |
return $result;
|
| 226 |
liveuser |
9897 |
|
| 3 |
liveuser |
9898 |
}#if end
|
| 226 |
liveuser |
9899 |
|
| 3 |
liveuser |
9900 |
#取得所有的欄位資訊
|
|
|
9901 |
#函式說明:
|
|
|
9902 |
#取得資料表所有欄位的詳細資訊
|
|
|
9903 |
#回傳的內容:
|
|
|
9904 |
#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
|
|
|
9905 |
#$result["error"],錯誤訊息陣列
|
|
|
9906 |
#$result["function"],當前執行的函數名稱.
|
|
|
9907 |
#$result["sql"],執行的sql語法
|
|
|
9908 |
#$result["oriInput"],原始的資料表欄位資訊
|
|
|
9909 |
#$result["everyLine"],逐行的欄位資訊
|
|
|
9910 |
#$result["tableName"],當前查詢的資料表名稱
|
|
|
9911 |
#$result["engine"],資料表使用的儲存引擎
|
|
|
9912 |
#$result["charset"],資料表預設的編碼
|
|
|
9913 |
#$result["columnName"][$i],各欄位的名稱陣列,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9914 |
#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9915 |
#$result["columnVarType"][$i],各欄位變數儲存的型態,$i爲1開始的數字,也可以使用欄位的名稱.
|
|
|
9916 |
#$result["columnVarLengthLimit"][$i],個欄位變數的長度限制,若不存在其限制,則為"",$i爲1開始的數字,也可以使用欄位的名稱.
|
|
|
9917 |
#$result["columnNotNull"][$i],各欄位是否不可爲null,"true"爲不可以爲null;"false"爲可爲"null",$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9918 |
#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9919 |
#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9920 |
#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9921 |
#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9922 |
#$result["columnCollate"][$i],各欄位使用的Collate,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9923 |
#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
|
|
|
9924 |
#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
|
|
|
9925 |
#$result["keyConstraintName"][$j],該資料表用於識別索引鍵的CONSTRAINT名稱陣列,$j爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9926 |
#$result["primaryKey"],該資料表的主鍵
|
|
|
9927 |
#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
|
|
|
9928 |
#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9929 |
#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
|
|
|
9930 |
#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲1開始的數字,,也可用欄位的名稱來找value.
|
|
|
9931 |
#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲1開始的數字,也可用欄位的名稱來找value.
|
|
|
9932 |
#$result["foreignKey"]["onUpdateAction"][$i],當參照的欄位資料更新時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
|
|
|
9933 |
#$result["foreignKey"]["onDeleteAction"][$i],當參照的欄位資料移除時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
|
|
|
9934 |
#必填參數:
|
|
|
9935 |
$conf["db::getTableColumnDetailInfo"]["dbAddress"]=$conf["dbAddress"];#資料庫的網路位置
|
|
|
9936 |
$conf["db::getTableColumnDetailInfo"]["dbAccount"]=$conf["dbAccount"];#連線到資料庫要用的帳號
|
|
|
9937 |
$conf["db::getTableColumnDetailInfo"]["selectedDataBase"]=$conf["dbName"];#連線到資料庫要選擇的資料庫
|
|
|
9938 |
$conf["db::getTableColumnDetailInfo"]["selectedDataTable"]=$conf["dtName"];#連線到資料庫要檢視的資料表
|
|
|
9939 |
#可省略參數:
|
| 226 |
liveuser |
9940 |
|
| 3 |
liveuser |
9941 |
#如果有設定連線密碼
|
|
|
9942 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
9943 |
|
| 3 |
liveuser |
9944 |
$conf["db::getTableColumnDetailInfo"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
9945 |
|
| 3 |
liveuser |
9946 |
}#if end
|
| 226 |
liveuser |
9947 |
|
| 3 |
liveuser |
9948 |
#如果有設定連線port
|
|
|
9949 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
9950 |
|
| 3 |
liveuser |
9951 |
$conf["db::getTableColumnDetailInfo"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
9952 |
|
| 3 |
liveuser |
9953 |
}#if end
|
| 226 |
liveuser |
9954 |
|
| 3 |
liveuser |
9955 |
$queryResult=db::getTableColumnDetailInfo($conf["db::getTableColumnDetailInfo"]);
|
|
|
9956 |
unset($conf["db::getTableColumnDetailInfo"]);
|
| 226 |
liveuser |
9957 |
|
| 3 |
liveuser |
9958 |
#如果查詢失敗
|
|
|
9959 |
if($queryResult["status"]=="false"){
|
| 226 |
liveuser |
9960 |
|
| 3 |
liveuser |
9961 |
#設置錯誤
|
|
|
9962 |
$result["status"]="false";
|
| 226 |
liveuser |
9963 |
|
| 3 |
liveuser |
9964 |
#設置錯誤訊息
|
|
|
9965 |
$result["error"]=$queryResult;
|
| 226 |
liveuser |
9966 |
|
| 3 |
liveuser |
9967 |
#回傳結果
|
|
|
9968 |
return $result;
|
| 226 |
liveuser |
9969 |
|
| 3 |
liveuser |
9970 |
}#if end
|
| 226 |
liveuser |
9971 |
|
| 3 |
liveuser |
9972 |
#var_dump($queryResult);
|
| 226 |
liveuser |
9973 |
|
| 3 |
liveuser |
9974 |
#檢查是否有我們要的欄位存在
|
|
|
9975 |
#函式說明:
|
|
|
9976 |
#檢查一個數值是否與陣列裏面的元素相同
|
|
|
9977 |
#回傳結果::
|
|
|
9978 |
#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
|
|
|
9979 |
#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
|
|
|
9980 |
#$result["error"],錯誤訊息
|
|
|
9981 |
#$result["function"],當前執行的函數名稱
|
|
|
9982 |
#$result["equalVarName"],相等的變數名稱或key.
|
|
|
9983 |
#$result["equalVarValue"],相等的變數數值內容.
|
|
|
9984 |
#必填參數:
|
|
|
9985 |
$conf["search"]["getEqualVar"]["conditionElement"]=$conf["columnName"];#條件元素,要等於的元素內容。
|
|
|
9986 |
$conf["search"]["getEqualVar"]["compareElements"]=$queryResult["columnName"];#要比對的陣列變數內容。
|
|
|
9987 |
$searchResult=search::getEqualVar($conf["search"]["getEqualVar"]);
|
|
|
9988 |
unset($conf["search"]["getEqualVar"]);
|
| 226 |
liveuser |
9989 |
|
| 3 |
liveuser |
9990 |
#如果尋找失敗
|
|
|
9991 |
if($searchResult["status"]=="false"){
|
| 226 |
liveuser |
9992 |
|
| 3 |
liveuser |
9993 |
#設置錯誤
|
|
|
9994 |
$result["status"]="false";
|
| 226 |
liveuser |
9995 |
|
| 3 |
liveuser |
9996 |
#設置錯誤訊息
|
|
|
9997 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
9998 |
|
| 3 |
liveuser |
9999 |
#回傳結果
|
|
|
10000 |
return $result;
|
| 226 |
liveuser |
10001 |
|
| 3 |
liveuser |
10002 |
}#if end
|
| 226 |
liveuser |
10003 |
|
| 3 |
liveuser |
10004 |
#如果沒有找到符合的欄位明稱
|
|
|
10005 |
if($searchResult["founded"]=="false"){
|
| 226 |
liveuser |
10006 |
|
| 3 |
liveuser |
10007 |
#設置錯誤
|
|
|
10008 |
$result["status"]="false";
|
| 226 |
liveuser |
10009 |
|
| 3 |
liveuser |
10010 |
#設置錯誤訊息
|
|
|
10011 |
$result["error"]="沒有找到指定的欄位!";
|
| 226 |
liveuser |
10012 |
|
| 3 |
liveuser |
10013 |
#回傳結果
|
|
|
10014 |
return $result;
|
| 226 |
liveuser |
10015 |
|
| 3 |
liveuser |
10016 |
}#if end
|
| 226 |
liveuser |
10017 |
|
| 3 |
liveuser |
10018 |
#取得欄位資訊的key
|
|
|
10019 |
$equalVarKey=$searchResult["equalVarName"];
|
| 226 |
liveuser |
10020 |
|
| 3 |
liveuser |
10021 |
#取得欄位的名稱
|
|
|
10022 |
$result["columnInfo"]["name"]=$queryResult["columnName"][$equalVarKey];
|
| 226 |
liveuser |
10023 |
|
| 3 |
liveuser |
10024 |
#取欄位的儲存型態與長度限制
|
|
|
10025 |
$result["columnInfo"]["type"]=$queryResult["columnVarType"][$equalVarKey];
|
| 226 |
liveuser |
10026 |
|
| 3 |
liveuser |
10027 |
#檢查欄位儲存型態是否含有「(」與「)」
|
|
|
10028 |
#函式說明:
|
|
|
10029 |
#檢查一個字串裡面是否有多個關鍵字
|
|
|
10030 |
#回傳結果::
|
|
|
10031 |
#$result["status"],"true"代表執行成功,"false"代表執行失敗。
|
|
|
10032 |
#$result["error"],錯誤訊息
|
|
|
10033 |
#$result["founded"],是否找到所有的關鍵字,"true"代表有找到關鍵字;"false"代表沒有找到關鍵字。
|
|
|
10034 |
#必填參數:
|
|
|
10035 |
$conf["search"]["findManyKeyWords"]["keyWords"]=array("(",")");#想要搜尋的關鍵字
|
|
|
10036 |
$conf["search"]["findManyKeyWords"]["string"]=$result["columnInfo"]["type"];#要被搜尋的字串內容
|
|
|
10037 |
#可省略參數:
|
|
|
10038 |
#$conf["search"]["findManyKeyWords"]["completeEqual"]="true";#是否內容要完全符合,不能多出任何不符合的內容,預設為不需要完全符合。
|
|
|
10039 |
$searchResult=search::findManyKeyWords($conf["search"]["findManyKeyWords"]);
|
|
|
10040 |
unset($conf["search"]["findManyKeyWords"]);
|
| 226 |
liveuser |
10041 |
|
| 3 |
liveuser |
10042 |
#如果 檢查欄位儲存型態是否含有「(」與「)」 失敗
|
|
|
10043 |
if($searchResult["status"]=="false"){
|
| 226 |
liveuser |
10044 |
|
| 3 |
liveuser |
10045 |
#設置錯誤
|
|
|
10046 |
$result["status"]="false";
|
| 226 |
liveuser |
10047 |
|
| 3 |
liveuser |
10048 |
#設置錯誤訊息
|
|
|
10049 |
$result["error"]=$searchResult;
|
| 226 |
liveuser |
10050 |
|
| 3 |
liveuser |
10051 |
#回傳結果
|
|
|
10052 |
return $result;
|
| 226 |
liveuser |
10053 |
|
| 3 |
liveuser |
10054 |
}#if end
|
| 226 |
liveuser |
10055 |
|
| 3 |
liveuser |
10056 |
#如果欄位儲存型態含有「(」與「)」,則將其從「(」開始分割
|
|
|
10057 |
if($searchResult["founded"]=="true"){
|
| 226 |
liveuser |
10058 |
|
| 3 |
liveuser |
10059 |
#函式說明:
|
|
|
10060 |
#將固定格式的字串分開,並回傳分開的結果。
|
|
|
10061 |
#回傳的參數:
|
|
|
10062 |
#$result["oriStr"],要分割的原始字串內容
|
|
|
10063 |
#$result["dataArray"],爲分割好字串的陣列內容,$result["dataArray"][$i]爲第($i+1)段的內容。
|
|
|
10064 |
#$result["dataCounts"],爲總共分成幾段
|
|
|
10065 |
#必填參數:
|
|
|
10066 |
$conf["stringProcess"]["spiltString"]["stringIn"]=$result["columnInfo"]["type"];#要處理的字串。
|
|
|
10067 |
$conf["stringProcess"]["spiltString"]["spiltSymbol"]="(";#爲以哪個符號作爲分割
|
|
|
10068 |
$spiltedStr=stringProcess::spiltString($conf["stringProcess"]["spiltString"]);
|
|
|
10069 |
unset($conf["stringProcess"]["spiltString"]);
|
| 226 |
liveuser |
10070 |
|
| 3 |
liveuser |
10071 |
#如果分割字串失敗
|
|
|
10072 |
if($spiltedStr["status"]=="false"){
|
| 226 |
liveuser |
10073 |
|
| 3 |
liveuser |
10074 |
#設置錯誤
|
|
|
10075 |
$result["status"]="false";
|
| 226 |
liveuser |
10076 |
|
| 3 |
liveuser |
10077 |
#設置錯誤訊息
|
|
|
10078 |
$result["error"]=$spiltedStr;
|
| 226 |
liveuser |
10079 |
|
| 3 |
liveuser |
10080 |
#回傳結果
|
|
|
10081 |
return $result;
|
| 226 |
liveuser |
10082 |
|
| 3 |
liveuser |
10083 |
}#if end
|
| 226 |
liveuser |
10084 |
|
| 3 |
liveuser |
10085 |
#取得欄位型態
|
|
|
10086 |
$result["columnInfo"]["type"]=$spiltedStr["dataArray"][0];
|
| 226 |
liveuser |
10087 |
|
|
|
10088 |
}#if end
|
|
|
10089 |
|
| 3 |
liveuser |
10090 |
#取得欄位長度限制
|
|
|
10091 |
$result["columnInfo"]["length"]=$queryResult["columnVarLengthLimit"][$conf["columnName"]];
|
| 226 |
liveuser |
10092 |
|
| 3 |
liveuser |
10093 |
#取得欄位是否可以為null
|
|
|
10094 |
$result["columnInfo"]["null"]=$queryResult["columnNotNull"][$conf["columnName"]];
|
| 226 |
liveuser |
10095 |
|
| 3 |
liveuser |
10096 |
#如果該欄位有key的名稱
|
|
|
10097 |
if(isset($queryResult["key"][$conf["columnName"]])){
|
| 226 |
liveuser |
10098 |
|
| 3 |
liveuser |
10099 |
#該欄位為index key
|
|
|
10100 |
$result["columnInfo"]["keyType"]="index key";
|
| 226 |
liveuser |
10101 |
|
| 3 |
liveuser |
10102 |
#取得欄位的鍵名稱
|
|
|
10103 |
$result["columnInfo"]["key"]=$queryResult["keyConstraintName"];
|
| 226 |
liveuser |
10104 |
|
| 3 |
liveuser |
10105 |
}#if end
|
| 226 |
liveuser |
10106 |
|
| 3 |
liveuser |
10107 |
#如果該欄位是foreignKey
|
|
|
10108 |
if(isset($queryResult["foreignKey"]["constraintName"][$conf["columnName"]])){
|
| 226 |
liveuser |
10109 |
|
| 3 |
liveuser |
10110 |
#該欄位為foreign key
|
|
|
10111 |
$result["columnInfo"]["keyType"]="foreign key";
|
| 226 |
liveuser |
10112 |
|
| 3 |
liveuser |
10113 |
#取得外鍵的名稱
|
|
|
10114 |
$result["columnInfo"]["foreignKeyConstraintName"]=$queryResult["foreignKey"]["constraintName"][$conf["columnName"]];
|
| 226 |
liveuser |
10115 |
|
| 3 |
liveuser |
10116 |
#取得外鍵參考的資料表
|
|
|
10117 |
$result["columnInfo"]["referencesTable"]=$queryResult["foreignKey"]["referencesTable"][$conf["columnName"]];
|
| 226 |
liveuser |
10118 |
|
| 3 |
liveuser |
10119 |
#取得外按鍵參考的欄位
|
|
|
10120 |
$result["columnInfo"]["referencesColumn"]=$queryResult["foreignKey"]["referencesColumn"][$conf["columnName"]];
|
| 226 |
liveuser |
10121 |
|
| 3 |
liveuser |
10122 |
#當參考的欄位更新時,要怎麼因應
|
|
|
10123 |
$result["columnInfo"]["onUpdateAction"]=$queryResult["foreignKey"]["onUpdateAction"][$conf["columnName"]];
|
| 226 |
liveuser |
10124 |
|
| 3 |
liveuser |
10125 |
#當參考的欄位資料消失時,要怎麼因應
|
|
|
10126 |
$result["columnInfo"]["onDeleteAction"]=$queryResult["foreignKey"]["onDeleteAction"][$conf["columnName"]];
|
| 226 |
liveuser |
10127 |
|
| 3 |
liveuser |
10128 |
}#if enb
|
| 226 |
liveuser |
10129 |
|
| 3 |
liveuser |
10130 |
#取得欄位的預設內容
|
|
|
10131 |
$result["columnInfo"]["default"]=$queryResult["columnDefault"][$conf["columnName"]];
|
| 226 |
liveuser |
10132 |
|
| 3 |
liveuser |
10133 |
#取得欄位的字元集
|
|
|
10134 |
$result["columnInfo"]["columnCharacterSet"]=$queryResult["columnCharacterSet"][$conf["columnName"]];
|
| 226 |
liveuser |
10135 |
|
| 3 |
liveuser |
10136 |
#取得欄位的校對編碼設定
|
|
|
10137 |
$result["columnInfo"]["columnCollate"]=$queryResult["columnCollate"][$conf["columnName"]];
|
| 226 |
liveuser |
10138 |
|
| 3 |
liveuser |
10139 |
#設置執行成功
|
|
|
10140 |
$result["status"]="true";
|
| 226 |
liveuser |
10141 |
|
| 3 |
liveuser |
10142 |
#回傳結果
|
|
|
10143 |
return $result;
|
| 226 |
liveuser |
10144 |
|
| 3 |
liveuser |
10145 |
}#function getDataTableSpecificColumn end
|
|
|
10146 |
|
|
|
10147 |
/*
|
|
|
10148 |
#函式說明:
|
|
|
10149 |
#檢查資料庫裏的資料表有無指定條件的資料
|
|
|
10150 |
#回傳結果::
|
|
|
10151 |
#$result["status"],執行是否成功,成功為"true",失敗為"false"。
|
| 226 |
liveuser |
10152 |
#$result["error"],錯誤訊息
|
|
|
10153 |
#$result["founded"],是否找到資料,"true"代表有符合的資料;"false"代表沒有符合的資料.
|
| 3 |
liveuser |
10154 |
#$result["sql"],執行的sql字串.
|
|
|
10155 |
#$result["function"],當前執行的函數名稱.
|
|
|
10156 |
#必填參數:
|
| 220 |
liveuser |
10157 |
#$conf["dbAddress"],字串,爲mysql-Server的位置
|
| 3 |
liveuser |
10158 |
$conf["dbAddress"]="";
|
| 220 |
liveuser |
10159 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
|
| 226 |
liveuser |
10160 |
$conf["dbAccount"]="";
|
| 220 |
liveuser |
10161 |
#$conf["selectedDataTableName"],字串,欲選擇的資料表名稱
|
| 3 |
liveuser |
10162 |
$conf["selectedDataTableName"]="";
|
|
|
10163 |
#可省略參數:
|
| 220 |
liveuser |
10164 |
#$conf["selectedDataBaseName"],字串,爲指定的資料庫名稱,欲選擇的資料庫名稱
|
|
|
10165 |
#$conf["selectedDataBaseName"]="";
|
| 3 |
liveuser |
10166 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
10167 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
10168 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
|
|
|
10169 |
#$conf["dbPort"]="";
|
|
|
10170 |
#$conf["conditionTargetName"],字串陣列,用來判斷的資料表數值名稱,需爲陣列,可省略
|
|
|
10171 |
#$conf["conditionTargetName"]=array("");
|
|
|
10172 |
#$conf["conditionTargetValue"],字串陣列,用來判斷的資料表數值名稱若等於該數值,表示條件成立,需爲陣列,可省略
|
|
|
10173 |
#$conf["conditionTargetValue"]=array("");
|
|
|
10174 |
#參考資料:
|
|
|
10175 |
#無.
|
|
|
10176 |
#備註:
|
|
|
10177 |
#無.
|
|
|
10178 |
*/
|
|
|
10179 |
public static function checkDataExists($conf){
|
| 226 |
liveuser |
10180 |
|
| 3 |
liveuser |
10181 |
#初始化要回傳的內容
|
|
|
10182 |
$result=array();
|
|
|
10183 |
|
|
|
10184 |
#取得當前執行的函數名稱
|
|
|
10185 |
$result["function"]=__FUNCTION__;
|
|
|
10186 |
|
|
|
10187 |
#如果 $conf 不為陣列
|
|
|
10188 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
10189 |
|
| 3 |
liveuser |
10190 |
#設置執行失敗
|
|
|
10191 |
$result["status"]="false";
|
| 226 |
liveuser |
10192 |
|
| 3 |
liveuser |
10193 |
#設置執行錯誤訊息
|
|
|
10194 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
10195 |
|
|
|
10196 |
#如果傳入的參數為 null
|
|
|
10197 |
if($conf==null){
|
| 226 |
liveuser |
10198 |
|
| 3 |
liveuser |
10199 |
#設置執行錯誤訊息
|
|
|
10200 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
10201 |
|
| 3 |
liveuser |
10202 |
}#if end
|
|
|
10203 |
|
|
|
10204 |
#回傳結果
|
|
|
10205 |
return $result;
|
| 226 |
liveuser |
10206 |
|
| 3 |
liveuser |
10207 |
}#if end
|
| 226 |
liveuser |
10208 |
|
| 3 |
liveuser |
10209 |
#函式說明:
|
| 220 |
liveuser |
10210 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容.
|
| 3 |
liveuser |
10211 |
#回傳結果:
|
| 220 |
liveuser |
10212 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
10213 |
#$result["error"],執行不正常結束的錯訊息陣列.
|
|
|
10214 |
#$result["simpleError"],簡單表示的錯誤訊息.
|
|
|
10215 |
#$result["function"],當前執行的函式名稱.
|
|
|
10216 |
#$result["argu"],設置給予的參數.
|
| 3 |
liveuser |
10217 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
| 220 |
liveuser |
10218 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
10219 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
10220 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
10221 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
10222 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
10223 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
10224 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
| 3 |
liveuser |
10225 |
#必填參數:
|
| 220 |
liveuser |
10226 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
10227 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
10228 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
10229 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
| 3 |
liveuser |
10230 |
#可省略參數:
|
| 220 |
liveuser |
10231 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
10232 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("selectedDataTableName");
|
|
|
10233 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null、any代表不指定變數形態.其中 resource也包含"resource (closed)".
|
|
|
10234 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string");
|
|
|
10235 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
10236 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
10237 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
10238 |
#$conf["canNotBeEmpty"]=array();
|
|
|
10239 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
10240 |
#$conf["canBeEmpty"]=array();
|
|
|
10241 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
10242 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("dbAddress","dbAccount","selectedDataBaseName","dbPort","conditionTargetName","conditionTargetValue");
|
|
|
10243 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
10244 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbAddress","dbAccount","selectedDataBaseName","dbPort","conditionTargetName","conditionTargetValue");
|
|
|
10245 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
|
|
10246 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","string","string");
|
|
|
10247 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
10248 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array($dbAddress,$adAccount,$dbName,$dbPort,null,null);
|
|
|
10249 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
10250 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
10251 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
10252 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
10253 |
#$conf["disallowAllSkipableVarNotExist"],字串,是否不允許每個可省略參數都不存在,預設為"false"代表允許,反之為"true".
|
|
|
10254 |
#$conf["disallowAllSkipableVarNotExist"]="";
|
|
|
10255 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
10256 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("conditionTargetName","conditionTargetValue");
|
|
|
10257 |
#參考資料:
|
|
|
10258 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
| 3 |
liveuser |
10259 |
#備註:
|
| 220 |
liveuser |
10260 |
#無.
|
|
|
10261 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
10262 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
10263 |
|
| 3 |
liveuser |
10264 |
#如果檢查失敗
|
|
|
10265 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
10266 |
|
| 3 |
liveuser |
10267 |
#設置錯誤識別
|
|
|
10268 |
$result["status"]="false";
|
| 226 |
liveuser |
10269 |
|
| 3 |
liveuser |
10270 |
#設置錯誤訊息
|
|
|
10271 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
10272 |
|
| 3 |
liveuser |
10273 |
#回傳結果
|
|
|
10274 |
return $result;
|
| 226 |
liveuser |
10275 |
|
| 3 |
liveuser |
10276 |
}#if end
|
| 226 |
liveuser |
10277 |
|
| 3 |
liveuser |
10278 |
#如果檢查沒有通過
|
|
|
10279 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
10280 |
|
| 3 |
liveuser |
10281 |
#設置錯誤識別
|
|
|
10282 |
$result["status"]="false";
|
| 226 |
liveuser |
10283 |
|
| 3 |
liveuser |
10284 |
#設置錯誤訊息
|
|
|
10285 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
10286 |
|
| 3 |
liveuser |
10287 |
#回傳結果
|
|
|
10288 |
return $result;
|
| 226 |
liveuser |
10289 |
|
| 3 |
liveuser |
10290 |
}#if end
|
|
|
10291 |
|
|
|
10292 |
#如果 $conf["conditionTargetName"] 有設定
|
|
|
10293 |
if(isset($conf["conditionTargetName"])){
|
|
|
10294 |
|
|
|
10295 |
#如果其形態不爲 array
|
|
|
10296 |
if(gettype($conf["conditionTargetName"])!="array"){
|
|
|
10297 |
|
|
|
10298 |
#設置錯誤識別
|
|
|
10299 |
$result["status"]="false";
|
| 226 |
liveuser |
10300 |
|
| 3 |
liveuser |
10301 |
#設置錯誤訊息
|
|
|
10302 |
$result["error"]="\$conf[\"conditionTargetName\"]須爲陣列值";
|
| 226 |
liveuser |
10303 |
|
| 3 |
liveuser |
10304 |
#回傳結果
|
|
|
10305 |
return $result;
|
|
|
10306 |
|
|
|
10307 |
}#if end
|
|
|
10308 |
|
|
|
10309 |
}#if end
|
|
|
10310 |
|
|
|
10311 |
#如果 $conf["conditionTargetValue"] 有設定
|
|
|
10312 |
if(isset($conf["conditionTargetValue"])){
|
|
|
10313 |
|
|
|
10314 |
#如果其形態不爲 array
|
|
|
10315 |
if(gettype($conf["conditionTargetValue"])!="array"){
|
|
|
10316 |
|
|
|
10317 |
#設置錯誤識別
|
|
|
10318 |
$result["status"]="false";
|
| 226 |
liveuser |
10319 |
|
| 3 |
liveuser |
10320 |
#設置錯誤訊息
|
|
|
10321 |
$result["error"]="\$conf[\"conditionTargetValue\"]須爲陣列值";
|
| 226 |
liveuser |
10322 |
|
| 3 |
liveuser |
10323 |
#回傳結果
|
|
|
10324 |
return $result;
|
|
|
10325 |
|
|
|
10326 |
}#if end
|
|
|
10327 |
|
|
|
10328 |
}#if end
|
|
|
10329 |
|
|
|
10330 |
#函式說明:
|
|
|
10331 |
#一次取得資料庫、表的資料
|
|
|
10332 |
#回傳結果:
|
|
|
10333 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
10334 |
#$result["error"],錯誤訊息陣列。
|
|
|
10335 |
#$result["dataContent"],爲資料的內容。
|
|
|
10336 |
#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
10337 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
10338 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
10339 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
10340 |
#必填參數:
|
|
|
10341 |
$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"];#爲dbServer的位置。
|
|
|
10342 |
$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"];#爲登入dbServer的帳號。
|
|
|
10343 |
$conf["db"]["fastGetDbData"]["dbName"]=$conf["selectedDataBaseName"];#爲要存取的資料庫名稱
|
|
|
10344 |
$conf["db"]["fastGetDbData"]["tableName"]=$conf["selectedDataTableName"];#爲要存取的資料表名稱
|
|
|
10345 |
$conf["db"]["fastGetDbData"]["columnYouWant"]=$conf["conditionTargetName"];#你想要的欄位!
|
|
|
10346 |
#可省略參數:
|
| 226 |
liveuser |
10347 |
|
| 3 |
liveuser |
10348 |
#如果 $conf["dbPassword"] 有設置
|
|
|
10349 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
10350 |
|
| 3 |
liveuser |
10351 |
$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"];#爲要存取dbServer的密碼
|
| 226 |
liveuser |
10352 |
|
| 3 |
liveuser |
10353 |
}#if end
|
| 226 |
liveuser |
10354 |
|
| 3 |
liveuser |
10355 |
#如果 $conf["dbPort"] 有設置
|
|
|
10356 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
10357 |
|
| 3 |
liveuser |
10358 |
$conf["db"]["fastGetDbData"]["dbPort"]=$conf["dbPort"];#爲要存取dbServer的port
|
| 226 |
liveuser |
10359 |
|
| 3 |
liveuser |
10360 |
}#if end
|
| 226 |
liveuser |
10361 |
|
| 3 |
liveuser |
10362 |
$conf["db"]["fastGetDbData"]["WhereColumnName"]=$conf["conditionTargetName"];#用於判斷語句的欄位項目陣列。
|
|
|
10363 |
$conf["db"]["fastGetDbData"]["WhereColumnValue"]=$conf["conditionTargetValue"];#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
|
|
10364 |
#$conf["db"]["fastGetDbData"]["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
10365 |
#$conf["db"]["fastGetDbData"]["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
10366 |
#$conf["db"]["fastGetDbData"]["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
10367 |
#$conf["db"]["fastGetDbData"]["orderItem"]="";#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
|
|
10368 |
#$conf["db"]["fastGetDbData"]["ascORdesc"]="";#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
|
|
10369 |
#$conf["db"]["fastGetDbData"]["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
|
|
|
10370 |
#$conf["db"]["fastGetDbData"]["numLimit"]="30";#為要取幾筆資料,可以省略,省略則表示不限制數目。
|
|
|
10371 |
#$conf["db"]["fastGetDbData"]["groupBy"]=array("");#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
|
|
10372 |
$dataResult=db::fastGetDbData($conf["db"]["fastGetDbData"]);
|
|
|
10373 |
unset($conf["db"]["fastGetDbData"]);
|
|
|
10374 |
|
|
|
10375 |
#如果查詢資料失敗
|
|
|
10376 |
if($dataResult["status"]=="false"){
|
| 226 |
liveuser |
10377 |
|
| 3 |
liveuser |
10378 |
#設置錯誤識別
|
|
|
10379 |
$result["status"]="false";
|
| 226 |
liveuser |
10380 |
|
| 3 |
liveuser |
10381 |
#設置錯誤訊息
|
|
|
10382 |
$result["error"]=$dataResult;
|
| 226 |
liveuser |
10383 |
|
| 3 |
liveuser |
10384 |
#回傳結果
|
|
|
10385 |
return $result;
|
| 226 |
liveuser |
10386 |
|
| 3 |
liveuser |
10387 |
}#if end
|
|
|
10388 |
|
|
|
10389 |
#取得執行的sql字串
|
|
|
10390 |
$result["sql"]=$dataResult["sql"];
|
|
|
10391 |
|
|
|
10392 |
#如果 $dataResult["status"] 等於"false"
|
|
|
10393 |
if($dataResult["status"]=="false"){
|
| 226 |
liveuser |
10394 |
|
| 3 |
liveuser |
10395 |
#設置錯誤識別
|
|
|
10396 |
$result["status"]="false";
|
| 226 |
liveuser |
10397 |
|
| 3 |
liveuser |
10398 |
#設置錯誤訊息
|
|
|
10399 |
$result["error"]=$dataResult;
|
| 226 |
liveuser |
10400 |
|
| 3 |
liveuser |
10401 |
#回傳結果
|
|
|
10402 |
return $result;
|
| 226 |
liveuser |
10403 |
|
| 3 |
liveuser |
10404 |
}#if end
|
| 226 |
liveuser |
10405 |
|
| 3 |
liveuser |
10406 |
#如果$dataResult["dataCount"]沒設定,就表示沒找到相符的資料
|
|
|
10407 |
if(!isset($dataResult["dataCount"])){
|
| 226 |
liveuser |
10408 |
|
| 3 |
liveuser |
10409 |
#設置錯誤識別
|
|
|
10410 |
$result["status"]="true";
|
| 226 |
liveuser |
10411 |
|
| 3 |
liveuser |
10412 |
#設置沒有找到符合資料
|
|
|
10413 |
$result["founded"]="false";
|
| 226 |
liveuser |
10414 |
|
| 3 |
liveuser |
10415 |
#回傳結果
|
|
|
10416 |
return $result;
|
| 226 |
liveuser |
10417 |
|
| 3 |
liveuser |
10418 |
}#if end
|
| 226 |
liveuser |
10419 |
|
| 3 |
liveuser |
10420 |
#如果符合的資料等於0
|
|
|
10421 |
if($dataResult["dataCount"]==0){
|
| 226 |
liveuser |
10422 |
|
| 3 |
liveuser |
10423 |
#設置錯誤識別
|
|
|
10424 |
$result["status"]="true";
|
| 226 |
liveuser |
10425 |
|
| 3 |
liveuser |
10426 |
#設置沒有找到符合資料
|
|
|
10427 |
$result["founded"]="false";
|
| 226 |
liveuser |
10428 |
|
| 3 |
liveuser |
10429 |
#回傳結果
|
|
|
10430 |
return $result;
|
| 226 |
liveuser |
10431 |
|
| 3 |
liveuser |
10432 |
}#if end
|
|
|
10433 |
|
|
|
10434 |
#執行到這邊代表執行成功
|
|
|
10435 |
$result["status"]="true";
|
|
|
10436 |
|
|
|
10437 |
#設置有找到符合資料
|
|
|
10438 |
$result["founded"]="true";
|
|
|
10439 |
|
|
|
10440 |
#回傳結果
|
|
|
10441 |
return $result;
|
|
|
10442 |
|
|
|
10443 |
}#function checkDataExists
|
|
|
10444 |
|
|
|
10445 |
/*
|
|
|
10446 |
#函式說明:
|
|
|
10447 |
#檢查資料表是否存在
|
|
|
10448 |
#回傳結果::
|
|
|
10449 |
#設置執行錯誤的識別
|
|
|
10450 |
#$result["status"],"true"代表執行成功;"false"代表執行失敗.
|
|
|
10451 |
#$result["error"],錯誤訊息.
|
|
|
10452 |
#$result["founded"],是否有有找到相同的,"true"代表有找到符合的資料;"false"代表沒有符合的資料.
|
|
|
10453 |
#$result["function"],當前執行的函數名稱.
|
|
|
10454 |
#$result["argu"],使用的參數
|
|
|
10455 |
#其餘的結果代表參數不正確
|
|
|
10456 |
#必填參數:
|
|
|
10457 |
#$conf["dbAddress"],字串,爲mysql-Server的位置
|
|
|
10458 |
$conf["dbAddress"]=$dbAddress;
|
|
|
10459 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
|
|
|
10460 |
$conf["dbAccount"]=$dbAccount;
|
|
|
10461 |
#$conf["selectedDataBaseName"],字串,爲指定的資料庫名稱
|
|
|
10462 |
$conf["selectedDataBaseName"]="";
|
|
|
10463 |
#$conf["selectedDataTableName"],字串,為要檢查是否存在的資料表名稱
|
|
|
10464 |
$conf["selectedDataTableName"]="";
|
|
|
10465 |
#可省略參數
|
| 226 |
liveuser |
10466 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 3 |
liveuser |
10467 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
10468 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
|
|
|
10469 |
#$conf["dbPort"]="";
|
|
|
10470 |
#參考資料:
|
|
|
10471 |
#無.
|
|
|
10472 |
#備註:
|
|
|
10473 |
#無.
|
|
|
10474 |
*/
|
|
|
10475 |
public static function checkDataTableExists($conf){
|
| 226 |
liveuser |
10476 |
|
| 3 |
liveuser |
10477 |
#初始化要回傳的變數
|
|
|
10478 |
$result=array();
|
| 226 |
liveuser |
10479 |
|
| 3 |
liveuser |
10480 |
#取得當前執行的函數名稱
|
|
|
10481 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
10482 |
|
| 3 |
liveuser |
10483 |
#如果 $conf 不為陣列
|
|
|
10484 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
10485 |
|
| 3 |
liveuser |
10486 |
#設置執行失敗
|
|
|
10487 |
$result["status"]="false";
|
| 226 |
liveuser |
10488 |
|
| 3 |
liveuser |
10489 |
#設置執行錯誤訊息
|
|
|
10490 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
10491 |
|
|
|
10492 |
#如果傳入的參數為 null
|
|
|
10493 |
if($conf==null){
|
| 226 |
liveuser |
10494 |
|
| 3 |
liveuser |
10495 |
#設置執行錯誤訊息
|
|
|
10496 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
10497 |
|
| 3 |
liveuser |
10498 |
}#if end
|
|
|
10499 |
|
|
|
10500 |
#回傳結果
|
|
|
10501 |
return $result;
|
| 226 |
liveuser |
10502 |
|
| 3 |
liveuser |
10503 |
}#if end
|
| 226 |
liveuser |
10504 |
|
| 3 |
liveuser |
10505 |
#取得參數
|
|
|
10506 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
10507 |
|
| 3 |
liveuser |
10508 |
#函式說明:
|
|
|
10509 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
10510 |
#回傳結果:
|
|
|
10511 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
10512 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
10513 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
10514 |
#必填參數:
|
|
|
10515 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
10516 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
10517 |
#可省略參數:
|
| 226 |
liveuser |
10518 |
$conf["variableType"]=array("string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
10519 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
10520 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
10521 |
unset($conf["variableCheck"]["isexistMuti"]);
|
| 226 |
liveuser |
10522 |
|
| 3 |
liveuser |
10523 |
#var_dump($checkResult);
|
| 226 |
liveuser |
10524 |
|
| 3 |
liveuser |
10525 |
#如果檢查不通過
|
|
|
10526 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
10527 |
|
| 3 |
liveuser |
10528 |
#設置執行錯誤的識別
|
|
|
10529 |
$result["status"]="false";
|
| 226 |
liveuser |
10530 |
|
| 3 |
liveuser |
10531 |
#設置錯誤訊息
|
|
|
10532 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
10533 |
|
| 3 |
liveuser |
10534 |
#回傳結果
|
|
|
10535 |
return $result;
|
| 226 |
liveuser |
10536 |
|
| 3 |
liveuser |
10537 |
}#if end
|
| 226 |
liveuser |
10538 |
|
| 3 |
liveuser |
10539 |
#查詢特定資料庫裡的資料表列表,會回傳查詢的結果
|
|
|
10540 |
#$result["status"],若成功則爲0,失敗則爲1。
|
|
|
10541 |
#$result["error"],錯誤訊息陣列.
|
|
|
10542 |
#$result["tableName"] 爲查詢的資料庫名稱陣列,
|
|
|
10543 |
#第一筆資料庫名稱爲$result["tableName"][0],
|
|
|
10544 |
#第二筆資料庫名稱爲$result["tableName"][1],
|
|
|
10545 |
#其餘以此類推。
|
|
|
10546 |
#$result["dataCounts"] 爲資料庫的總筆數
|
|
|
10547 |
#必填參數:
|
|
|
10548 |
$conf["db"]["getDataTableList"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
10549 |
$conf["db"]["getDataTableList"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
10550 |
$conf["db"]["getDataTableList"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲指定的資料庫名稱
|
|
|
10551 |
#可省略參數:
|
| 226 |
liveuser |
10552 |
|
| 3 |
liveuser |
10553 |
#如果 $conf["dbPassword"] 有設定
|
|
|
10554 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
10555 |
|
| 3 |
liveuser |
10556 |
#設定連線時要用的密碼
|
|
|
10557 |
$conf["db"]["getDataTableList"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
10558 |
|
| 3 |
liveuser |
10559 |
}#if end
|
| 226 |
liveuser |
10560 |
|
| 3 |
liveuser |
10561 |
#如果 $conf["dbPort"] 有設定
|
|
|
10562 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
10563 |
|
| 3 |
liveuser |
10564 |
#設定連線時要用的密碼
|
|
|
10565 |
$conf["db"]["getDataTableList"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
10566 |
|
|
|
10567 |
}#if end
|
|
|
10568 |
|
| 3 |
liveuser |
10569 |
#原始語法:
|
|
|
10570 |
#show tables FROM databaseName,代表檢視databaseName裡面的資料表清單。
|
|
|
10571 |
$dataTableList=db::getDataTableList($conf["db"]["getDataTableList"]);
|
|
|
10572 |
unset($conf["db"]["getDataTableList"]);
|
| 226 |
liveuser |
10573 |
|
| 3 |
liveuser |
10574 |
#如果調閱資料表清單出錯
|
|
|
10575 |
if($dataTableList["status"]=="false"){
|
| 226 |
liveuser |
10576 |
|
| 3 |
liveuser |
10577 |
#設置錯誤識別
|
|
|
10578 |
$result["status"]="false";
|
| 226 |
liveuser |
10579 |
|
| 3 |
liveuser |
10580 |
#設置錯誤訊息
|
|
|
10581 |
$result["error"]=$dataTableList;
|
| 226 |
liveuser |
10582 |
|
| 3 |
liveuser |
10583 |
#回傳結果
|
|
|
10584 |
return $result;
|
| 226 |
liveuser |
10585 |
|
| 3 |
liveuser |
10586 |
}#if end
|
| 226 |
liveuser |
10587 |
|
| 3 |
liveuser |
10588 |
#如果裡面沒有任何1個資料表
|
|
|
10589 |
if($dataTableList["dataCounts"]==0){
|
| 226 |
liveuser |
10590 |
|
| 3 |
liveuser |
10591 |
#設置執行成功的識別
|
|
|
10592 |
$result["status"]="true";
|
| 226 |
liveuser |
10593 |
|
| 3 |
liveuser |
10594 |
#設置有找到相同的
|
|
|
10595 |
$result["founded"]="false";
|
| 226 |
liveuser |
10596 |
|
| 3 |
liveuser |
10597 |
#回傳結果
|
|
|
10598 |
return $result;
|
| 226 |
liveuser |
10599 |
|
| 3 |
liveuser |
10600 |
}#if end
|
| 226 |
liveuser |
10601 |
|
| 3 |
liveuser |
10602 |
#函式說明:
|
|
|
10603 |
#檢查一個數值是否與陣列裏面的元素相同
|
|
|
10604 |
#回傳結果::
|
|
|
10605 |
#$result["status"],"true"表示執行正確,"false"表示執行錯誤.
|
|
|
10606 |
#$result["founded"],"true"表示有找到相同的,"false"表示沒有找到相同的.
|
|
|
10607 |
#$result["error"],錯誤訊息
|
|
|
10608 |
#$result["function"],當前執行的函數名稱
|
|
|
10609 |
#$result["argv"],使用的參數
|
|
|
10610 |
#$result["equalVarName"],相等的變數名稱或key.
|
|
|
10611 |
#$result["equalVarValue"],相等的變數數值內容.
|
|
|
10612 |
#必填參數:
|
|
|
10613 |
$conf["search"]["getEqualVar"]["conditionElement"]=$conf["selectedDataTableName"];#條件元素,要等於的元素內容。
|
|
|
10614 |
$conf["search"]["getEqualVar"]["compareElements"]=$dataTableList["tableName"];#要比對的陣列變數內容。
|
|
|
10615 |
$checkResult=search::getEqualVar($conf["search"]["getEqualVar"]);
|
|
|
10616 |
unset($conf["search"]["getEqualVar"]);
|
|
|
10617 |
|
|
|
10618 |
#如果有找到相同的元素
|
|
|
10619 |
if($checkResult["founded"]==="true"){
|
| 226 |
liveuser |
10620 |
|
| 3 |
liveuser |
10621 |
#設置執行成功的識別
|
|
|
10622 |
$result["status"]="true";
|
| 226 |
liveuser |
10623 |
|
| 3 |
liveuser |
10624 |
#設置有找到相同的
|
|
|
10625 |
$result["founded"]="true";
|
| 226 |
liveuser |
10626 |
|
| 3 |
liveuser |
10627 |
#回傳結果
|
|
|
10628 |
return $result;
|
| 226 |
liveuser |
10629 |
|
| 3 |
liveuser |
10630 |
}#if end
|
| 226 |
liveuser |
10631 |
|
| 3 |
liveuser |
10632 |
#如果沒有找到相同的元素
|
|
|
10633 |
if($checkResult["founded"]==="false"){
|
|
|
10634 |
|
|
|
10635 |
#設置執行成功的識別
|
|
|
10636 |
$result["status"]="true";
|
| 226 |
liveuser |
10637 |
|
| 3 |
liveuser |
10638 |
#設置有找到相同的
|
|
|
10639 |
$result["founded"]="false";
|
| 226 |
liveuser |
10640 |
|
| 3 |
liveuser |
10641 |
#回傳結果
|
|
|
10642 |
return $result;
|
| 226 |
liveuser |
10643 |
|
| 3 |
liveuser |
10644 |
}#if end
|
| 226 |
liveuser |
10645 |
|
| 3 |
liveuser |
10646 |
#不應該執行到這邊
|
| 226 |
liveuser |
10647 |
|
| 3 |
liveuser |
10648 |
#設置執行失敗
|
|
|
10649 |
$result["status"]="false";
|
| 226 |
liveuser |
10650 |
|
| 3 |
liveuser |
10651 |
#設置執行錯誤
|
|
|
10652 |
$result["error"]="不應該出現的例外狀況";
|
| 226 |
liveuser |
10653 |
|
| 3 |
liveuser |
10654 |
#回傳結果
|
|
|
10655 |
return $result;
|
| 226 |
liveuser |
10656 |
|
| 3 |
liveuser |
10657 |
}#funcrion checkDataTableExists end
|
|
|
10658 |
|
|
|
10659 |
/*
|
|
|
10660 |
#函式說明:
|
|
|
10661 |
#檢查資料表的欄位是否存在
|
|
|
10662 |
#回傳結果::
|
|
|
10663 |
#設置執行錯誤的識別
|
|
|
10664 |
#$result["function"],當前執行的函數名稱.
|
|
|
10665 |
#$result["status"],"true"代表執行成功;"false"代表執行失敗.
|
|
|
10666 |
#$result["error"],錯誤訊息.
|
|
|
10667 |
#$result["warning"],警告訊息陣列
|
|
|
10668 |
#$result["passed"],是否通過檢查,"true"代表通過;"false"代表不通過.
|
|
|
10669 |
#其餘的結果代表參數不正確
|
|
|
10670 |
#必填參數:
|
|
|
10671 |
#$conf["dbAddr"],字串,爲mysql-Server的位置
|
| 226 |
liveuser |
10672 |
$conf["dbAddr"]=$dbAddress;
|
| 3 |
liveuser |
10673 |
#$conf["dbAcct"],字串,爲用於連入mysql-Server時要使用的帳號
|
|
|
10674 |
$conf["dbAcct"]=$dbAccount;
|
|
|
10675 |
#$conf["dbName"],字串,爲指定的資料庫名稱
|
|
|
10676 |
$conf["dbName"]="";
|
|
|
10677 |
#$conf["dtName"],字串,為要檢查是否存在的資料表名稱
|
|
|
10678 |
$conf["dtName"]="";
|
|
|
10679 |
#$conf["col"],字串陣列,要檢查的欄位名稱.
|
|
|
10680 |
$conf["col"]=array();
|
|
|
10681 |
#可省略參數
|
| 226 |
liveuser |
10682 |
#$conf["dbPass"],爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 3 |
liveuser |
10683 |
#$conf["dbPass"]=$dbPassword;
|
|
|
10684 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
|
|
|
10685 |
#$conf["dbPort"]="";
|
|
|
10686 |
#參考資料:
|
|
|
10687 |
#無.
|
|
|
10688 |
#備註:
|
|
|
10689 |
#無.
|
|
|
10690 |
*/
|
|
|
10691 |
public static function checkTableColExists(&$conf=array()){
|
| 226 |
liveuser |
10692 |
|
| 3 |
liveuser |
10693 |
#初始化要回傳的結果
|
|
|
10694 |
$result=array();
|
|
|
10695 |
|
|
|
10696 |
#取得當前執行的函數名稱
|
|
|
10697 |
$result["function"]=__FUNCTION__;
|
|
|
10698 |
|
|
|
10699 |
#如果沒有參數
|
|
|
10700 |
if(func_num_args()==0){
|
| 226 |
liveuser |
10701 |
|
| 3 |
liveuser |
10702 |
#設置執行失敗
|
|
|
10703 |
$result["status"]="false";
|
| 226 |
liveuser |
10704 |
|
| 3 |
liveuser |
10705 |
#設置執行錯誤訊息
|
|
|
10706 |
$result["error"]="函數".$result["function"]."需要參數";
|
| 226 |
liveuser |
10707 |
|
| 3 |
liveuser |
10708 |
#回傳結果
|
|
|
10709 |
return $result;
|
| 226 |
liveuser |
10710 |
|
| 3 |
liveuser |
10711 |
}#if end
|
| 226 |
liveuser |
10712 |
|
| 3 |
liveuser |
10713 |
#取得參數
|
|
|
10714 |
$result["argu"]=$conf;
|
|
|
10715 |
|
|
|
10716 |
#如果 $conf 不為陣列
|
|
|
10717 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
10718 |
|
| 3 |
liveuser |
10719 |
#設置執行失敗
|
|
|
10720 |
$result["status"]="false";
|
| 226 |
liveuser |
10721 |
|
| 3 |
liveuser |
10722 |
#設置執行錯誤訊息
|
|
|
10723 |
$result["error"][]="\$conf變數須為陣列形態";
|
| 226 |
liveuser |
10724 |
|
| 3 |
liveuser |
10725 |
#如果傳入的參數為 null
|
|
|
10726 |
if($conf===null){
|
| 226 |
liveuser |
10727 |
|
| 3 |
liveuser |
10728 |
#設置執行錯誤訊息
|
|
|
10729 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
10730 |
|
| 3 |
liveuser |
10731 |
}#if end
|
|
|
10732 |
|
|
|
10733 |
#回傳結果
|
|
|
10734 |
return $result;
|
| 226 |
liveuser |
10735 |
|
| 3 |
liveuser |
10736 |
}#if end
|
| 226 |
liveuser |
10737 |
|
| 3 |
liveuser |
10738 |
#函式說明:
|
|
|
10739 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
10740 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
10741 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
10742 |
#$result["function"],當前執行的函式名稱.
|
|
|
10743 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
10744 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
10745 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
10746 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
10747 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
10748 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
10749 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
10750 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
10751 |
#必填參數:
|
|
|
10752 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
10753 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
| 3 |
liveuser |
10754 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
10755 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
10756 |
#可以省略的參數:
|
|
|
10757 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
10758 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddr","dbName","dbAcct","dtName","col");
|
|
|
10759 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
10760 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","array");
|
|
|
10761 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
10762 |
#$conf["canBeEmptyString"]="false";
|
|
|
10763 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
10764 |
#$conf["canNotBeEmpty"]=array();
|
|
|
10765 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
10766 |
#$conf["canBeEmpty"]=array();
|
|
|
10767 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
10768 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
10769 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
10770 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPass","dbPort");
|
| 226 |
liveuser |
10771 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
10772 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
10773 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
10774 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null);
|
|
|
10775 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
10776 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
10777 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
10778 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
10779 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
10780 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
10781 |
#參考資料:
|
|
|
10782 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
10783 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
10784 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
10785 |
|
| 3 |
liveuser |
10786 |
#如果檢查失敗
|
|
|
10787 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
10788 |
|
| 3 |
liveuser |
10789 |
#設置執行失敗
|
|
|
10790 |
$result["status"]="false";
|
| 226 |
liveuser |
10791 |
|
| 3 |
liveuser |
10792 |
#設置錯誤訊息
|
|
|
10793 |
$result["error"]=$checkArguments["error"];
|
| 226 |
liveuser |
10794 |
|
| 3 |
liveuser |
10795 |
#回傳結果
|
|
|
10796 |
return $result;
|
| 226 |
liveuser |
10797 |
|
| 3 |
liveuser |
10798 |
}#if end
|
| 226 |
liveuser |
10799 |
|
| 3 |
liveuser |
10800 |
#如果檢查不通過
|
|
|
10801 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
10802 |
|
| 3 |
liveuser |
10803 |
#設置執行失敗
|
|
|
10804 |
$result["status"]="false";
|
| 226 |
liveuser |
10805 |
|
| 3 |
liveuser |
10806 |
#設置錯誤訊息
|
|
|
10807 |
$result["error"]=$checkArguments["error"];
|
| 226 |
liveuser |
10808 |
|
| 3 |
liveuser |
10809 |
#回傳結果
|
|
|
10810 |
return $result;
|
| 226 |
liveuser |
10811 |
|
| 3 |
liveuser |
10812 |
}#if end
|
| 226 |
liveuser |
10813 |
|
| 3 |
liveuser |
10814 |
#函式說明:
|
|
|
10815 |
#取得資料表所有欄位的詳細資訊
|
|
|
10816 |
#回傳的內容:
|
|
|
10817 |
#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
|
|
|
10818 |
#$result["error"],錯誤訊息陣列
|
|
|
10819 |
#$result["function"],當前執行的函數名稱.
|
|
|
10820 |
#$result["sql"],執行的sql語法
|
|
|
10821 |
#$result["oriInput"],原始的資料表欄位資訊
|
|
|
10822 |
#$result["everyLine"],逐行的欄位資訊
|
|
|
10823 |
#$result["tableName"],當前查詢的資料表名稱
|
|
|
10824 |
#$result["engine"],資料表使用的儲存引擎
|
|
|
10825 |
#$result["charset"],資料表預設的編碼
|
|
|
10826 |
#$result["columnName"][$i],各欄位的名稱陣列,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
10827 |
#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
10828 |
#$result["columnVarType"][$i],各欄位變數儲存的型態,$i爲1開始的數字,也可以使用欄位的名稱.
|
|
|
10829 |
#$result["columnVarLengthLimit"][$i],個欄位變數的長度限制,若不存在其限制,則為"",$i爲1開始的數字,也可以使用欄位的名稱.
|
|
|
10830 |
#$result["columnNotNull"][$i],各欄位是否不可爲null,"true"爲不可以爲null;"false"爲可爲"null",$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
10831 |
#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
10832 |
#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
10833 |
#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
10834 |
#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
10835 |
#$result["columnCollate"][$i],各欄位使用的Collate,$i爲1開始的數字,也可以使用欄位的名稱。
|
|
|
10836 |
#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
|
|
|
10837 |
#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
|
|
|
10838 |
#$result["keyConstraintName"][$j],該資料表用於識別索引鍵的CONSTRAINT名稱陣列,$j爲1開始的數字,也可以使用欄位的名稱。
|
|
|
10839 |
#$result["primaryKey"],該資料表的主鍵
|
|
|
10840 |
#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
|
|
|
10841 |
#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
|
|
|
10842 |
#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列,$k爲1開始的數字,也可以使用欄位的名稱。
|
|
|
10843 |
#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲1開始的數字,,也可用欄位的名稱來找value.
|
|
|
10844 |
#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲1開始的數字,也可用欄位的名稱來找value.
|
|
|
10845 |
#$result["foreignKey"]["onUpdateAction"][$i],當參照的欄位資料更新時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
|
|
|
10846 |
#$result["foreignKey"]["onDeleteAction"][$i],當參照的欄位資料移除時,會怎麼同步,$i爲1開始的數字,也可用欄位的名稱來找value.
|
|
|
10847 |
#必填參數:
|
|
|
10848 |
$conf["db::getDataTableColumn"]["dbAddress"]=$conf["dbAddr"];#資料庫的網路位置
|
|
|
10849 |
$conf["db::getDataTableColumn"]["dbAccount"]=$conf["dbAcct"];#連線到資料庫要用的帳號
|
|
|
10850 |
$conf["db::getDataTableColumn"]["selectedDataBase"]=$conf["dbName"];#連線到資料庫要選擇的資料庫
|
|
|
10851 |
$conf["db::getDataTableColumn"]["selectedDataTable"]=$conf["dtName"];#連線到資料庫要檢視的資料表
|
|
|
10852 |
#可省略參數:
|
|
|
10853 |
if(isset($conf["dbPass"])){
|
| 226 |
liveuser |
10854 |
|
| 3 |
liveuser |
10855 |
#$conf["dbPassword"]=$dbPassword;#連線到資料庫要用的密碼
|
|
|
10856 |
$conf["db::getDataTableColumn"]["dbPassword"]=$conf["dbPass"];
|
| 226 |
liveuser |
10857 |
|
| 3 |
liveuser |
10858 |
}#if end
|
| 226 |
liveuser |
10859 |
|
| 3 |
liveuser |
10860 |
#如果有設置 $conf["dbPort"]
|
|
|
10861 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
10862 |
|
| 3 |
liveuser |
10863 |
#$conf["dbPort"]=$dbPort;#連線到資料庫要用的port
|
|
|
10864 |
$conf["db::getDataTableColumn"]["dbPort"]=$conf["dbPass"];
|
| 226 |
liveuser |
10865 |
|
| 3 |
liveuser |
10866 |
}#if end
|
| 226 |
liveuser |
10867 |
|
| 3 |
liveuser |
10868 |
#備註:
|
|
|
10869 |
#查詢的功能有點弱,目前用getTableColumnDetailInfo替代
|
|
|
10870 |
$getDataTableColumn=db::getDataTableColumn($conf["db::getDataTableColumn"]);
|
|
|
10871 |
unset($conf["db::getDataTableColumn"]);
|
| 226 |
liveuser |
10872 |
|
| 3 |
liveuser |
10873 |
#如果查詢失敗
|
|
|
10874 |
if($getDataTableColumn["status"]==="false"){
|
| 226 |
liveuser |
10875 |
|
| 3 |
liveuser |
10876 |
#設置執行失敗
|
|
|
10877 |
$result["status"]="false";
|
| 226 |
liveuser |
10878 |
|
| 3 |
liveuser |
10879 |
#設置錯誤訊息
|
|
|
10880 |
$result["error"]=$getDataTableColumn["error"];
|
| 226 |
liveuser |
10881 |
|
| 3 |
liveuser |
10882 |
#回傳結果
|
|
|
10883 |
return $result;
|
| 226 |
liveuser |
10884 |
|
| 3 |
liveuser |
10885 |
}#if end
|
| 226 |
liveuser |
10886 |
|
| 3 |
liveuser |
10887 |
#初始化通過檢查
|
|
|
10888 |
$result["passed"]="true";
|
| 226 |
liveuser |
10889 |
|
| 3 |
liveuser |
10890 |
#針對每個要檢查的欄位
|
|
|
10891 |
foreach($conf["col"] as $colName){
|
| 226 |
liveuser |
10892 |
|
| 3 |
liveuser |
10893 |
#如果欄位 $colName 不存在
|
|
|
10894 |
if(!in_array($colName,$getDataTableColumn["columnName"])){
|
| 226 |
liveuser |
10895 |
|
| 3 |
liveuser |
10896 |
#設置欄位不存在的警告訊息
|
|
|
10897 |
$result["warning"][]="欄位 ".$colName." 不存在";
|
| 226 |
liveuser |
10898 |
|
| 3 |
liveuser |
10899 |
#設置未通過檢查
|
|
|
10900 |
$result["passed"]="false";
|
| 226 |
liveuser |
10901 |
|
| 3 |
liveuser |
10902 |
}#if end
|
| 226 |
liveuser |
10903 |
|
| 3 |
liveuser |
10904 |
}#foreach end
|
| 226 |
liveuser |
10905 |
|
| 3 |
liveuser |
10906 |
#設置執行正常
|
|
|
10907 |
$result["status"]="true";
|
| 226 |
liveuser |
10908 |
|
| 3 |
liveuser |
10909 |
#回傳結果
|
|
|
10910 |
return $result;
|
| 226 |
liveuser |
10911 |
|
| 3 |
liveuser |
10912 |
}#function checkTableColExists end
|
|
|
10913 |
|
|
|
10914 |
/*
|
|
|
10915 |
#函式說明:
|
|
|
10916 |
#檢查該資料庫是否存在,結果會回傳一個陣列。
|
|
|
10917 |
#回傳結果:
|
|
|
10918 |
#$result["status"],"true"代表執行成功;"false"代表執行失敗.
|
|
|
10919 |
#$result["error"],錯誤訊息.
|
|
|
10920 |
#$result["exist"],有為"true",無為"false".
|
|
|
10921 |
#$result["function"],當前執行的函數名稱.
|
|
|
10922 |
#必填參數:
|
| 177 |
liveuser |
10923 |
#$conf["dbAddress"],字串,爲mysql-Server的位置
|
| 3 |
liveuser |
10924 |
$conf["dbAddress"]=$dbAddress;
|
| 177 |
liveuser |
10925 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
|
| 3 |
liveuser |
10926 |
$conf["dbAccount"]=$dbAccount;
|
| 177 |
liveuser |
10927 |
#$conf["checkDataBaseName"],字串,爲要檢查是否存在的資料庫名稱
|
| 3 |
liveuser |
10928 |
$conf["checkDataBaseName"]="";
|
|
|
10929 |
#可省略參數:
|
|
|
10930 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
10931 |
#$conf["dbPassword"]="";
|
|
|
10932 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
|
|
|
10933 |
#$conf["dbPort"]="";
|
|
|
10934 |
#參考資料:
|
|
|
10935 |
#無.
|
|
|
10936 |
#備註:
|
|
|
10937 |
#無.
|
| 226 |
liveuser |
10938 |
*/
|
| 3 |
liveuser |
10939 |
public static function checkDataBaseExists($conf){
|
|
|
10940 |
|
|
|
10941 |
#初始化要回傳的變數
|
|
|
10942 |
$result=array();
|
|
|
10943 |
|
|
|
10944 |
#紀錄當前執行的函數名稱
|
|
|
10945 |
$result["function"]=__FUNCTION__;
|
|
|
10946 |
|
|
|
10947 |
#如果 $conf 不為陣列
|
|
|
10948 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
10949 |
|
| 3 |
liveuser |
10950 |
#設置執行失敗
|
|
|
10951 |
$result["status"]="false";
|
| 226 |
liveuser |
10952 |
|
| 3 |
liveuser |
10953 |
#設置執行錯誤訊息
|
|
|
10954 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
10955 |
|
|
|
10956 |
#如果傳入的參數為 null
|
|
|
10957 |
if($conf==null){
|
| 226 |
liveuser |
10958 |
|
| 3 |
liveuser |
10959 |
#設置執行錯誤訊息
|
|
|
10960 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
10961 |
|
| 3 |
liveuser |
10962 |
}#if end
|
|
|
10963 |
|
|
|
10964 |
#回傳結果
|
|
|
10965 |
return $result;
|
| 226 |
liveuser |
10966 |
|
| 3 |
liveuser |
10967 |
}#if end
|
|
|
10968 |
|
|
|
10969 |
#檢查參數
|
|
|
10970 |
#函式說明:
|
|
|
10971 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
10972 |
#回傳結果:
|
|
|
10973 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
10974 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
10975 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
10976 |
#必填參數:
|
|
|
10977 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
10978 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","checkDataBaseName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
10979 |
#可省略參數:
|
| 226 |
liveuser |
10980 |
#$conf["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
10981 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
10982 |
#備註:
|
|
|
10983 |
#功能與checkExistAndType函式相同
|
|
|
10984 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
10985 |
unset($conf["variableCheck"]["isexistMuti"]);
|
| 226 |
liveuser |
10986 |
|
| 3 |
liveuser |
10987 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
10988 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
10989 |
|
| 3 |
liveuser |
10990 |
#設置執行失敗
|
|
|
10991 |
$result["status"]="false";
|
| 226 |
liveuser |
10992 |
|
| 3 |
liveuser |
10993 |
#設置執行錯誤
|
|
|
10994 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
10995 |
|
| 3 |
liveuser |
10996 |
#回傳結果
|
|
|
10997 |
return $result;
|
| 226 |
liveuser |
10998 |
|
|
|
10999 |
}#if end
|
|
|
11000 |
|
| 3 |
liveuser |
11001 |
#如果 $checkResult["passed"] 等於 "false"
|
|
|
11002 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
11003 |
|
| 3 |
liveuser |
11004 |
#設置執行失敗
|
|
|
11005 |
$result["status"]="false";
|
| 226 |
liveuser |
11006 |
|
| 3 |
liveuser |
11007 |
#設置執行錯誤
|
|
|
11008 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
11009 |
|
| 3 |
liveuser |
11010 |
#回傳結果
|
|
|
11011 |
return $result;
|
| 226 |
liveuser |
11012 |
|
| 3 |
liveuser |
11013 |
}#if end
|
| 226 |
liveuser |
11014 |
|
| 3 |
liveuser |
11015 |
#取得資料庫列表的語法
|
|
|
11016 |
#查詢所有的資料庫列表,會回傳查詢的結果
|
|
|
11017 |
#$result["status"],執行是否正常,"true"為正常,"fasle"為不正常
|
|
|
11018 |
#$result["error"],爲錯誤訊息
|
|
|
11019 |
#$result["connectInformation"],爲回傳的mysql連線資訊。
|
|
|
11020 |
#$result["dbName"] 爲查詢的資料庫名稱陣列,第一筆資料庫名稱爲$result["dbName"][0],第二筆資料庫名稱爲$result["dbName"][1],其餘以此類推。
|
| 226 |
liveuser |
11021 |
#$result["dbCounts"] 爲資料庫的總筆數
|
| 3 |
liveuser |
11022 |
#必填參數:
|
|
|
11023 |
$conf["db"]["getDataBaseList"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
11024 |
$conf["db"]["getDataBaseList"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
11025 |
#可省略參數:
|
| 226 |
liveuser |
11026 |
|
| 3 |
liveuser |
11027 |
#如果 $conf["dbPassword"] 有設定
|
|
|
11028 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
11029 |
|
| 3 |
liveuser |
11030 |
$conf["db"]["getDataBaseList"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
11031 |
|
| 3 |
liveuser |
11032 |
}#if end
|
| 226 |
liveuser |
11033 |
|
| 3 |
liveuser |
11034 |
#如果 $conf["dbPort"] 有設定
|
|
|
11035 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
11036 |
|
| 3 |
liveuser |
11037 |
$conf["db"]["getDataBaseList"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的3306.
|
| 226 |
liveuser |
11038 |
|
| 3 |
liveuser |
11039 |
}#if end
|
| 226 |
liveuser |
11040 |
|
| 3 |
liveuser |
11041 |
$queryResult=db::getDataBaseList($conf["db"]["getDataBaseList"]);
|
|
|
11042 |
unset($conf["db"]["getDataBaseList"]);
|
| 226 |
liveuser |
11043 |
|
| 3 |
liveuser |
11044 |
#如果 $queryResult["status"] 等於 "fasle"
|
|
|
11045 |
if($queryResult["status"]=="false"){
|
| 226 |
liveuser |
11046 |
|
| 3 |
liveuser |
11047 |
#設置錯誤識別
|
|
|
11048 |
$result["status"]="false";
|
| 226 |
liveuser |
11049 |
|
| 3 |
liveuser |
11050 |
#設置錯誤訊息
|
|
|
11051 |
$result["error"]=$queryResult;
|
| 226 |
liveuser |
11052 |
|
| 3 |
liveuser |
11053 |
#回傳結果
|
|
|
11054 |
return $result;
|
| 226 |
liveuser |
11055 |
|
| 3 |
liveuser |
11056 |
}#if end
|
| 226 |
liveuser |
11057 |
|
| 3 |
liveuser |
11058 |
#有幾個資料庫就檢查該名稱有沒有重複
|
|
|
11059 |
for($i=0;$i<$queryResult["dbCounts"];$i++){
|
|
|
11060 |
|
| 226 |
liveuser |
11061 |
#檢查名稱是否相同
|
| 3 |
liveuser |
11062 |
if($queryResult["dbName"][$i]==$conf["checkDataBaseName"]){
|
| 226 |
liveuser |
11063 |
|
| 3 |
liveuser |
11064 |
#相同名稱代表資料庫重複
|
|
|
11065 |
$result["exist"]="true";
|
| 226 |
liveuser |
11066 |
|
| 3 |
liveuser |
11067 |
#跳出迴圈
|
|
|
11068 |
break;
|
| 226 |
liveuser |
11069 |
|
| 3 |
liveuser |
11070 |
}#判斷式結束
|
|
|
11071 |
|
|
|
11072 |
}#迴圈結束
|
|
|
11073 |
|
|
|
11074 |
#如果 $result["exist"] 沒有設定
|
|
|
11075 |
if(!isset($result["exist"])){
|
| 226 |
liveuser |
11076 |
|
| 3 |
liveuser |
11077 |
#代表都沒有相同的名稱就代表沒有重複
|
|
|
11078 |
$result["exist"]="false";
|
| 226 |
liveuser |
11079 |
|
| 3 |
liveuser |
11080 |
}#if end
|
| 226 |
liveuser |
11081 |
|
| 3 |
liveuser |
11082 |
#執行到這邊代表執行正常
|
|
|
11083 |
$result["status"]="true";
|
| 226 |
liveuser |
11084 |
|
| 3 |
liveuser |
11085 |
#回傳結果
|
| 226 |
liveuser |
11086 |
return $result;
|
|
|
11087 |
|
| 177 |
liveuser |
11088 |
}#function checkDataBaseExists end
|
| 3 |
liveuser |
11089 |
|
|
|
11090 |
/*
|
|
|
11091 |
#函式說明:
|
|
|
11092 |
#尋找特定資料庫裏特定資料表裏面特定欄位有無可用整數編號,可以指定數字的起點與終點,此函式會回傳可用的編號。
|
|
|
11093 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
| 226 |
liveuser |
11094 |
#$result["error"],錯誤訊息陣列
|
| 3 |
liveuser |
11095 |
#$result["function"],當前執行的函數.
|
|
|
11096 |
#$result["founded"],爲搜尋可以用的數字是否成功,"true"表示成功,"false"表示失敗.
|
|
|
11097 |
#$result["usableNumber"],爲可用的整數。
|
|
|
11098 |
#$result["sql"],執行的sql語法.
|
|
|
11099 |
#必填參數:
|
|
|
11100 |
#$conf["dbAddress"],字串,爲mysql-Server的位置.
|
|
|
11101 |
$conf["dbAddress"]=$dbAddress;
|
|
|
11102 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
|
|
|
11103 |
$conf["dbAccount"]=$dbAccount;
|
|
|
11104 |
#$conf["selectedDataBaseName"],字串,爲要檢查的資料庫名稱
|
|
|
11105 |
$conf["selectedDataBaseName"]=$dbName;
|
|
|
11106 |
#$conf["checkDataTableName"],字串,爲要檢查的資料表名稱
|
|
|
11107 |
$conf["checkDataTableName"]="";
|
|
|
11108 |
#$conf["conditionTargetName"]字串,用來判斷的資料表數值名稱
|
|
|
11109 |
$conf["conditionTargetName"]="";
|
|
|
11110 |
#$conf["startPoint"],字串,要執行的迴圈起點(資料的起始檢查點),須為整數.
|
|
|
11111 |
$conf["startPoint"]="";
|
|
|
11112 |
#$conf["endPoint"],字串,要執行的迴圈終點(資料的結束檢查點),須為整數.
|
|
|
11113 |
$conf["endPoint"]="";
|
|
|
11114 |
#可省略參數:
|
|
|
11115 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
11116 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
11117 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
|
|
|
11118 |
#$conf["dbPort"]="";
|
|
|
11119 |
#$conf["otherConditionTargetName"]=array();#查詢欄位項目可用數值的其它條件欄位名稱,爲陣列值。須搭配 $conf["otherConditionTargetValue"] 一起使用
|
|
|
11120 |
#$conf["otherConditionTargetName"]=array();
|
|
|
11121 |
#$conf["otherConditionTargetValue"]=array();#查詢欄位項目可用數值的其它條件欄位數值,爲陣列值。須搭配 $conf["otherConditionTargetName"] 一起使用
|
|
|
11122 |
#$conf["otherConditionTargetValue"]=array();
|
|
|
11123 |
#參考資料:
|
|
|
11124 |
#無.
|
|
|
11125 |
#備註:
|
|
|
11126 |
#無.
|
|
|
11127 |
*/
|
|
|
11128 |
public static function findUsableNumber($conf){
|
|
|
11129 |
|
|
|
11130 |
#初始化要回傳的內容
|
|
|
11131 |
$result=array();
|
|
|
11132 |
|
|
|
11133 |
#取得當前執行的函數名稱
|
|
|
11134 |
$result["function"]=__FUNCTION__;
|
|
|
11135 |
|
|
|
11136 |
#如果 $conf 不為陣列
|
|
|
11137 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
11138 |
|
| 3 |
liveuser |
11139 |
#設置執行失敗
|
|
|
11140 |
$result["status"]="false";
|
| 226 |
liveuser |
11141 |
|
| 3 |
liveuser |
11142 |
#設置執行錯誤訊息
|
|
|
11143 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
11144 |
|
|
|
11145 |
#如果傳入的參數為 null
|
|
|
11146 |
if($conf==null){
|
| 226 |
liveuser |
11147 |
|
| 3 |
liveuser |
11148 |
#設置執行錯誤訊息
|
|
|
11149 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
11150 |
|
| 3 |
liveuser |
11151 |
}#if end
|
|
|
11152 |
|
|
|
11153 |
#回傳結果
|
|
|
11154 |
return $result;
|
| 226 |
liveuser |
11155 |
|
| 3 |
liveuser |
11156 |
}#if end
|
|
|
11157 |
|
|
|
11158 |
#可用號碼的預設值,用int型態儲存.
|
|
|
11159 |
(int)$userableNumber=0;
|
|
|
11160 |
|
|
|
11161 |
#函式說明:
|
|
|
11162 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
11163 |
#回傳結果:
|
|
|
11164 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11165 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
11166 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
11167 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
11168 |
#必填參數:
|
|
|
11169 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
11170 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","checkDataTableName","conditionTargetName","startPoint","endPoint");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
11171 |
#可省略參數:
|
| 226 |
liveuser |
11172 |
$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string","string","string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
11173 |
#$conf["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
11174 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
11175 |
unset($conf["variableCheck"]["isexistMuti"]);
|
| 226 |
liveuser |
11176 |
|
| 3 |
liveuser |
11177 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
11178 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
11179 |
|
| 3 |
liveuser |
11180 |
#設置錯誤識別
|
|
|
11181 |
$result["status"]="false";
|
| 226 |
liveuser |
11182 |
|
| 3 |
liveuser |
11183 |
#設置錯誤訊息
|
|
|
11184 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
11185 |
|
| 3 |
liveuser |
11186 |
#回傳結果
|
|
|
11187 |
return $result;
|
| 226 |
liveuser |
11188 |
|
| 3 |
liveuser |
11189 |
}#if end
|
| 226 |
liveuser |
11190 |
|
| 3 |
liveuser |
11191 |
#如果 $checkResult["passed"] 等於 "false"
|
|
|
11192 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
11193 |
|
| 3 |
liveuser |
11194 |
#設置錯誤識別
|
|
|
11195 |
$result["status"]="false";
|
| 226 |
liveuser |
11196 |
|
| 3 |
liveuser |
11197 |
#設置錯誤訊息
|
|
|
11198 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
11199 |
|
| 3 |
liveuser |
11200 |
#回傳結果
|
|
|
11201 |
return $result;
|
| 226 |
liveuser |
11202 |
|
| 3 |
liveuser |
11203 |
}#if end
|
|
|
11204 |
|
|
|
11205 |
#從$startPoint開始到$endPoint結束,供執行 $endPoint-$startPoint 次。
|
|
|
11206 |
for($i=$conf["startPoint"];$i<=$conf["endPoint"];$i++){
|
|
|
11207 |
|
|
|
11208 |
#更新可用號碼
|
|
|
11209 |
$userableNumber=$i;
|
|
|
11210 |
|
|
|
11211 |
#查詢目標號碼是否已存在
|
|
|
11212 |
#函式說明:
|
|
|
11213 |
#一次取得資料庫、表的資料
|
|
|
11214 |
#回傳結果:
|
|
|
11215 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
11216 |
#$result["error"],錯誤訊息陣列。
|
|
|
11217 |
#$result["dataContent"],爲資料的內容。
|
|
|
11218 |
#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
11219 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
11220 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
11221 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
11222 |
#$result["sql"],執行的sql字串.
|
|
|
11223 |
#必填參數:
|
|
|
11224 |
$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"];#爲dbServer的位置。
|
|
|
11225 |
$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"];#爲登入dbServer的帳號。
|
|
|
11226 |
$conf["db"]["fastGetDbData"]["dbName"]=$conf["selectedDataBaseName"];#爲要存取的資料庫名稱
|
|
|
11227 |
$conf["db"]["fastGetDbData"]["tableName"]=$conf["checkDataTableName"];#爲要存取的資料表名稱
|
|
|
11228 |
$conf["db"]["fastGetDbData"]["columnYouWant"]=array($conf["conditionTargetName"]);#你想要的欄位!
|
|
|
11229 |
#可省略參數:
|
| 226 |
liveuser |
11230 |
|
| 3 |
liveuser |
11231 |
#如果 $conf["dbPassword"] 有設置
|
|
|
11232 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
11233 |
|
| 3 |
liveuser |
11234 |
$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"];#爲要存取dbServer的密碼
|
| 226 |
liveuser |
11235 |
|
| 3 |
liveuser |
11236 |
}#if end
|
| 226 |
liveuser |
11237 |
|
| 3 |
liveuser |
11238 |
#如果 $conf["dbPort"] 有設置
|
|
|
11239 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
11240 |
|
| 3 |
liveuser |
11241 |
$conf["db"]["fastGetDbData"]["dbPort"]=$conf["dbPort"];#爲要存取dbServer的port
|
| 226 |
liveuser |
11242 |
|
| 3 |
liveuser |
11243 |
}#if end
|
| 226 |
liveuser |
11244 |
|
| 3 |
liveuser |
11245 |
#要檢查可用數字的欄位為塞選的欄位
|
|
|
11246 |
$conf["db"]["fastGetDbData"]["WhereColumnName"][]=$conf["conditionTargetName"];
|
| 226 |
liveuser |
11247 |
|
| 3 |
liveuser |
11248 |
#如果 $conf["otherConditionTargetName"] 有設置
|
|
|
11249 |
if(isset($conf["otherConditionTargetName"])){
|
| 226 |
liveuser |
11250 |
|
|
|
11251 |
#針對 $conf["otherConditionTargetName"] 的每個元素
|
| 3 |
liveuser |
11252 |
foreach($conf["otherConditionTargetName"] as $columnName){
|
| 226 |
liveuser |
11253 |
|
| 3 |
liveuser |
11254 |
$conf["db"]["fastGetDbData"]["WhereColumnName"][]=$columnName;#用於判斷語句的欄位項目陣列.
|
| 226 |
liveuser |
11255 |
|
| 3 |
liveuser |
11256 |
}#foreach end
|
| 226 |
liveuser |
11257 |
|
| 3 |
liveuser |
11258 |
}#if end
|
| 226 |
liveuser |
11259 |
|
| 3 |
liveuser |
11260 |
#要檢查可用數字的欄位數值為塞選的欄位對應數值
|
|
|
11261 |
$conf["db"]["fastGetDbData"]["WhereColumnValue"][]=$userableNumber;
|
| 226 |
liveuser |
11262 |
|
| 3 |
liveuser |
11263 |
#如果 $conf["otherConditionTargetValue"] 有設置
|
|
|
11264 |
if(isset($conf["otherConditionTargetValue"])){
|
| 226 |
liveuser |
11265 |
|
| 3 |
liveuser |
11266 |
#針對每個 $conf["otherConditionTargetValue"] 元素
|
|
|
11267 |
foreach($conf["otherConditionTargetValue"] as $columnValue){
|
| 226 |
liveuser |
11268 |
|
| 3 |
liveuser |
11269 |
$conf["db"]["fastGetDbData"]["WhereColumnValue"][]=$columnValue;#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容.
|
| 226 |
liveuser |
11270 |
|
| 3 |
liveuser |
11271 |
}#foreach end
|
| 226 |
liveuser |
11272 |
|
| 3 |
liveuser |
11273 |
}#if end
|
| 226 |
liveuser |
11274 |
|
| 3 |
liveuser |
11275 |
#$conf["db"]["fastGetDbData"]["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
11276 |
#$conf["db"]["fastGetDbData"]["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
11277 |
#$conf["db"]["fastGetDbData"]["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
11278 |
#$conf["db"]["fastGetDbData"]["orderItem"]="";#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
|
|
11279 |
#$conf["db"]["fastGetDbData"]["ascORdesc"]="";#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
|
|
11280 |
#$conf["db"]["fastGetDbData"]["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
|
|
|
11281 |
#$conf["db"]["fastGetDbData"]["numLimit"]="30";#為要取幾筆資料,可以省略,省略則表示不限制數目。
|
|
|
11282 |
#$conf["db"]["fastGetDbData"]["groupBy"]=array("");#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
|
|
11283 |
$db["fastGetDbData"]=db::fastGetDbData($conf["db"]["fastGetDbData"]);
|
|
|
11284 |
unset($conf["db"]["fastGetDbData"]);
|
| 226 |
liveuser |
11285 |
|
| 3 |
liveuser |
11286 |
#如果取得資料失敗
|
|
|
11287 |
if($db["fastGetDbData"]["status"]=="false"){
|
| 226 |
liveuser |
11288 |
|
| 3 |
liveuser |
11289 |
#設置錯誤識別
|
|
|
11290 |
$result["status"]="false";
|
| 226 |
liveuser |
11291 |
|
| 3 |
liveuser |
11292 |
#設置錯誤訊息
|
|
|
11293 |
$result["error"]=$db["fastGetDbData"];
|
| 226 |
liveuser |
11294 |
|
| 3 |
liveuser |
11295 |
#回傳結果
|
|
|
11296 |
return $result;
|
| 226 |
liveuser |
11297 |
|
| 3 |
liveuser |
11298 |
}#if end
|
|
|
11299 |
|
|
|
11300 |
#如果該條件下沒有符合的資料
|
|
|
11301 |
if($db["fastGetDbData"]["dataCount"]==0){
|
| 226 |
liveuser |
11302 |
|
| 3 |
liveuser |
11303 |
#取得可用的編號
|
|
|
11304 |
$result["usableNumber"]=$i;
|
|
|
11305 |
|
|
|
11306 |
#設置有找到符合的數字
|
|
|
11307 |
$result["founded"]="true";
|
|
|
11308 |
|
|
|
11309 |
#跳出迴圈
|
|
|
11310 |
break;
|
| 226 |
liveuser |
11311 |
|
| 3 |
liveuser |
11312 |
}#if end
|
| 226 |
liveuser |
11313 |
|
| 3 |
liveuser |
11314 |
#反之該條件下有符合的資料
|
|
|
11315 |
else{
|
| 226 |
liveuser |
11316 |
|
| 3 |
liveuser |
11317 |
#設置沒有找到符合的數字
|
|
|
11318 |
$result["founded"]="false";
|
|
|
11319 |
|
|
|
11320 |
}#else end
|
|
|
11321 |
|
|
|
11322 |
}#for end
|
|
|
11323 |
|
|
|
11324 |
#執行到這邊代表執行正常
|
|
|
11325 |
$result["status"]="true";
|
|
|
11326 |
|
|
|
11327 |
#回傳結果
|
|
|
11328 |
return $result;
|
|
|
11329 |
|
|
|
11330 |
}#function findUsableNumber end
|
|
|
11331 |
|
|
|
11332 |
/*
|
|
|
11333 |
#函式說明:
|
|
|
11334 |
#取得特定的資料表資料
|
|
|
11335 |
#回傳的參數:
|
|
|
11336 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
11337 |
#$result["error"],錯誤訊息陣列。
|
|
|
11338 |
#$result["function"],當前執行的函數名稱
|
|
|
11339 |
#$result["sql"],執行的sql語法
|
|
|
11340 |
#$result["sqlQueryResult"]#爲資料連線處理完畢之後的結果,需要 sendQueryDataToVariabele 涵式來解析。
|
|
|
11341 |
#$result["dataCount"]#符合條件的資料筆數
|
|
|
11342 |
#必填參數:
|
|
|
11343 |
#$conf["dbAddress"],字串,爲mysql-Server的位置。
|
|
|
11344 |
$conf["dbAddress"]=$dbAddress;
|
|
|
11345 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號。
|
|
|
11346 |
$conf["dbAccount"]=$dbAccount;
|
|
|
11347 |
#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱。
|
|
|
11348 |
$conf["selectedDataBaseName"]=$dbName;
|
|
|
11349 |
#$conf["selectedDataTableName"],字串,爲欲選擇的資料表名稱。
|
|
|
11350 |
$conf["selectedDataTableName"]="";
|
| 226 |
liveuser |
11351 |
#可省略參數:
|
| 3 |
liveuser |
11352 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
11353 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
11354 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
|
|
|
11355 |
#$conf["dbPort"]="";
|
|
|
11356 |
#$conf["WhereColumnCombine"],字串陣列,用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
11357 |
#$conf["WhereColumnCombine"]=array("");
|
|
|
11358 |
#$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。
|
|
|
11359 |
#$conf["WhereColumnName"]=array("");
|
|
|
11360 |
#$conf["WhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
11361 |
#$conf["WhereColumnOperator"]=array("");
|
|
|
11362 |
#$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
|
|
11363 |
#$conf["WhereColumnValue"]=array("");
|
|
|
11364 |
#$conf["WhereColumnAndOr"],字串陣列,用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
11365 |
#$conf["WhereColumnAndOr"]=array("");
|
|
|
11366 |
#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
|
|
|
11367 |
#$conf["whereIn"]=array(array("colName",array("a","b","c")));
|
|
|
11368 |
#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
|
|
|
11369 |
#$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
|
|
|
11370 |
#$conf["orderItem"],字串,爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
|
|
11371 |
#$conf["orderItem"]="";
|
|
|
11372 |
#$conf["ascORdesc"],字串,爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
|
|
11373 |
#$conf["ascORdesc"]="";
|
|
|
11374 |
#$conf["numberStart"],字串,為從第幾筆開始讀取,預設為0,代筆第一筆。
|
|
|
11375 |
#$conf["numberStart"]="0";
|
|
|
11376 |
#$conf["number"],字串,為要取幾筆資料,可以省略,省略則表示不限制數目。
|
|
|
11377 |
#$conf["number"]="30"
|
|
|
11378 |
#$conf["groupBy"],字串陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
|
|
11379 |
#$conf["groupBy"]=array("");
|
|
|
11380 |
#參考資料:
|
|
|
11381 |
#http://stackoverflow.com/questions/5021243/mysql-query-multiple-group-by
|
|
|
11382 |
#備註:
|
|
|
11383 |
#無.
|
|
|
11384 |
*/
|
|
|
11385 |
public static function dataTableSelect(&$conf){
|
|
|
11386 |
|
|
|
11387 |
#初始化要回傳的變數
|
|
|
11388 |
$result=array();
|
| 226 |
liveuser |
11389 |
|
| 3 |
liveuser |
11390 |
#取得當前執行的函數名稱
|
|
|
11391 |
$result["function"]=__FUNCTION__;
|
| 226 |
liveuser |
11392 |
|
| 3 |
liveuser |
11393 |
#如果 $conf 不為陣列
|
|
|
11394 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
11395 |
|
| 3 |
liveuser |
11396 |
#設置執行失敗
|
|
|
11397 |
$result["status"]="false";
|
| 226 |
liveuser |
11398 |
|
| 3 |
liveuser |
11399 |
#設置執行錯誤訊息
|
|
|
11400 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
11401 |
|
|
|
11402 |
#如果傳入的參數為 null
|
|
|
11403 |
if($conf==null){
|
| 226 |
liveuser |
11404 |
|
| 3 |
liveuser |
11405 |
#設置執行錯誤訊息
|
|
|
11406 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
11407 |
|
| 3 |
liveuser |
11408 |
}#if end
|
|
|
11409 |
|
|
|
11410 |
#回傳結果
|
|
|
11411 |
return $result;
|
| 226 |
liveuser |
11412 |
|
| 3 |
liveuser |
11413 |
}#if end
|
| 226 |
liveuser |
11414 |
|
| 3 |
liveuser |
11415 |
#檢查參數
|
|
|
11416 |
#函式說明:
|
|
|
11417 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
11418 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
11419 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
11420 |
#$result["function"],當前執行的函式名稱.
|
|
|
11421 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
11422 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
11423 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
11424 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
11425 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
11426 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
11427 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
11428 |
#必填參數:
|
|
|
11429 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
11430 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
11431 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
11432 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName");
|
| 226 |
liveuser |
11433 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
11434 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string");
|
|
|
11435 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
11436 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
11437 |
#可省略參數:
|
|
|
11438 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
11439 |
#$conf["canBeEmptyString"]="false";
|
|
|
11440 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
11441 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort","WhereColumnCombine","WhereColumnName","WhereColumnOperator","WhereColumnValue","WhereColumnAndOr","orderItem","ascORdesc","numberStart","number","groupBy","whereIn","whereNotIn");
|
| 226 |
liveuser |
11442 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
11443 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","array","array","array","array","string","string","string","string","array","array","array");
|
|
|
11444 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
11445 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null,null,null,null,null,null,"0",null,null,null,null);
|
|
|
11446 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
11447 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("WhereColumnName","WhereColumnValue");
|
|
|
11448 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("WhereColumnValue","WhereColumnOperator");
|
|
|
11449 |
#參考資料:
|
|
|
11450 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
11451 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
11452 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
11453 |
|
| 3 |
liveuser |
11454 |
#如果檢查失敗
|
|
|
11455 |
if($checkResult["status"]==="false"){
|
| 226 |
liveuser |
11456 |
|
| 3 |
liveuser |
11457 |
#設置執行失敗的訊息
|
|
|
11458 |
$result["status"]="false";
|
| 226 |
liveuser |
11459 |
|
| 3 |
liveuser |
11460 |
#設置錯誤訊息
|
|
|
11461 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
11462 |
|
| 3 |
liveuser |
11463 |
#回傳結果
|
|
|
11464 |
return $result;
|
| 226 |
liveuser |
11465 |
|
| 3 |
liveuser |
11466 |
}#if end
|
| 226 |
liveuser |
11467 |
|
| 3 |
liveuser |
11468 |
#如果檢查不通過
|
|
|
11469 |
if($checkResult["passed"]==="false"){
|
| 226 |
liveuser |
11470 |
|
| 3 |
liveuser |
11471 |
#設置執行失敗的訊息
|
|
|
11472 |
$result["status"]="false";
|
| 226 |
liveuser |
11473 |
|
| 3 |
liveuser |
11474 |
#設置錯誤訊息
|
|
|
11475 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
11476 |
|
| 3 |
liveuser |
11477 |
#回傳結果
|
|
|
11478 |
return $result;
|
| 226 |
liveuser |
11479 |
|
| 3 |
liveuser |
11480 |
}#if end
|
| 226 |
liveuser |
11481 |
|
| 3 |
liveuser |
11482 |
#連線到資料庫
|
|
|
11483 |
#函式說明:
|
|
|
11484 |
#連線到資料庫,結果會回傳一個陣列
|
|
|
11485 |
#$result["status"],若連線成功則爲"true",連線失敗則爲"false".
|
|
|
11486 |
#$result["connectInformation"],爲回傳的mysql連線資訊.
|
| 177 |
liveuser |
11487 |
#$result["error"],錯誤訊息.
|
|
|
11488 |
#$result["function"],當前執行的函數名稱.
|
| 3 |
liveuser |
11489 |
#必填參數:
|
|
|
11490 |
$conf["db"]["dbConnect"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
11491 |
$conf["db"]["dbConnect"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
11492 |
#$conf["dbName"],字串,爲要連的資料庫名稱
|
|
|
11493 |
$conf["db"]["dbConnect"]["dbName"]=$conf["selectedDataBaseName"];
|
|
|
11494 |
#可省略參數:
|
| 226 |
liveuser |
11495 |
|
| 3 |
liveuser |
11496 |
#如果 $conf["dbPassword"] 有設定
|
|
|
11497 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
11498 |
|
| 3 |
liveuser |
11499 |
$conf["db"]["dbConnect"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
11500 |
|
| 3 |
liveuser |
11501 |
}#if end
|
| 226 |
liveuser |
11502 |
|
| 3 |
liveuser |
11503 |
#如果 $conf["dbPort"] 有設定
|
|
|
11504 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
11505 |
|
| 3 |
liveuser |
11506 |
$conf["db"]["dbConnect"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
11507 |
|
| 3 |
liveuser |
11508 |
}#if end
|
| 226 |
liveuser |
11509 |
|
| 3 |
liveuser |
11510 |
$con=db::dbConnect($conf["db"]["dbConnect"]);
|
|
|
11511 |
unset($conf["db"]);
|
|
|
11512 |
|
|
|
11513 |
#如果連線到資料庫失敗
|
|
|
11514 |
if($con["status"]==="false"){
|
| 226 |
liveuser |
11515 |
|
| 3 |
liveuser |
11516 |
#設置執行失敗
|
|
|
11517 |
$result["status"]="false";
|
| 226 |
liveuser |
11518 |
|
| 3 |
liveuser |
11519 |
#設置執行錯誤訊息
|
|
|
11520 |
$result["error"]=$con;
|
| 226 |
liveuser |
11521 |
|
| 3 |
liveuser |
11522 |
#回傳結果
|
|
|
11523 |
return $result;
|
| 226 |
liveuser |
11524 |
|
| 3 |
liveuser |
11525 |
}#if end
|
| 226 |
liveuser |
11526 |
|
|
|
11527 |
#var_dump($con);
|
|
|
11528 |
|
| 3 |
liveuser |
11529 |
#取得mysqli物件
|
|
|
11530 |
$mysqli=$con["connectInformation"];
|
| 226 |
liveuser |
11531 |
|
| 3 |
liveuser |
11532 |
#如果 $conf["WhereColumnAndOr"] 沒有設定,但是有指定判斷條件的欄位
|
|
|
11533 |
if(!isset($conf["WhereColumnAndOr"]) && isset($conf["WhereColumnName"])){
|
|
|
11534 |
|
|
|
11535 |
#則$conf["WhereColumnAndOr"]爲有 count($conf["WhereColumnName"])-1 個 "AND" 的字串陣列
|
|
|
11536 |
for($i=0;$i<(count($conf["WhereColumnName"])-1);$i++){
|
|
|
11537 |
|
|
|
11538 |
$conf["WhereColumnAndOr"][$i]="AND";
|
|
|
11539 |
|
|
|
11540 |
}#for end
|
| 226 |
liveuser |
11541 |
|
| 3 |
liveuser |
11542 |
}#if end
|
|
|
11543 |
|
|
|
11544 |
#如果 $conf["WhereColumnCombine"] 沒有設定,但是有指定判斷條件的欄位
|
|
|
11545 |
if(!isset($conf["WhereColumnCombine"]) && isset($conf["WhereColumnName"])){
|
|
|
11546 |
|
|
|
11547 |
#則 $conf["WhereColumnCombine"] 爲有 count($conf["WhereColumnName"]) 個 "" 的字串陣列
|
|
|
11548 |
for($i=0;$i<count($conf["WhereColumnName"]);$i++){
|
|
|
11549 |
|
|
|
11550 |
$conf["WhereColumnCombine"][$i]="";
|
|
|
11551 |
|
|
|
11552 |
}#for end
|
| 226 |
liveuser |
11553 |
|
| 3 |
liveuser |
11554 |
}#if end
|
|
|
11555 |
|
|
|
11556 |
#如果 $conf["WhereColumnOperator"] 沒有設定,但是有設定判斷條件的欄位
|
|
|
11557 |
if(!isset($conf["WhereColumnOperator"]) && isset($conf["WhereColumnName"])){
|
|
|
11558 |
|
|
|
11559 |
#則 $conf["WhereColumnOperator"] 爲有 count($conf["WhereColumnName"]) 個 "" 的字串陣列
|
|
|
11560 |
for($i=0;$i<count($conf["WhereColumnName"]);$i++){
|
|
|
11561 |
|
|
|
11562 |
$conf["WhereColumnOperator"][$i]="=";
|
|
|
11563 |
|
|
|
11564 |
}#for end
|
|
|
11565 |
|
|
|
11566 |
}#if end
|
|
|
11567 |
|
|
|
11568 |
#如果 $conf"ascORdesc"] 沒有設定,則不指定遞增或遞減排序
|
|
|
11569 |
if(!isset($conf["ascORdesc"])){
|
| 226 |
liveuser |
11570 |
|
| 3 |
liveuser |
11571 |
#排序變數爲空字串
|
|
|
11572 |
$conf["ascORdesc"]="";
|
|
|
11573 |
|
|
|
11574 |
}#if end
|
|
|
11575 |
|
|
|
11576 |
#如果 $conf["number"] 沒設定,則不限定要取幾筆資料
|
|
|
11577 |
if(!isset($conf["number"])){
|
|
|
11578 |
|
|
|
11579 |
#限定筆數爲空字串
|
|
|
11580 |
$queryStringLimit = "";
|
|
|
11581 |
|
| 226 |
liveuser |
11582 |
}#if end
|
| 3 |
liveuser |
11583 |
|
|
|
11584 |
#如果 $conf["number"] 不爲空,則限定要取出幾筆
|
|
|
11585 |
else{
|
| 226 |
liveuser |
11586 |
|
| 3 |
liveuser |
11587 |
#如果 $conf["numberStart"] 有設定
|
|
|
11588 |
if(isset($conf["numberStart"])){
|
| 226 |
liveuser |
11589 |
|
| 3 |
liveuser |
11590 |
$queryStringLimit = " LIMIT ".$conf["numberStart"]." , ".$conf["number"]." ";
|
| 226 |
liveuser |
11591 |
|
| 3 |
liveuser |
11592 |
}#if end
|
| 226 |
liveuser |
11593 |
|
| 3 |
liveuser |
11594 |
#反之 $conf["numberStart"] 沒有設定
|
|
|
11595 |
else{
|
| 226 |
liveuser |
11596 |
|
| 3 |
liveuser |
11597 |
$queryStringLimit = " LIMIT 0 , ".$conf["number"]." ";
|
|
|
11598 |
|
|
|
11599 |
}#else end
|
|
|
11600 |
|
|
|
11601 |
}#else end
|
|
|
11602 |
|
| 226 |
liveuser |
11603 |
#如果存在 $conf["orderItem"]
|
| 3 |
liveuser |
11604 |
if(isset($conf["orderItem"])){
|
|
|
11605 |
|
|
|
11606 |
#如果排序的依據是 rand() 或 RAND()
|
|
|
11607 |
if($conf["orderItem"] == "rand()" || $conf["orderItem"] == "RAND()"){
|
| 226 |
liveuser |
11608 |
|
| 3 |
liveuser |
11609 |
# 依 $order 為排序依據,進行 隨機 排序
|
| 226 |
liveuser |
11610 |
$queryStringOrder = " ORDER BY ".$conf["orderItem"]." ".$conf["ascORdesc"]." ";
|
| 3 |
liveuser |
11611 |
|
|
|
11612 |
}#if end
|
|
|
11613 |
|
|
|
11614 |
#反之 $order 為排序依據
|
|
|
11615 |
else{
|
| 226 |
liveuser |
11616 |
|
| 3 |
liveuser |
11617 |
#爲 acs 或 desc, 依 $order 為排序依據,進行 asc OR desc 排序
|
| 226 |
liveuser |
11618 |
$queryStringOrder = " ORDER BY ".$conf["orderItem"]." ".$conf["ascORdesc"]." ";
|
| 3 |
liveuser |
11619 |
|
|
|
11620 |
}#else end
|
|
|
11621 |
|
|
|
11622 |
}#if end
|
| 226 |
liveuser |
11623 |
|
| 3 |
liveuser |
11624 |
#反之 不存在
|
|
|
11625 |
else{
|
| 226 |
liveuser |
11626 |
|
| 3 |
liveuser |
11627 |
#預設為不指定
|
|
|
11628 |
$queryStringOrder="";
|
| 226 |
liveuser |
11629 |
|
| 3 |
liveuser |
11630 |
}#else end
|
|
|
11631 |
|
|
|
11632 |
#如果有設定 $conf["WhereColumnName"] 參數
|
|
|
11633 |
if(isset($conf["WhereColumnName"])){
|
|
|
11634 |
|
|
|
11635 |
#條件判斷的起始語句
|
|
|
11636 |
$conf["whereCondition"]="WHERE ";
|
|
|
11637 |
|
|
|
11638 |
#有幾個判斷用的欄位就執行幾次
|
|
|
11639 |
for($i=0;$i<count($conf["WhereColumnName"]);$i++){
|
|
|
11640 |
|
|
|
11641 |
#如果是左掛號
|
|
|
11642 |
if($conf["WhereColumnCombine"][$i]=="("){
|
|
|
11643 |
|
|
|
11644 |
$conf["whereCondition"]=$conf["whereCondition"]." ".$conf["WhereColumnCombine"][$i]." ";
|
| 226 |
liveuser |
11645 |
|
| 3 |
liveuser |
11646 |
}#if end
|
|
|
11647 |
|
|
|
11648 |
#如果欄位數值不是字串,也不是NULL
|
|
|
11649 |
if(gettype($conf["WhereColumnValue"][$i])!=="string" && $conf["WhereColumnValue"][$i]!==NULL){
|
| 226 |
liveuser |
11650 |
|
| 3 |
liveuser |
11651 |
#設置執行失敗
|
|
|
11652 |
$result["status"]="false";
|
| 226 |
liveuser |
11653 |
|
| 3 |
liveuser |
11654 |
#設置執行錯誤
|
|
|
11655 |
$result["error"][]="WhereColumnValue 參數須為陣列字串";
|
| 226 |
liveuser |
11656 |
|
| 3 |
liveuser |
11657 |
#回傳結果
|
|
|
11658 |
return $result;
|
| 226 |
liveuser |
11659 |
|
| 3 |
liveuser |
11660 |
}#if end
|
|
|
11661 |
|
|
|
11662 |
#結合各個條件語句
|
|
|
11663 |
$conf["whereCondition"]=$conf["whereCondition"]." `".$conf["WhereColumnName"][$i]."` ";
|
|
|
11664 |
$conf["whereCondition"]=$conf["whereCondition"]." ".$conf["WhereColumnOperator"][$i]." ";
|
|
|
11665 |
$conf["whereCondition"]=$conf["whereCondition"]." '".mysqli_real_escape_string($mysqli,$conf["WhereColumnValue"][$i])."' ";
|
| 226 |
liveuser |
11666 |
|
| 3 |
liveuser |
11667 |
#如果右掛號
|
|
|
11668 |
if($conf["WhereColumnCombine"][$i]==")"){
|
|
|
11669 |
|
|
|
11670 |
$conf["whereCondition"]=$conf["whereCondition"]." ".$conf["WhereColumnCombine"][$i]." ";
|
| 226 |
liveuser |
11671 |
|
| 3 |
liveuser |
11672 |
}#if end
|
|
|
11673 |
|
|
|
11674 |
#如果不是最後一筆項目,就放置AND or OR
|
|
|
11675 |
if($i<count($conf["WhereColumnName"])-1){
|
|
|
11676 |
|
|
|
11677 |
$conf["whereCondition"]=$conf["whereCondition"]." ".$conf["WhereColumnAndOr"][$i]." ";
|
|
|
11678 |
|
| 226 |
liveuser |
11679 |
}#if end
|
|
|
11680 |
|
|
|
11681 |
}#for end
|
|
|
11682 |
|
| 3 |
liveuser |
11683 |
}#if end
|
|
|
11684 |
|
|
|
11685 |
#反之,套件變數設爲空字串
|
|
|
11686 |
else{
|
|
|
11687 |
|
|
|
11688 |
$conf["whereCondition"]="";
|
|
|
11689 |
|
|
|
11690 |
}#else end
|
| 226 |
liveuser |
11691 |
|
| 3 |
liveuser |
11692 |
#初始化 where in 語句
|
|
|
11693 |
$whereIn=" ";
|
|
|
11694 |
|
|
|
11695 |
#如果 $conf["whereIn"] 存在
|
|
|
11696 |
if(isset($conf["whereIn"])){
|
| 226 |
liveuser |
11697 |
|
| 3 |
liveuser |
11698 |
#如果 $conf["whereCondition"] 等於 空
|
|
|
11699 |
if($conf["whereCondition"]!==""){
|
| 226 |
liveuser |
11700 |
|
| 3 |
liveuser |
11701 |
#先加上串接的 AND
|
|
|
11702 |
$whereIn=$whereIn."AND ";
|
| 226 |
liveuser |
11703 |
|
| 3 |
liveuser |
11704 |
}#if end
|
| 226 |
liveuser |
11705 |
|
| 3 |
liveuser |
11706 |
#反之為第一個where條件
|
|
|
11707 |
else{
|
| 226 |
liveuser |
11708 |
|
| 3 |
liveuser |
11709 |
#設置where開頭
|
|
|
11710 |
$whereIn=$whereIn."where ";
|
| 226 |
liveuser |
11711 |
|
| 3 |
liveuser |
11712 |
}#else end
|
| 226 |
liveuser |
11713 |
|
| 3 |
liveuser |
11714 |
#針對每個要用 in 條件判斷的語句
|
|
|
11715 |
for($i=0;$i<count($conf["whereIn"]);$i++){
|
| 226 |
liveuser |
11716 |
|
| 3 |
liveuser |
11717 |
#取得要判斷的欄位
|
|
|
11718 |
$col=$conf["whereIn"][$i][0];
|
| 226 |
liveuser |
11719 |
|
| 3 |
liveuser |
11720 |
#加上 in 的開頭語句
|
|
|
11721 |
$whereIn=$whereIn."`".$col."` in(";
|
| 226 |
liveuser |
11722 |
|
| 3 |
liveuser |
11723 |
#針對每個 in 的值
|
|
|
11724 |
for($j=0;$j<count($conf["whereIn"][$i][1]);$j++){
|
| 226 |
liveuser |
11725 |
|
| 3 |
liveuser |
11726 |
#串接條件
|
|
|
11727 |
$whereIn=$whereIn."'".mysqli_real_escape_string($mysqli,$conf["whereIn"][$i][1][$j])."'";
|
| 226 |
liveuser |
11728 |
|
| 3 |
liveuser |
11729 |
#如果不是最後一個條件
|
|
|
11730 |
if($j!==count($conf["whereIn"][$i][1])-1){
|
| 226 |
liveuser |
11731 |
|
| 3 |
liveuser |
11732 |
#後面還有條件
|
|
|
11733 |
$whereIn=$whereIn.",";
|
| 226 |
liveuser |
11734 |
|
| 3 |
liveuser |
11735 |
}#if end
|
| 226 |
liveuser |
11736 |
|
| 3 |
liveuser |
11737 |
#反之是最後一個條件
|
|
|
11738 |
else{
|
| 226 |
liveuser |
11739 |
|
| 3 |
liveuser |
11740 |
#後面沒有條件
|
|
|
11741 |
$whereIn=$whereIn.")";
|
| 226 |
liveuser |
11742 |
|
| 3 |
liveuser |
11743 |
}#else end
|
| 226 |
liveuser |
11744 |
|
| 3 |
liveuser |
11745 |
}#for end
|
| 226 |
liveuser |
11746 |
|
| 3 |
liveuser |
11747 |
}#for end
|
| 226 |
liveuser |
11748 |
|
| 3 |
liveuser |
11749 |
#如果沒有in的條件
|
|
|
11750 |
if($whereIn===" AND `".$col."` in(" OR $whereIn===" AND " OR $whereIn===" " OR $whereIn===" where "){
|
| 226 |
liveuser |
11751 |
|
| 3 |
liveuser |
11752 |
#設為 ""
|
|
|
11753 |
$whereIn="";
|
| 226 |
liveuser |
11754 |
|
| 3 |
liveuser |
11755 |
}#if end
|
| 226 |
liveuser |
11756 |
|
| 3 |
liveuser |
11757 |
}#if end
|
| 226 |
liveuser |
11758 |
|
| 3 |
liveuser |
11759 |
#串接 where in 語句
|
|
|
11760 |
$conf["whereCondition"]=$conf["whereCondition"].$whereIn;
|
| 226 |
liveuser |
11761 |
|
| 3 |
liveuser |
11762 |
#初始化 where not in 語句
|
| 226 |
liveuser |
11763 |
$whereNotIn=" ";
|
|
|
11764 |
|
| 3 |
liveuser |
11765 |
#如果 $conf["whereNotIn"] 存在
|
|
|
11766 |
if(isset($conf["whereNotIn"])){
|
| 226 |
liveuser |
11767 |
|
| 3 |
liveuser |
11768 |
#如果 $conf["whereCondition"] 等於 空
|
|
|
11769 |
if(str_replace(" ","",$conf["whereCondition"])!==""){
|
| 226 |
liveuser |
11770 |
|
| 3 |
liveuser |
11771 |
#先加上串接的 AND
|
|
|
11772 |
$whereNotIn=$whereNotIn."AND ";
|
| 226 |
liveuser |
11773 |
|
| 3 |
liveuser |
11774 |
}#if end
|
| 226 |
liveuser |
11775 |
|
| 3 |
liveuser |
11776 |
#反之為第一個where條件
|
|
|
11777 |
else{
|
| 226 |
liveuser |
11778 |
|
| 3 |
liveuser |
11779 |
#設置where開頭
|
|
|
11780 |
$whereNotIn=$whereNotIn."where ";
|
| 226 |
liveuser |
11781 |
|
| 3 |
liveuser |
11782 |
}#else end
|
| 226 |
liveuser |
11783 |
|
| 3 |
liveuser |
11784 |
#針對每個要用 in 條件判斷的語句
|
|
|
11785 |
for($i=0;$i<count($conf["whereNotIn"]);$i++){
|
| 226 |
liveuser |
11786 |
|
| 3 |
liveuser |
11787 |
#取得要判斷的欄位
|
|
|
11788 |
$col=$conf["whereNotIn"][$i][0];
|
| 226 |
liveuser |
11789 |
|
| 3 |
liveuser |
11790 |
#加上 in 的開頭語句
|
|
|
11791 |
$whereNotIn=$whereNotIn."`".$col."` not in(";
|
| 226 |
liveuser |
11792 |
|
| 3 |
liveuser |
11793 |
#針對每個 in 的值
|
|
|
11794 |
for($j=0;$j<count($conf["whereNotIn"][$i][1]);$j++){
|
| 226 |
liveuser |
11795 |
|
| 3 |
liveuser |
11796 |
#串接條件
|
|
|
11797 |
$whereNotIn=$whereNotIn."'".mysqli_real_escape_string($mysqli,$conf["whereNotIn"][$i][1][$j])."'";
|
| 226 |
liveuser |
11798 |
|
| 3 |
liveuser |
11799 |
#如果不是最後一個條件
|
|
|
11800 |
if($j!==count($conf["whereNotIn"][$i][1])-1){
|
| 226 |
liveuser |
11801 |
|
| 3 |
liveuser |
11802 |
#後面還有條件
|
|
|
11803 |
$whereNotIn=$whereNotIn.",";
|
| 226 |
liveuser |
11804 |
|
| 3 |
liveuser |
11805 |
}#if end
|
| 226 |
liveuser |
11806 |
|
| 3 |
liveuser |
11807 |
#反之是最後一個條件
|
|
|
11808 |
else{
|
| 226 |
liveuser |
11809 |
|
| 3 |
liveuser |
11810 |
#後面沒有條件
|
|
|
11811 |
$whereNotIn=$whereNotIn.")";
|
| 226 |
liveuser |
11812 |
|
| 3 |
liveuser |
11813 |
}#else end
|
| 226 |
liveuser |
11814 |
|
| 3 |
liveuser |
11815 |
}#for end
|
| 226 |
liveuser |
11816 |
|
| 3 |
liveuser |
11817 |
}#for end
|
| 226 |
liveuser |
11818 |
|
| 3 |
liveuser |
11819 |
#如果沒有in的條件
|
|
|
11820 |
if($whereNotIn===" AND `".$col."` not in(" OR $whereNotIn===" AND " OR $whereNotIn===" " OR $whereNotIn===" where "){
|
| 226 |
liveuser |
11821 |
|
| 3 |
liveuser |
11822 |
#設為 ""
|
|
|
11823 |
$whereNotIn="";
|
| 226 |
liveuser |
11824 |
|
| 3 |
liveuser |
11825 |
}#if end
|
| 226 |
liveuser |
11826 |
|
| 3 |
liveuser |
11827 |
}#if end
|
|
|
11828 |
|
|
|
11829 |
#串接 where not in 語句
|
|
|
11830 |
$conf["whereCondition"]=$conf["whereCondition"].$whereNotIn;
|
|
|
11831 |
|
|
|
11832 |
#如果 $conf["groupBy"] 有指定
|
|
|
11833 |
if(isset($conf["groupBy"])){
|
|
|
11834 |
|
|
|
11835 |
#初始化分類語句的字串
|
|
|
11836 |
$groupByQueryStr="GROUP BY ";
|
|
|
11837 |
|
|
|
11838 |
#設定要以哪些欄位爲分組的依據
|
|
|
11839 |
for($i=0;$i<count($conf["groupBy"]);$i++){
|
| 226 |
liveuser |
11840 |
|
| 3 |
liveuser |
11841 |
#如果不是最後一筆
|
|
|
11842 |
if($i!=count($conf["groupBy"])-1){
|
| 226 |
liveuser |
11843 |
|
| 3 |
liveuser |
11844 |
#語法裡面含有 , 代表還有其他欄位
|
|
|
11845 |
$groupByQueryStr=$groupByQueryStr." `".$conf["groupBy"][$i]."` , ";
|
| 226 |
liveuser |
11846 |
|
| 3 |
liveuser |
11847 |
}#if end
|
| 226 |
liveuser |
11848 |
|
| 3 |
liveuser |
11849 |
#反之是最後一筆資料
|
|
|
11850 |
else{
|
| 226 |
liveuser |
11851 |
|
| 3 |
liveuser |
11852 |
#語法結尾沒有 , 代表沒有其他欄位
|
|
|
11853 |
$groupByQueryStr=$groupByQueryStr." `".$conf["groupBy"][$i]."` ";
|
| 226 |
liveuser |
11854 |
|
| 3 |
liveuser |
11855 |
}#else end
|
| 226 |
liveuser |
11856 |
|
| 3 |
liveuser |
11857 |
}#for end
|
| 226 |
liveuser |
11858 |
|
| 3 |
liveuser |
11859 |
#取得分組的語法
|
|
|
11860 |
$conf["groupBy"]=$groupByQueryStr;
|
| 226 |
liveuser |
11861 |
|
| 3 |
liveuser |
11862 |
}#if end
|
|
|
11863 |
|
|
|
11864 |
#如果 $conf["groupBy"] 沒有設定
|
|
|
11865 |
else{
|
|
|
11866 |
|
|
|
11867 |
#則將其設爲空值
|
|
|
11868 |
$conf["groupBy"]="";
|
| 226 |
liveuser |
11869 |
|
| 3 |
liveuser |
11870 |
}#else end
|
| 226 |
liveuser |
11871 |
|
| 3 |
liveuser |
11872 |
#要執行的sql語法
|
|
|
11873 |
$result["sql"]=$queryStringFinal="SELECT * FROM `".$conf["selectedDataBaseName"]."`.`".$conf["selectedDataTableName"]."` ".$conf["whereCondition"]." ".$conf["groupBy"]." ".$queryStringOrder.$queryStringLimit;
|
|
|
11874 |
|
|
|
11875 |
#執行 SQL 語法
|
|
|
11876 |
#函式說明:
|
|
|
11877 |
#執行mysql指令
|
|
|
11878 |
#回傳結果::
|
|
|
11879 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
11880 |
#$result["error"],錯誤訊息的陣列
|
|
|
11881 |
#$result["function"],當前執行的涵式
|
|
|
11882 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
11883 |
#$result["queryString"],mysql查詢的語言
|
|
|
11884 |
#查詢號的解果,需要解析。
|
|
|
11885 |
#必填參數:
|
|
|
11886 |
$conf["db::execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
11887 |
$conf["db::execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
11888 |
$conf["db::execMysqlQuery"]["dbSql"]=$queryStringFinal;#要執行sql語法
|
|
|
11889 |
#可省略參數:
|
| 226 |
liveuser |
11890 |
|
| 3 |
liveuser |
11891 |
#如果 $conf["dbPassword"] 有設定
|
|
|
11892 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
11893 |
|
| 3 |
liveuser |
11894 |
$conf["db::execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
11895 |
|
| 3 |
liveuser |
11896 |
}#if end
|
| 226 |
liveuser |
11897 |
|
| 3 |
liveuser |
11898 |
#如果 $conf["dbPort"] 有設定
|
|
|
11899 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
11900 |
|
| 3 |
liveuser |
11901 |
$conf["db::execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的3306.
|
| 226 |
liveuser |
11902 |
|
| 3 |
liveuser |
11903 |
}#if end
|
|
|
11904 |
#$conf["dbLink"],物件,mysqli物件,由mysqli_connect()回傳的物件內容,若為數值則改用賬號密碼等資訊進行連線,反之則沿用連線物件.
|
| 226 |
liveuser |
11905 |
$conf["db::execMysqlQuery"]["dbLink"]=$mysqli;
|
| 3 |
liveuser |
11906 |
$execMysqlQuery=db::execMysqlQuery($conf["db::execMysqlQuery"]);
|
|
|
11907 |
unset($conf["db::execMysqlQuery"]);
|
| 226 |
liveuser |
11908 |
|
| 3 |
liveuser |
11909 |
#如果執行錯誤
|
|
|
11910 |
if($execMysqlQuery["status"]=="false"){
|
| 226 |
liveuser |
11911 |
|
| 3 |
liveuser |
11912 |
#設置執行錯誤的識別
|
|
|
11913 |
$result["status"]="false";
|
| 226 |
liveuser |
11914 |
|
| 3 |
liveuser |
11915 |
#設置錯誤訊息
|
|
|
11916 |
$result["error"]=$execMysqlQuery;
|
| 226 |
liveuser |
11917 |
|
| 3 |
liveuser |
11918 |
#回傳錯誤訊息
|
|
|
11919 |
return $result;
|
| 226 |
liveuser |
11920 |
|
| 3 |
liveuser |
11921 |
}#if end
|
|
|
11922 |
|
|
|
11923 |
#取得查詢後的結果
|
|
|
11924 |
$result["sqlQueryResult"]=$execMysqlQuery["queryResource"];
|
|
|
11925 |
|
|
|
11926 |
#取得符合條件的資料筆數
|
|
|
11927 |
$result["dataCount"]=mysqli_num_rows($execMysqlQuery["queryResource"]);
|
|
|
11928 |
|
|
|
11929 |
#執行到這邊代表執行成功
|
|
|
11930 |
$result["status"]="true";
|
|
|
11931 |
|
| 226 |
liveuser |
11932 |
#回傳查詢的結果;
|
|
|
11933 |
return $result;
|
| 3 |
liveuser |
11934 |
|
|
|
11935 |
}#end dataTableSelect
|
|
|
11936 |
|
|
|
11937 |
/*
|
|
|
11938 |
#函式說明:
|
|
|
11939 |
#解析 dataTableSelect($conf) 後的結果,亦即將執行sql語法後所得到的結果解析放進變數裏面
|
|
|
11940 |
#回傳結果:
|
|
|
11941 |
#$result["status"],執行結果"true"為成功;"false"為失敗
|
|
|
11942 |
#$result["error"],錯誤訊息
|
|
|
11943 |
#$result["function"],儲存當前函數名稱
|
|
|
11944 |
#$result["dataColumnName"],為資料欄位的名稱陣列.
|
| 177 |
liveuser |
11945 |
#$result["dataColumnName"][$i]代表第一個欄位名稱.
|
|
|
11946 |
#$result["dataContent"],爲資料的內容陣列,第1維度的key為$conf["tableValueName"][$i],亦即第 $i+1 個欄位的名稱,若該欄位不存在,則其value為空字串;第2維度的key為第$i+1筆資料的索引.
|
|
|
11947 |
#$result["dataCount"],爲取得的資料筆數.
|
| 3 |
liveuser |
11948 |
#必填參數:
|
| 177 |
liveuser |
11949 |
#$conf["sqlQueryResult"],object,爲執行sql語法所獲得的查詢結果。
|
| 3 |
liveuser |
11950 |
$conf["sqlQueryResult"]="";
|
| 177 |
liveuser |
11951 |
#$conf["tableValueName"],字串陣列,爲該資料表列項目的每一項名稱,須爲陣列值,若為「array("*")」則代表所有欄位.
|
| 3 |
liveuser |
11952 |
$conf["tableValueName"]=array();
|
|
|
11953 |
#可省略參數:
|
| 177 |
liveuser |
11954 |
#$conf["dbAddress"],字串,爲mysql-Server的位置,目前沒有用途.
|
|
|
11955 |
#$conf["dbAddress"]=$dbAddress;
|
|
|
11956 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號,目前沒有用途.
|
|
|
11957 |
#$conf["dbAccount"]=$dbAccount;
|
|
|
11958 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼,目前沒有用途.
|
| 3 |
liveuser |
11959 |
#$conf["dbPassword"]=$dbPassword;
|
| 177 |
liveuser |
11960 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port,目前沒有用途.
|
| 3 |
liveuser |
11961 |
#$conf["dbPort"]="";
|
|
|
11962 |
#$conf["valueName"],字串陣列,爲該資料表列項目的每一項所要對應的變數名稱,預設為欄位的名稱($conf["tableValueName"]).
|
|
|
11963 |
#$conf["valueName"]=$conf["tableValueName"];
|
|
|
11964 |
#參考資料:
|
|
|
11965 |
#http://www.w3school.com.cn/php/func_mysql_fetch_array.asp => 解析取得的資料表欄位時,能夠選擇回傳含有欄位名稱與數字代表的key.
|
|
|
11966 |
#備註:
|
|
|
11967 |
#無.
|
|
|
11968 |
*/
|
|
|
11969 |
public static function sendQueryDataToVariabele(&$conf){
|
|
|
11970 |
|
|
|
11971 |
#初始化要回傳的內容
|
|
|
11972 |
$result=array();
|
|
|
11973 |
|
|
|
11974 |
#取得當前執行的函數名稱
|
|
|
11975 |
$result["function"]=__FUNCTION__;
|
|
|
11976 |
|
|
|
11977 |
#如果 $conf 不為陣列
|
|
|
11978 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
11979 |
|
| 3 |
liveuser |
11980 |
#設置執行失敗
|
|
|
11981 |
$result["status"]="false";
|
| 226 |
liveuser |
11982 |
|
| 3 |
liveuser |
11983 |
#設置執行錯誤訊息
|
|
|
11984 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
11985 |
|
|
|
11986 |
#如果傳入的參數為 null
|
|
|
11987 |
if($conf==null){
|
| 226 |
liveuser |
11988 |
|
| 3 |
liveuser |
11989 |
#設置執行錯誤訊息
|
|
|
11990 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
11991 |
|
| 3 |
liveuser |
11992 |
}#if end
|
|
|
11993 |
|
|
|
11994 |
#回傳結果
|
|
|
11995 |
return $result;
|
| 226 |
liveuser |
11996 |
|
| 3 |
liveuser |
11997 |
}#if end
|
|
|
11998 |
|
|
|
11999 |
#檢查參數
|
|
|
12000 |
#函式說明:
|
|
|
12001 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
12002 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12003 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
12004 |
#$result["function"],當前執行的函式名稱.
|
|
|
12005 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
12006 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
12007 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
12008 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
12009 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
12010 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
12011 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
12012 |
#必填參數:
|
|
|
12013 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
12014 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
12015 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
| 177 |
liveuser |
12016 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("sqlQueryResult","tableValueName");
|
| 226 |
liveuser |
12017 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 177 |
liveuser |
12018 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("object","array");
|
| 3 |
liveuser |
12019 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
12020 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
12021 |
#可省略參數:
|
|
|
12022 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
12023 |
#$conf["canBeEmptyString"]="false";
|
|
|
12024 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 177 |
liveuser |
12025 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort","valueName","dbAddress","dbAccount");
|
| 226 |
liveuser |
12026 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 177 |
liveuser |
12027 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","string","string");
|
| 3 |
liveuser |
12028 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 177 |
liveuser |
12029 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,"\$conf[\"tableValueName\"]",null,null);
|
| 3 |
liveuser |
12030 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
12031 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("valueName","tableValueName");
|
|
|
12032 |
#參考資料:
|
|
|
12033 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
12034 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
12035 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
12036 |
|
| 3 |
liveuser |
12037 |
#如果檢查失敗
|
|
|
12038 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
12039 |
|
| 3 |
liveuser |
12040 |
#設置執行失敗的訊息
|
|
|
12041 |
$result["status"]="false";
|
| 226 |
liveuser |
12042 |
|
| 3 |
liveuser |
12043 |
#設置錯誤訊息
|
|
|
12044 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
12045 |
|
| 3 |
liveuser |
12046 |
#回傳結果
|
|
|
12047 |
return $result;
|
| 226 |
liveuser |
12048 |
|
| 3 |
liveuser |
12049 |
}#if end
|
| 226 |
liveuser |
12050 |
|
| 3 |
liveuser |
12051 |
#如果檢查不通過
|
|
|
12052 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
12053 |
|
| 3 |
liveuser |
12054 |
#設置執行失敗的訊息
|
|
|
12055 |
$result["status"]="false";
|
| 226 |
liveuser |
12056 |
|
| 3 |
liveuser |
12057 |
#設置錯誤訊息
|
|
|
12058 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
12059 |
|
| 3 |
liveuser |
12060 |
#回傳結果
|
|
|
12061 |
return $result;
|
| 226 |
liveuser |
12062 |
|
| 3 |
liveuser |
12063 |
}#if end
|
| 226 |
liveuser |
12064 |
|
| 3 |
liveuser |
12065 |
#給予初始值表示從0筆開始統計
|
|
|
12066 |
$dataSetNum=0;
|
|
|
12067 |
|
|
|
12068 |
#取得資料表的欄位數量
|
|
|
12069 |
$columnCounts=count($conf["tableValueName"]);
|
|
|
12070 |
|
|
|
12071 |
#初始化識別是否要匯出全部欄位的變數
|
|
|
12072 |
$exportAll="false";
|
|
|
12073 |
|
|
|
12074 |
#初始化儲存取得的欄位名稱陣列
|
|
|
12075 |
$result["dataColumnName"]=array();
|
|
|
12076 |
|
|
|
12077 |
#如果剛好只有一個元素
|
|
|
12078 |
if($columnCounts==1){
|
| 226 |
liveuser |
12079 |
|
| 3 |
liveuser |
12080 |
#如果第一個元素為 "*"
|
|
|
12081 |
if($conf["tableValueName"][0]=="*"){
|
| 226 |
liveuser |
12082 |
|
| 3 |
liveuser |
12083 |
#則代表要全部欄位均匯出.
|
|
|
12084 |
$exportAll="true";
|
| 226 |
liveuser |
12085 |
|
| 3 |
liveuser |
12086 |
#初始化計數的變數
|
|
|
12087 |
$dataSetNum=0;
|
| 226 |
liveuser |
12088 |
|
| 3 |
liveuser |
12089 |
#將讀取到的資料一次只讀取一列
|
|
|
12090 |
while($row = mysqli_fetch_array($conf["sqlQueryResult"])){
|
| 226 |
liveuser |
12091 |
|
| 3 |
liveuser |
12092 |
#筆數加1
|
|
|
12093 |
$dataSetNum++;
|
| 226 |
liveuser |
12094 |
|
| 3 |
liveuser |
12095 |
#針對每個欄位
|
|
|
12096 |
foreach($row as $columnName => $columnValue){
|
| 226 |
liveuser |
12097 |
|
| 3 |
liveuser |
12098 |
#取得欄位的內容並用欄位名稱作為key
|
|
|
12099 |
$result["dataContent"][$columnName][]=$columnValue;
|
| 226 |
liveuser |
12100 |
|
| 3 |
liveuser |
12101 |
#如果 $dataSetNum 等於 1
|
|
|
12102 |
#亦即第一筆資料
|
|
|
12103 |
if($dataSetNum==1 && gettype($columnName)!="integer"){
|
|
|
12104 |
|
|
|
12105 |
#取得每個欄位名稱
|
|
|
12106 |
$result["dataColumnName"][]=$columnName;
|
|
|
12107 |
|
|
|
12108 |
}#if end
|
|
|
12109 |
|
|
|
12110 |
}#foreach end
|
| 226 |
liveuser |
12111 |
|
| 3 |
liveuser |
12112 |
}#while end
|
| 226 |
liveuser |
12113 |
|
| 3 |
liveuser |
12114 |
#將資料筆數放進 $result["dataCount"] 裏面
|
|
|
12115 |
$result["dataCount"]=$dataSetNum;
|
| 226 |
liveuser |
12116 |
|
| 3 |
liveuser |
12117 |
}#if end
|
| 226 |
liveuser |
12118 |
|
| 3 |
liveuser |
12119 |
}#if end
|
|
|
12120 |
|
|
|
12121 |
#如果 $exportAll 等於 "fasle" 則代表要根據需求匯出指定的欄位.
|
|
|
12122 |
if($exportAll=="false"){
|
|
|
12123 |
|
|
|
12124 |
#如果 $conf["valueName"] 沒有設置
|
|
|
12125 |
if(!isset($conf["valueName"])){
|
| 226 |
liveuser |
12126 |
|
| 3 |
liveuser |
12127 |
#預設為 $conf["tableValueName"]
|
|
|
12128 |
$conf["valueName"]=$conf["tableValueName"];
|
| 226 |
liveuser |
12129 |
|
| 3 |
liveuser |
12130 |
}#if end
|
| 226 |
liveuser |
12131 |
|
| 3 |
liveuser |
12132 |
#取得每個欄位名稱
|
|
|
12133 |
$result["dataColumnName"]=$conf["tableValueName"];
|
| 226 |
liveuser |
12134 |
|
| 3 |
liveuser |
12135 |
#將讀取到的資料一次只讀取一列
|
|
|
12136 |
while($row = mysqli_fetch_array($conf["sqlQueryResult"])){
|
|
|
12137 |
|
|
|
12138 |
#$i筆項列資料,則運行$i次。
|
| 177 |
liveuser |
12139 |
for($i=0;$i<$columnCounts;$i++){
|
| 3 |
liveuser |
12140 |
|
|
|
12141 |
#如果欄位不存在
|
|
|
12142 |
if(!isset($row[$conf["tableValueName"][$i]])){
|
| 226 |
liveuser |
12143 |
|
| 3 |
liveuser |
12144 |
#將解析的資料內容用空字串替代放進$result["dataContent"]變數裏面
|
|
|
12145 |
$result["dataContent"][$conf["valueName"][$i]][$dataSetNum] = "";
|
| 226 |
liveuser |
12146 |
|
| 3 |
liveuser |
12147 |
}#if end
|
|
|
12148 |
|
|
|
12149 |
#將解析的資料內容結果放進$result["dataContent"]變數裏面
|
| 226 |
liveuser |
12150 |
$result["dataContent"][$conf["valueName"][$i]][$dataSetNum] = $row[$conf["tableValueName"][$i]];
|
|
|
12151 |
|
| 3 |
liveuser |
12152 |
}#for end
|
|
|
12153 |
|
|
|
12154 |
#資料筆數編號加1
|
| 226 |
liveuser |
12155 |
$dataSetNum++;
|
| 3 |
liveuser |
12156 |
|
|
|
12157 |
}#while end
|
| 226 |
liveuser |
12158 |
|
| 3 |
liveuser |
12159 |
#將資料筆數放進 $result["dataCount"] 裏面
|
|
|
12160 |
$result["dataCount"]=$dataSetNum;
|
| 226 |
liveuser |
12161 |
|
| 3 |
liveuser |
12162 |
}#if end
|
|
|
12163 |
|
|
|
12164 |
#執行道這邊代表執行成功
|
|
|
12165 |
$result["status"]="true";
|
|
|
12166 |
|
|
|
12167 |
#將取得的結果回傳
|
|
|
12168 |
return $result;
|
|
|
12169 |
|
|
|
12170 |
}#function sendQueryDataToVariabele end
|
|
|
12171 |
|
|
|
12172 |
/*
|
|
|
12173 |
#函式說明:
|
|
|
12174 |
#一次取得資料庫、表的資料
|
|
|
12175 |
#回傳結果:
|
|
|
12176 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
12177 |
#$result["error"],錯誤訊息陣列。
|
|
|
12178 |
#$result["function"],當前執行的漢書名稱.
|
|
|
12179 |
#$result["argu"],使用的參數.
|
|
|
12180 |
#$result["dataColumnName"],抓取的資料欄位名稱陣列.
|
|
|
12181 |
#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
|
|
|
12182 |
#$result["dataContent"],爲資料的內容。
|
|
|
12183 |
#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
12184 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
12185 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
12186 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
12187 |
#$result["sql"],執行的sql字串.
|
|
|
12188 |
#必填參數:
|
|
|
12189 |
#$conf["dbAddress"],字串,爲dbServer的位置。
|
|
|
12190 |
$conf["dbAddress"]=$dbAddress;
|
|
|
12191 |
#$conf["dbAccount"],字串,爲登入dbServer的帳號。
|
|
|
12192 |
$conf["dbAccount"]=$dbAccount;
|
|
|
12193 |
#$conf["dbName"],字串,爲要存取的資料庫名稱
|
|
|
12194 |
$conf["dbName"]=$dbName;
|
|
|
12195 |
#$conf["tableName"],字串,爲要存取的資料表名稱
|
|
|
12196 |
$conf["tableName"]="";
|
|
|
12197 |
#$conf["columnYouWant"],字串陣列,你想要的欄位!,若設為「array("*")」則代表全部欄位.
|
|
|
12198 |
$conf["columnYouWant"]=array();
|
|
|
12199 |
#可省略參數:
|
|
|
12200 |
#$conf["dbPassword"],字串,爲要存取dbServer的密碼.
|
|
|
12201 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
12202 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
|
|
|
12203 |
#$conf["dbPort"]="";
|
|
|
12204 |
#$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。
|
|
|
12205 |
#$conf["WhereColumnName"]=array("");
|
|
|
12206 |
#$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
|
|
12207 |
#$conf["WhereColumnValue"]=array("");
|
|
|
12208 |
#$conf["WhereColumnCombine"],字串陣列,用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
12209 |
#$conf["WhereColumnCombine"]=array("");
|
|
|
12210 |
#$conf["WhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、"!="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
12211 |
#$conf["WhereColumnOperator"]=array("");
|
|
|
12212 |
#$conf["WhereColumnAndOr"],字串陣列,用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
12213 |
#$conf["WhereColumnAndOr"]=array("");
|
|
|
12214 |
#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
|
|
|
12215 |
#$conf["whereIn"]=array(array("colName",array("a","b","c")));
|
|
|
12216 |
#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
|
|
|
12217 |
#$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
|
|
|
12218 |
#$conf["orderItem"],字串,爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
|
|
12219 |
#$conf["orderItem"]="";
|
|
|
12220 |
#$conf["ascORdesc"],字串,爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
|
|
12221 |
#$conf["ascORdesc"]="";
|
|
|
12222 |
#$conf["numberStart"],字串,為從第幾筆開始讀取,預設為0,代筆第一筆。
|
|
|
12223 |
#$conf["numberStart"]="0";
|
|
|
12224 |
#$conf["numLimit"],字串,為要取幾筆資料,可以省略,省略則表示不限制數目。
|
|
|
12225 |
#$conf["numLimit"]="30";
|
|
|
12226 |
#$conf["groupBy"],字串陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
|
|
12227 |
#$conf["groupBy"]=array("");
|
|
|
12228 |
#參考資料:
|
|
|
12229 |
#無.
|
|
|
12230 |
#備註:
|
|
|
12231 |
#無.
|
|
|
12232 |
*/
|
|
|
12233 |
public static function fastGetDbData(&$conf){
|
| 226 |
liveuser |
12234 |
|
| 3 |
liveuser |
12235 |
#初始化要回傳的內容
|
|
|
12236 |
$result=array();
|
|
|
12237 |
|
|
|
12238 |
#取得當前執行的函數名稱
|
|
|
12239 |
$result["function"]=__FUNCTION__;
|
|
|
12240 |
|
|
|
12241 |
#如果 $conf 不為陣列
|
|
|
12242 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
12243 |
|
| 3 |
liveuser |
12244 |
#設置執行失敗
|
|
|
12245 |
$result["status"]="false";
|
| 226 |
liveuser |
12246 |
|
| 3 |
liveuser |
12247 |
#設置執行錯誤訊息
|
|
|
12248 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
12249 |
|
|
|
12250 |
#如果傳入的參數為 null
|
|
|
12251 |
if($conf==null){
|
| 226 |
liveuser |
12252 |
|
| 3 |
liveuser |
12253 |
#設置執行錯誤訊息
|
|
|
12254 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
12255 |
|
| 3 |
liveuser |
12256 |
}#if end
|
|
|
12257 |
|
|
|
12258 |
#回傳結果
|
|
|
12259 |
return $result;
|
| 226 |
liveuser |
12260 |
|
| 3 |
liveuser |
12261 |
}#if end
|
| 226 |
liveuser |
12262 |
|
| 3 |
liveuser |
12263 |
#取得使用的
|
|
|
12264 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
12265 |
|
| 3 |
liveuser |
12266 |
#檢查參數
|
|
|
12267 |
#函式說明:
|
|
|
12268 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
12269 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12270 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
12271 |
#$result["function"],當前執行的函式名稱.
|
|
|
12272 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
12273 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
12274 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
12275 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
12276 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
12277 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
12278 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
12279 |
#必填參數:
|
|
|
12280 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
12281 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
12282 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
12283 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","dbName","tableName","columnYouWant");
|
| 226 |
liveuser |
12284 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
12285 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","array");
|
|
|
12286 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
12287 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
12288 |
#可省略參數:
|
|
|
12289 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
12290 |
#$conf["canBeEmptyString"]="false";
|
|
|
12291 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
12292 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort","WhereColumnName","WhereColumnValue","WhereColumnCombine","WhereColumnOperator","WhereColumnAndOr","orderItem","ascORdesc","numberStart","numLimit","groupBy","whereIn","whereNotIn");
|
| 226 |
liveuser |
12293 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
12294 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","array","array","array","array","string","string","string","string","array","array","array");
|
|
|
12295 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
12296 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null,null,null,null,null,null,"0",null,null,null,null);
|
|
|
12297 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
12298 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("WhereColumnName","WhereColumnValue");
|
|
|
12299 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("WhereColumnValue","WhereColumnOperator");
|
|
|
12300 |
#參考資料:
|
|
|
12301 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
12302 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
12303 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
12304 |
|
| 3 |
liveuser |
12305 |
#如果檢查失敗
|
|
|
12306 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
12307 |
|
| 3 |
liveuser |
12308 |
#設置執行失敗的訊息
|
|
|
12309 |
$result["status"]="false";
|
| 226 |
liveuser |
12310 |
|
| 3 |
liveuser |
12311 |
#設置錯誤訊息
|
|
|
12312 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
12313 |
|
| 3 |
liveuser |
12314 |
#回傳結果
|
|
|
12315 |
return $result;
|
| 226 |
liveuser |
12316 |
|
| 3 |
liveuser |
12317 |
}#if end
|
| 226 |
liveuser |
12318 |
|
| 3 |
liveuser |
12319 |
#如果檢查不通過
|
|
|
12320 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
12321 |
|
| 3 |
liveuser |
12322 |
#設置執行失敗的訊息
|
|
|
12323 |
$result["status"]="false";
|
| 226 |
liveuser |
12324 |
|
| 3 |
liveuser |
12325 |
#設置錯誤訊息
|
|
|
12326 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
12327 |
|
| 3 |
liveuser |
12328 |
#回傳結果
|
|
|
12329 |
return $result;
|
| 226 |
liveuser |
12330 |
|
| 3 |
liveuser |
12331 |
}#if end
|
|
|
12332 |
|
|
|
12333 |
#初始化要檢查的欄位
|
|
|
12334 |
$colToCheck=array();
|
|
|
12335 |
|
|
|
12336 |
#如果有指定要的欄位
|
|
|
12337 |
if($conf["columnYouWant"]!==array("*")){
|
| 226 |
liveuser |
12338 |
|
| 3 |
liveuser |
12339 |
#針對每個欄位
|
|
|
12340 |
foreach($conf["columnYouWant"] as $col){
|
| 226 |
liveuser |
12341 |
|
| 3 |
liveuser |
12342 |
#取得欄位名稱
|
|
|
12343 |
$colToCheck[]=$col;
|
| 226 |
liveuser |
12344 |
|
| 177 |
liveuser |
12345 |
}#foreach end
|
| 226 |
liveuser |
12346 |
|
| 3 |
liveuser |
12347 |
}#if end
|
| 226 |
liveuser |
12348 |
|
| 3 |
liveuser |
12349 |
#如果有設置
|
|
|
12350 |
if(isset($conf["WhereColumnName"])){
|
| 226 |
liveuser |
12351 |
|
| 3 |
liveuser |
12352 |
#針對每個欄位
|
|
|
12353 |
foreach($conf["WhereColumnName"] as $col){
|
| 226 |
liveuser |
12354 |
|
| 3 |
liveuser |
12355 |
#取得欄位名稱
|
|
|
12356 |
$colToCheck[]=$col;
|
| 226 |
liveuser |
12357 |
|
| 177 |
liveuser |
12358 |
}#foreach end
|
| 226 |
liveuser |
12359 |
|
| 3 |
liveuser |
12360 |
}#if end
|
| 226 |
liveuser |
12361 |
|
| 3 |
liveuser |
12362 |
#如果有設置 $conf["whereIn"]
|
|
|
12363 |
if(isset($conf["whereIn"])){
|
| 226 |
liveuser |
12364 |
|
| 3 |
liveuser |
12365 |
#針對每個 where in 條件
|
|
|
12366 |
for($i=0;$i<count($conf["whereIn"]);$i++){
|
| 226 |
liveuser |
12367 |
|
| 3 |
liveuser |
12368 |
#取得欄位名稱
|
|
|
12369 |
$colToCheck[]=$conf["whereIn"][$i][0];
|
| 226 |
liveuser |
12370 |
|
| 3 |
liveuser |
12371 |
}#for end
|
| 226 |
liveuser |
12372 |
|
| 3 |
liveuser |
12373 |
}#if end
|
| 226 |
liveuser |
12374 |
|
| 3 |
liveuser |
12375 |
#如果要檢查的欄位不是空陣列
|
|
|
12376 |
if($colToCheck!==array()){
|
| 226 |
liveuser |
12377 |
|
| 3 |
liveuser |
12378 |
#檢查需要判斷資料表欄位是否存在
|
|
|
12379 |
#函式說明:
|
|
|
12380 |
#檢查資料表的欄位是否存在
|
|
|
12381 |
#回傳結果::
|
|
|
12382 |
#設置執行錯誤的識別
|
|
|
12383 |
#$result["function"],當前執行的函數名稱.
|
|
|
12384 |
#$result["status"],"true"代表執行成功;"false"代表執行失敗.
|
|
|
12385 |
#$result["error"],錯誤訊息.
|
|
|
12386 |
#$result["warning"],警告訊息陣列
|
|
|
12387 |
#$result["passed"],是否通過檢查,"true"代表通過;"false"代表不通過.
|
|
|
12388 |
#其餘的結果代表參數不正確
|
|
|
12389 |
#必填參數:
|
|
|
12390 |
#$conf["dbAddr"],字串,爲mysql-Server的位置
|
| 226 |
liveuser |
12391 |
$conf["db::checkTableColExists"]["dbAddr"]=$conf["dbAddress"];
|
| 3 |
liveuser |
12392 |
#$conf["dbAcct"],字串,爲用於連入mysql-Server時要使用的帳號
|
|
|
12393 |
$conf["db::checkTableColExists"]["dbAcct"]=$conf["dbAccount"];
|
|
|
12394 |
#$conf["dbName"],字串,爲指定的資料庫名稱
|
|
|
12395 |
$conf["db::checkTableColExists"]["dbName"]=$conf["dbName"];
|
|
|
12396 |
#$conf["dtName"],字串,為要檢查是否存在的資料表名稱
|
|
|
12397 |
$conf["db::checkTableColExists"]["dtName"]=$conf["tableName"];
|
|
|
12398 |
#$conf["col"],字串陣列,要檢查的欄位名稱.
|
|
|
12399 |
$conf["db::checkTableColExists"]["col"]=array_unique($colToCheck);
|
|
|
12400 |
#可省略參數
|
| 226 |
liveuser |
12401 |
|
| 3 |
liveuser |
12402 |
#如果有設置 $conf["dbPassword"]
|
|
|
12403 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
12404 |
|
|
|
12405 |
#$conf["dbPass"],爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 3 |
liveuser |
12406 |
$conf["db::checkTableColExists"]["dbPass"]=$conf["dbPassword"];
|
| 226 |
liveuser |
12407 |
|
| 3 |
liveuser |
12408 |
}#if end
|
| 226 |
liveuser |
12409 |
|
| 3 |
liveuser |
12410 |
#如果有設置 $conf["dbPort"]
|
|
|
12411 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
12412 |
|
|
|
12413 |
#$conf["dbPort"],爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的port 3306
|
| 3 |
liveuser |
12414 |
$conf["db::checkTableColExists"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
12415 |
|
| 3 |
liveuser |
12416 |
}#if end
|
| 226 |
liveuser |
12417 |
|
| 3 |
liveuser |
12418 |
$checkTableColExists=db::checkTableColExists($conf["db::checkTableColExists"]);
|
|
|
12419 |
unset($conf["db::checkTableColExists"]);
|
| 226 |
liveuser |
12420 |
|
| 3 |
liveuser |
12421 |
#如果檢查失敗
|
|
|
12422 |
if($checkTableColExists["status"]==="false"){
|
| 226 |
liveuser |
12423 |
|
| 3 |
liveuser |
12424 |
#設置執行失敗
|
|
|
12425 |
$result["status"]="false";
|
| 226 |
liveuser |
12426 |
|
| 3 |
liveuser |
12427 |
#設置執行錯誤訊息
|
|
|
12428 |
$result["error"]=$checkTableColExists;
|
| 226 |
liveuser |
12429 |
|
| 3 |
liveuser |
12430 |
#回傳結果
|
|
|
12431 |
return $result;
|
| 226 |
liveuser |
12432 |
|
| 3 |
liveuser |
12433 |
}#if end
|
| 226 |
liveuser |
12434 |
|
| 3 |
liveuser |
12435 |
#如果檢查不通過
|
|
|
12436 |
if($checkTableColExists["passed"]==="false"){
|
| 226 |
liveuser |
12437 |
|
| 3 |
liveuser |
12438 |
#設置執行失敗
|
|
|
12439 |
$result["status"]="false";
|
| 226 |
liveuser |
12440 |
|
| 3 |
liveuser |
12441 |
#設置執行錯誤訊息
|
|
|
12442 |
$result["error"]=$checkTableColExists;
|
| 226 |
liveuser |
12443 |
|
| 3 |
liveuser |
12444 |
#回傳結果
|
|
|
12445 |
return $result;
|
| 226 |
liveuser |
12446 |
|
| 3 |
liveuser |
12447 |
}#if end
|
| 226 |
liveuser |
12448 |
|
| 3 |
liveuser |
12449 |
}#if end
|
| 226 |
liveuser |
12450 |
|
| 3 |
liveuser |
12451 |
#函式說明:
|
|
|
12452 |
#dataTableSelectCustom的改良版
|
|
|
12453 |
#回傳的參數:
|
|
|
12454 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
12455 |
#$result["error"],錯誤訊息陣列。
|
|
|
12456 |
#$result["sql"],執行的sql語法。
|
|
|
12457 |
#$result["sqlQueryResult"]#爲資料連線處理完畢之後的結果,需要 sendQueryDataToVariabele 涵式來解析。
|
|
|
12458 |
#$result["connectInformation"]#連結到資料庫的資訊。
|
|
|
12459 |
#$result["dataCount"]#符合條件的資料筆數
|
|
|
12460 |
#必填參數:
|
|
|
12461 |
$conf["db"]["dataTableSelectCustomV2"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置。
|
|
|
12462 |
$conf["db"]["dataTableSelectCustomV2"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號。
|
|
|
12463 |
$conf["db"]["dataTableSelectCustomV2"]["selectedDataBaseName"]=$conf["dbName"];#要選取的資料庫名稱 。
|
|
|
12464 |
$conf["db"]["dataTableSelectCustomV2"]["selectedDataTableName"]=$conf["tableName"];#爲欲選擇的資料表名稱。
|
|
|
12465 |
#可省略參數:
|
| 226 |
liveuser |
12466 |
|
| 3 |
liveuser |
12467 |
#如果存在 $conf["dbPassword"]
|
|
|
12468 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
12469 |
|
| 3 |
liveuser |
12470 |
#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
|
|
|
12471 |
$conf["db"]["dataTableSelectCustomV2"]["dbPassword"]=$conf["dbPassword"];
|
| 226 |
liveuser |
12472 |
|
| 3 |
liveuser |
12473 |
}#if end
|
| 226 |
liveuser |
12474 |
|
| 3 |
liveuser |
12475 |
#如果存在 $conf["dbPort"]
|
|
|
12476 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
12477 |
|
| 3 |
liveuser |
12478 |
#爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port
|
|
|
12479 |
$conf["db"]["dataTableSelectCustomV2"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
12480 |
|
| 3 |
liveuser |
12481 |
}#if end
|
| 226 |
liveuser |
12482 |
|
| 3 |
liveuser |
12483 |
#如果存在 $conf["WhereColumnCombine"]
|
|
|
12484 |
if(isset($conf["WhereColumnCombine"])){
|
| 226 |
liveuser |
12485 |
|
| 3 |
liveuser |
12486 |
#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
12487 |
$conf["db"]["dataTableSelectCustomV2"]["WhereColumnCombine"]=$conf["WhereColumnCombine"];
|
| 226 |
liveuser |
12488 |
|
| 3 |
liveuser |
12489 |
}#if end
|
| 226 |
liveuser |
12490 |
|
| 3 |
liveuser |
12491 |
#如果 $conf["WhereColumnName"] 存在
|
|
|
12492 |
if(isset($conf["WhereColumnName"])){
|
| 226 |
liveuser |
12493 |
|
| 3 |
liveuser |
12494 |
$conf["db"]["dataTableSelectCustomV2"]["WhereColumnName"]=$conf["WhereColumnName"];#用於判斷語句的欄位項目陣列。
|
| 226 |
liveuser |
12495 |
|
|
|
12496 |
}#if end
|
|
|
12497 |
|
| 3 |
liveuser |
12498 |
#如果存在 $conf["WhereColumnOperator"]
|
|
|
12499 |
if(isset($conf["WhereColumnOperator"])){
|
| 226 |
liveuser |
12500 |
|
| 3 |
liveuser |
12501 |
#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
12502 |
$conf["db"]["dataTableSelectCustomV2"]["WhereColumnOperator"]=$conf["WhereColumnOperator"];
|
| 226 |
liveuser |
12503 |
|
| 3 |
liveuser |
12504 |
}#if end
|
| 226 |
liveuser |
12505 |
|
| 3 |
liveuser |
12506 |
#如果 $conf["WhereColumnValue"] 有設置
|
|
|
12507 |
if(isset($conf["WhereColumnValue"])){
|
| 226 |
liveuser |
12508 |
|
| 3 |
liveuser |
12509 |
$conf["db"]["dataTableSelectCustomV2"]["WhereColumnValue"]=$conf["WhereColumnValue"];#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
| 226 |
liveuser |
12510 |
|
| 3 |
liveuser |
12511 |
}#if end
|
| 226 |
liveuser |
12512 |
|
| 3 |
liveuser |
12513 |
#如果 $conf["WhereColumnAndOr"] 存在
|
|
|
12514 |
if(isset($conf["WhereColumnAndOr"])){
|
| 226 |
liveuser |
12515 |
|
| 3 |
liveuser |
12516 |
#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
12517 |
$conf["db"]["dataTableSelectCustomV2"]["WhereColumnAndOr"]=$conf["WhereColumnAndOr"];
|
| 226 |
liveuser |
12518 |
|
| 3 |
liveuser |
12519 |
}#if end
|
| 226 |
liveuser |
12520 |
|
| 3 |
liveuser |
12521 |
#如果 $conf["orderItem"] 存在
|
|
|
12522 |
if(isset($conf["orderItem"])){
|
| 226 |
liveuser |
12523 |
|
| 3 |
liveuser |
12524 |
#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
|
|
12525 |
$conf["db"]["dataTableSelectCustomV2"]["orderItem"]=$conf["orderItem"];
|
| 226 |
liveuser |
12526 |
|
| 3 |
liveuser |
12527 |
}#if end
|
| 226 |
liveuser |
12528 |
|
| 3 |
liveuser |
12529 |
#如果 $conf["ascORdesc"] 存在
|
|
|
12530 |
if(isset($conf["ascORdesc"])){
|
| 226 |
liveuser |
12531 |
|
| 3 |
liveuser |
12532 |
#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
|
|
12533 |
$conf["db"]["dataTableSelectCustomV2"]["ascORdesc"]=$conf["ascORdesc"];
|
| 226 |
liveuser |
12534 |
|
| 3 |
liveuser |
12535 |
}#if end
|
| 226 |
liveuser |
12536 |
|
| 3 |
liveuser |
12537 |
#如果 $conf["numberStart"] 存在
|
|
|
12538 |
if(isset($conf["numberStart"])){
|
| 226 |
liveuser |
12539 |
|
| 3 |
liveuser |
12540 |
$conf["db"]["dataTableSelectCustomV2"]["numberStart"]=$conf["numberStart"];
|
| 226 |
liveuser |
12541 |
|
| 3 |
liveuser |
12542 |
}#if end
|
| 226 |
liveuser |
12543 |
|
| 3 |
liveuser |
12544 |
#如果 $conf["numLimit"] 存在
|
|
|
12545 |
if(isset($conf["numLimit"])){
|
| 226 |
liveuser |
12546 |
|
| 3 |
liveuser |
12547 |
#為要取幾筆資料,可以省略,省略則表示不限制數目。
|
|
|
12548 |
$conf["db"]["dataTableSelectCustomV2"]["number"]=$conf["numLimit"];
|
| 226 |
liveuser |
12549 |
|
| 3 |
liveuser |
12550 |
}#if end
|
| 226 |
liveuser |
12551 |
|
| 3 |
liveuser |
12552 |
#如果 $conf["groupBy"] 存在
|
|
|
12553 |
if(isset($conf["groupBy"])){
|
| 226 |
liveuser |
12554 |
|
| 3 |
liveuser |
12555 |
#爲要以那個欄爲作爲分羣的依據(該欄位相同的數值僅會取出一筆)。
|
|
|
12556 |
$conf["db"]["dataTableSelectCustomV2"]["groupBy"]=$conf["groupBy"];
|
| 226 |
liveuser |
12557 |
|
| 3 |
liveuser |
12558 |
}#if end
|
| 226 |
liveuser |
12559 |
|
| 3 |
liveuser |
12560 |
#如果 $conf["whereIn"] 存在
|
|
|
12561 |
if(isset($conf["whereIn"])){
|
| 226 |
liveuser |
12562 |
|
|
|
12563 |
#where in 條件
|
| 3 |
liveuser |
12564 |
$conf["db"]["dataTableSelectCustomV2"]["whereIn"]=$conf["whereIn"];
|
| 226 |
liveuser |
12565 |
|
| 3 |
liveuser |
12566 |
}#if end
|
| 226 |
liveuser |
12567 |
|
| 3 |
liveuser |
12568 |
#如果 $conf["whereNotIn"] 存在
|
|
|
12569 |
if(isset($conf["whereNotIn"])){
|
| 226 |
liveuser |
12570 |
|
| 177 |
liveuser |
12571 |
#where not in 條件
|
| 3 |
liveuser |
12572 |
$conf["db"]["dataTableSelectCustomV2"]["whereNotIn"]=$conf["whereNotIn"];
|
| 226 |
liveuser |
12573 |
|
| 3 |
liveuser |
12574 |
}#if end
|
| 226 |
liveuser |
12575 |
|
| 3 |
liveuser |
12576 |
$dataTableSelectCustomV2=db::dataTableSelect($conf["db"]["dataTableSelectCustomV2"]);
|
|
|
12577 |
unset($conf["db"]);
|
| 226 |
liveuser |
12578 |
|
| 3 |
liveuser |
12579 |
#如果sql查詢失敗
|
|
|
12580 |
#如果 $dataTableSelectCustomV2["status"] 等於 "false"
|
|
|
12581 |
if($dataTableSelectCustomV2["status"]=="false"){
|
| 226 |
liveuser |
12582 |
|
| 3 |
liveuser |
12583 |
#則設置執行錯誤的識別
|
|
|
12584 |
$result["status"]="false";
|
| 226 |
liveuser |
12585 |
|
| 3 |
liveuser |
12586 |
#設置錯誤訊息
|
|
|
12587 |
$result["error"]=$dataTableSelectCustomV2;
|
| 226 |
liveuser |
12588 |
|
| 3 |
liveuser |
12589 |
#回傳結果
|
|
|
12590 |
return $result;
|
| 226 |
liveuser |
12591 |
|
| 3 |
liveuser |
12592 |
}#if end
|
| 226 |
liveuser |
12593 |
|
| 3 |
liveuser |
12594 |
#取得執行的sql字串
|
|
|
12595 |
$result["sql"]=$dataTableSelectCustomV2["sql"];
|
| 226 |
liveuser |
12596 |
|
| 3 |
liveuser |
12597 |
#解析 dataTableSelect($conf) 後的結果,亦即將執行sql語法後所得到的結果解析放進變數裏面
|
|
|
12598 |
#回傳結果:
|
|
|
12599 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
12600 |
#$result["error"],錯誤訊息陣列。
|
|
|
12601 |
#$result["dataColumnName"],為資料欄位的名稱陣列.
|
|
|
12602 |
#$result["dataColumnName"][$i]代表第一個欄位名稱.
|
|
|
12603 |
#$result["dataContent"],爲資料的內容。
|
|
|
12604 |
#$result["dataContent"][$conf["tableValueName"][$i]][$dataSetNum],
|
|
|
12605 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
12606 |
#$conf["tableValueName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
12607 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
12608 |
#必填參數:
|
|
|
12609 |
$conf["db"]["sendQueryDataToVariabele"]["sqlQueryResult"]=$dataTableSelectCustomV2["sqlQueryResult"];#爲執行sql語法所獲得的查詢結果。
|
|
|
12610 |
$conf["db"]["sendQueryDataToVariabele"]["tableValueName"]=$conf["columnYouWant"];#$conf["tableValueName"]=array();#爲該資料表列項目的每一項名稱,須爲陣列值,若為「array("*")」則代表所有欄位.
|
|
|
12611 |
$conf["db"]["sendQueryDataToVariabele"]["valueName"]=$conf["columnYouWant"];#爲該資料表列項目的每一項所要對應的變數名稱,須爲陣列值。
|
|
|
12612 |
$conf["db"]["sendQueryDataToVariabele"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
12613 |
$conf["db"]["sendQueryDataToVariabele"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
12614 |
#可省略參數:
|
| 226 |
liveuser |
12615 |
|
| 3 |
liveuser |
12616 |
#如果存在 $conf["dbPassword"]
|
|
|
12617 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
12618 |
|
| 3 |
liveuser |
12619 |
#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
|
|
|
12620 |
$conf["db"]["sendQueryDataToVariabele"]["dbPassword"]=$conf["dbPassword"];
|
| 226 |
liveuser |
12621 |
|
| 3 |
liveuser |
12622 |
}#if end
|
| 226 |
liveuser |
12623 |
|
| 3 |
liveuser |
12624 |
#如果存在 $conf["dbPort"]
|
|
|
12625 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
12626 |
|
| 3 |
liveuser |
12627 |
#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表使用預設 port 3306
|
|
|
12628 |
$conf["db"]["sendQueryDataToVariabele"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
12629 |
|
| 3 |
liveuser |
12630 |
}#if end
|
| 226 |
liveuser |
12631 |
|
| 3 |
liveuser |
12632 |
$sendQueryDataToVariabele=db::sendQueryDataToVariabele($conf["db"]["sendQueryDataToVariabele"]);
|
|
|
12633 |
unset($conf["db"]);
|
| 226 |
liveuser |
12634 |
|
| 3 |
liveuser |
12635 |
#如果 $sendQueryDataToVariabele["status"] 等於 "false"
|
|
|
12636 |
if($sendQueryDataToVariabele["status"]=="false"){
|
| 226 |
liveuser |
12637 |
|
| 3 |
liveuser |
12638 |
#設置執行錯誤的識別
|
|
|
12639 |
$result["status"]="false";
|
| 226 |
liveuser |
12640 |
|
| 3 |
liveuser |
12641 |
#設置錯誤訊息
|
|
|
12642 |
$result["error"]=$sendQueryDataToVariabele;
|
| 226 |
liveuser |
12643 |
|
| 3 |
liveuser |
12644 |
#回傳結果
|
|
|
12645 |
return $result;
|
| 226 |
liveuser |
12646 |
|
| 3 |
liveuser |
12647 |
}#if end
|
| 226 |
liveuser |
12648 |
|
| 3 |
liveuser |
12649 |
#如果 $sendQueryDataToVariabele["dataContent"] 沒有設置
|
|
|
12650 |
if(!isset($sendQueryDataToVariabele["dataContent"])){
|
| 226 |
liveuser |
12651 |
|
| 3 |
liveuser |
12652 |
#那就代表沒有找到符合的資料
|
|
|
12653 |
$sendQueryDataToVariabele["dataContent"]=NULL;
|
| 226 |
liveuser |
12654 |
|
| 3 |
liveuser |
12655 |
#取得抓取到的資料內容
|
|
|
12656 |
$result["dataContent"]=$sendQueryDataToVariabele["dataContent"];
|
| 226 |
liveuser |
12657 |
|
| 3 |
liveuser |
12658 |
}#if end
|
| 226 |
liveuser |
12659 |
|
| 3 |
liveuser |
12660 |
#反之代表有資料
|
|
|
12661 |
else{
|
| 226 |
liveuser |
12662 |
|
| 3 |
liveuser |
12663 |
#取得抓取到的資料內容
|
|
|
12664 |
$result["dataContent"]=$sendQueryDataToVariabele["dataContent"];
|
| 226 |
liveuser |
12665 |
|
| 3 |
liveuser |
12666 |
#抓取欄位名稱
|
|
|
12667 |
$result["dataColumnName"]=$sendQueryDataToVariabele["dataColumnName"];
|
| 226 |
liveuser |
12668 |
|
| 3 |
liveuser |
12669 |
}#else end
|
| 226 |
liveuser |
12670 |
|
| 3 |
liveuser |
12671 |
#如果 $sendQueryDataToVariabele["dataCount"] 沒有設定
|
|
|
12672 |
if(!isset($sendQueryDataToVariabele["dataCount"])){
|
| 226 |
liveuser |
12673 |
|
| 3 |
liveuser |
12674 |
#則代表沒有抓到符合的資料
|
|
|
12675 |
(int)$sendQueryDataToVariabele["dataCount"]=0;
|
| 226 |
liveuser |
12676 |
|
| 3 |
liveuser |
12677 |
#取得資料筆數
|
|
|
12678 |
$result["dataCount"]=$sendQueryDataToVariabele["dataCount"];
|
| 226 |
liveuser |
12679 |
|
| 3 |
liveuser |
12680 |
}#if end
|
| 226 |
liveuser |
12681 |
|
| 3 |
liveuser |
12682 |
#反之代表有符合的資料
|
|
|
12683 |
else{
|
| 226 |
liveuser |
12684 |
|
| 3 |
liveuser |
12685 |
#取得抓取到的資料筆數
|
|
|
12686 |
$result["dataCount"]=$sendQueryDataToVariabele["dataCount"];
|
| 226 |
liveuser |
12687 |
|
| 3 |
liveuser |
12688 |
}#else end
|
| 226 |
liveuser |
12689 |
|
| 3 |
liveuser |
12690 |
#執行到這邊表示執行成功
|
|
|
12691 |
$result["status"]="true";
|
| 226 |
liveuser |
12692 |
|
| 3 |
liveuser |
12693 |
#回傳結果
|
|
|
12694 |
return $result;
|
| 226 |
liveuser |
12695 |
|
| 3 |
liveuser |
12696 |
}#function fastGetDbData end
|
| 226 |
liveuser |
12697 |
|
| 3 |
liveuser |
12698 |
/*
|
|
|
12699 |
#函式說明:
|
|
|
12700 |
#透過一個父資料表取得多個關聯子資料表的資料,並合併成一張表
|
|
|
12701 |
#回傳結果:
|
|
|
12702 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
12703 |
#$result["error"],錯誤訊息陣列。
|
|
|
12704 |
#$reuslt["function"],當前執行的函數
|
|
|
12705 |
#$result["parentTable"]["dataContent"],爲合併了子資料表欄位的父資料表的內容。
|
|
|
12706 |
#$result["parentTable"]["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
12707 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
12708 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
12709 |
#$result["parentTable"]["dataCount"],爲取得的資料筆數。
|
|
|
12710 |
#必填參數:
|
|
|
12711 |
#$conf["dbAddress"],字串陣列,爲每個dbServer的位置。
|
|
|
12712 |
$conf["dbAddress"]=array($dbAddress);
|
|
|
12713 |
#$conf["dbAccount"],字串陣列,爲登入每個dbServer的帳號。
|
|
|
12714 |
$conf["dbAccount"]=array($dbAccount);
|
|
|
12715 |
#$conf["dbName"],字串陣列,爲每個要存取的資料庫名稱
|
|
|
12716 |
$conf["dbName"]=array($dbName);
|
|
|
12717 |
#$conf["tableName"],字串陣列,爲每個要存取的資料表名稱,$conf["tableName"][0]為父資料表.
|
|
|
12718 |
$conf["tableName"]=array("");
|
|
|
12719 |
#$conf["linkColumnName"]=array(array(""));#二維字串陣列,為可以從父表關連到其他資料表的欄位名稱.
|
|
|
12720 |
#$conf["linkColumnName"][$i]=array("parentColumnName","childColumnName"),為父資料表的"parentColumnName"欄位跟第$i+1個關聯資料表的"childColumnName"關聯.
|
|
|
12721 |
$conf["linkColumnName"]=array(array(""));
|
|
|
12722 |
#$conf["columnYouWant"]=array(array(""));#二維字串陣列,為每個資料表依序想要的欄位.
|
|
|
12723 |
$conf["columnYouWant"]=array(array(""));#二維字串陣列,為每個資料表依序想要的欄位.
|
|
|
12724 |
#可省略參數:
|
|
|
12725 |
#$conf["dbPassword"],字串陣列,爲要存取每個dbServer的密碼
|
|
|
12726 |
#$conf["dbPassword"]=array($dbPassword);
|
|
|
12727 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
|
|
|
12728 |
#$conf["dbPort"]="";
|
|
|
12729 |
#$conf["WhereColumnName"],字串陣列,用於判斷語句的欄位項目陣列。
|
|
|
12730 |
#$conf["WhereColumnName"]=array("");
|
|
|
12731 |
#$conf["WhereColumnValue"],字串陣列,用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
| 226 |
liveuser |
12732 |
#$conf["WhereColumnValue"]=array("");
|
| 3 |
liveuser |
12733 |
#$conf["WhereColumnCombine"],字串陣列,用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
12734 |
#$conf["WhereColumnCombine"]=array("");
|
|
|
12735 |
#$conf["WhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
12736 |
#$conf["WhereColumnOperator"]=array("");
|
|
|
12737 |
#$conf["WhereColumnAndOr"],字串陣列,用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
12738 |
#$conf["WhereColumnAndOr"]=array("");
|
|
|
12739 |
#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
|
|
|
12740 |
#$conf["whereIn"]=array(array("colName",array("a","b","c")));
|
|
|
12741 |
#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
|
|
|
12742 |
#$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
|
|
|
12743 |
#$conf["orderItem"],字串,排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
|
|
12744 |
#$conf["orderItem"]="";
|
|
|
12745 |
#$conf["ascORdesc"],字串,要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
|
|
12746 |
#$conf["ascORdesc"]="";
|
|
|
12747 |
#$conf["numberStart"],字串,從第幾筆開始讀取,預設為"0",代筆第一筆。
|
|
|
12748 |
#$conf["numberStart"]="0";
|
|
|
12749 |
#$conf["numLimit"],字串,要取幾筆資料,可以省略,省略則表示不限制數目。
|
|
|
12750 |
#$conf["numLimit"]="30";
|
|
|
12751 |
#$conf["groupBy"],字串陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
|
|
12752 |
#$conf["groupBy"]=array();
|
|
|
12753 |
#參考資料:
|
|
|
12754 |
#無.
|
|
|
12755 |
#備註:
|
|
|
12756 |
#無.
|
|
|
12757 |
*/
|
|
|
12758 |
public static function fastGetMultiLinkedDbData(&$conf){
|
| 226 |
liveuser |
12759 |
|
| 3 |
liveuser |
12760 |
#初始化要回傳的內容
|
|
|
12761 |
$result=array();
|
|
|
12762 |
|
|
|
12763 |
#取得當前執行的函數名稱
|
|
|
12764 |
$result["function"]=__FUNCTION__;
|
|
|
12765 |
|
|
|
12766 |
#如果 $conf 不為陣列
|
|
|
12767 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
12768 |
|
| 3 |
liveuser |
12769 |
#設置執行失敗
|
|
|
12770 |
$result["status"]="false";
|
| 226 |
liveuser |
12771 |
|
| 3 |
liveuser |
12772 |
#設置執行錯誤訊息
|
|
|
12773 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
12774 |
|
|
|
12775 |
#如果傳入的參數為 null
|
|
|
12776 |
if($conf==null){
|
| 226 |
liveuser |
12777 |
|
| 3 |
liveuser |
12778 |
#設置執行錯誤訊息
|
|
|
12779 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
12780 |
|
| 3 |
liveuser |
12781 |
}#if end
|
|
|
12782 |
|
|
|
12783 |
#回傳結果
|
|
|
12784 |
return $result;
|
| 226 |
liveuser |
12785 |
|
| 3 |
liveuser |
12786 |
}#if end
|
| 226 |
liveuser |
12787 |
|
| 3 |
liveuser |
12788 |
#檢查參數
|
|
|
12789 |
#函式說明:
|
|
|
12790 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
12791 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
12792 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
12793 |
#$result["function"],當前執行的函式名稱.
|
|
|
12794 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
12795 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
12796 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
12797 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
12798 |
#必填參數:
|
|
|
12799 |
#$conf["variableCheck.checkArguments"]["varInput"],陣列變數,要檢查的陣列變數.
|
|
|
12800 |
$conf["variableCheck.checkArguments"]["varInput"]=&$conf;
|
|
|
12801 |
#$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
12802 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","dbName","tableName","linkColumnName","columnYouWant");
|
| 226 |
liveuser |
12803 |
#$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
12804 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array("array","array","array","array","array","array");
|
|
|
12805 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
12806 |
$conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
|
|
|
12807 |
#可省略參數:
|
|
|
12808 |
#$conf["variableCheck.checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
|
|
|
12809 |
#$conf["variableCheck.checkArguments"]["canBeEmptyString"]="false";
|
|
|
12810 |
#$conf["variableCheck.checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
12811 |
$conf["variableCheck.checkArguments"]["skipableVariableName"]=array("dbPassword","WhereColumnName","WhereColumnValue","WhereColumnCombine","WhereColumnOperator","WhereColumnAndOr","orderItem","ascORdesc","numberStart","numLimit","groupBy","whereIn","whereNotIn");
|
| 226 |
liveuser |
12812 |
#$conf["variableCheck.checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
12813 |
$conf["variableCheck.checkArguments"]["skipableVariableType"]=array("array","array","array","array","array","array","string","string","string","string","array","array","array");
|
|
|
12814 |
#$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定.
|
|
|
12815 |
#$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"]=array("");
|
|
|
12816 |
$checkResult=variableCheck::checkArguments($conf["variableCheck.checkArguments"]);
|
|
|
12817 |
unset($conf["variableCheck.checkArguments"]);
|
| 226 |
liveuser |
12818 |
|
| 3 |
liveuser |
12819 |
#如果檢查出錯
|
|
|
12820 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
12821 |
|
| 3 |
liveuser |
12822 |
#設置錯誤識別
|
|
|
12823 |
$result["status"]="false";
|
| 226 |
liveuser |
12824 |
|
| 3 |
liveuser |
12825 |
#設置錯誤訊息
|
|
|
12826 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
12827 |
|
| 3 |
liveuser |
12828 |
#回傳結果
|
|
|
12829 |
return $result;
|
| 226 |
liveuser |
12830 |
|
| 3 |
liveuser |
12831 |
}#if end
|
| 226 |
liveuser |
12832 |
|
| 3 |
liveuser |
12833 |
#如果檢查出錯
|
|
|
12834 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
12835 |
|
| 3 |
liveuser |
12836 |
#設置錯誤識別
|
|
|
12837 |
$result["status"]="false";
|
| 226 |
liveuser |
12838 |
|
| 3 |
liveuser |
12839 |
#設置錯誤訊息
|
|
|
12840 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
12841 |
|
| 3 |
liveuser |
12842 |
#回傳結果
|
|
|
12843 |
return $result;
|
| 226 |
liveuser |
12844 |
|
| 3 |
liveuser |
12845 |
}#if end
|
| 226 |
liveuser |
12846 |
|
| 3 |
liveuser |
12847 |
#取得父表的資料
|
|
|
12848 |
#函式說明:
|
|
|
12849 |
#一次取得資料庫、表的資料
|
|
|
12850 |
#回傳結果:
|
|
|
12851 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
12852 |
#$result["error"],錯誤訊息陣列。
|
|
|
12853 |
#$result["dataContent"],爲資料的內容。
|
|
|
12854 |
#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
12855 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
12856 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
12857 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
12858 |
#必填參數:
|
|
|
12859 |
$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"][0];#爲dbServer的位置。
|
|
|
12860 |
$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"][0];#爲登入dbServer的帳號。
|
|
|
12861 |
$conf["db"]["fastGetDbData"]["dbName"]=$conf["dbName"][0];#爲要存取的資料庫名稱
|
|
|
12862 |
$conf["db"]["fastGetDbData"]["tableName"]=$conf["tableName"][0];#爲要存取的資料表名稱
|
|
|
12863 |
$conf["db"]["fastGetDbData"]["columnYouWant"]=$conf["columnYouWant"][0];#你想要的欄位!
|
|
|
12864 |
#可省略參數:
|
| 226 |
liveuser |
12865 |
|
| 3 |
liveuser |
12866 |
#如果 $conf["dbPassword"][0] 有設置
|
|
|
12867 |
if(isset($conf["dbPassword"][0])){
|
| 226 |
liveuser |
12868 |
|
| 3 |
liveuser |
12869 |
$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"][0];#爲要存取dbServer的密碼
|
| 226 |
liveuser |
12870 |
|
| 3 |
liveuser |
12871 |
}#if end
|
| 226 |
liveuser |
12872 |
|
| 3 |
liveuser |
12873 |
#如果 $conf["WhereColumnName"] 有設置
|
|
|
12874 |
if(isset($conf["WhereColumnName"])){
|
| 226 |
liveuser |
12875 |
|
| 3 |
liveuser |
12876 |
$conf["db"]["fastGetDbData"]["WhereColumnName"]=$conf["WhereColumnName"];#用於判斷語句的欄位項目陣列。
|
| 226 |
liveuser |
12877 |
|
| 3 |
liveuser |
12878 |
}#if end
|
| 226 |
liveuser |
12879 |
|
| 3 |
liveuser |
12880 |
#如果 $conf["WhereColumnValue"] 有設置
|
|
|
12881 |
if(isset($conf["WhereColumnValue"])){
|
| 226 |
liveuser |
12882 |
|
| 3 |
liveuser |
12883 |
$conf["db"]["fastGetDbData"]["WhereColumnValue"]=$conf["WhereColumnValue"];#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
| 226 |
liveuser |
12884 |
|
| 3 |
liveuser |
12885 |
}#if end
|
| 226 |
liveuser |
12886 |
|
| 3 |
liveuser |
12887 |
#如果 $conf["WhereColumnCombine"] 有設置
|
|
|
12888 |
if(isset($conf["WhereColumnCombine"])){
|
| 226 |
liveuser |
12889 |
|
| 3 |
liveuser |
12890 |
$conf["db"]["fastGetDbData"]["WhereColumnCombine"]=$conf["WhereColumnCombine"];#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
| 226 |
liveuser |
12891 |
|
| 3 |
liveuser |
12892 |
}#if end
|
| 226 |
liveuser |
12893 |
|
| 3 |
liveuser |
12894 |
#如果 $conf["WhereColumnOperator"] 有設置
|
|
|
12895 |
if(isset($conf["WhereColumnOperator"])){
|
| 226 |
liveuser |
12896 |
|
| 3 |
liveuser |
12897 |
$conf["db"]["fastGetDbData"]["WhereColumnOperator"]=$conf["WhereColumnOperator"];#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
| 226 |
liveuser |
12898 |
|
| 3 |
liveuser |
12899 |
}#if end
|
| 226 |
liveuser |
12900 |
|
| 3 |
liveuser |
12901 |
#如果 $conf["WhereColumnAndOr"][$i] 有設置
|
|
|
12902 |
if(isset($conf["WhereColumnAndOr"])){
|
| 226 |
liveuser |
12903 |
|
| 3 |
liveuser |
12904 |
$conf["db"]["fastGetDbData"]["WhereColumnAndOr"]=$conf["WhereColumnAndOr"];#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
| 226 |
liveuser |
12905 |
|
| 3 |
liveuser |
12906 |
}#if end
|
| 226 |
liveuser |
12907 |
|
| 3 |
liveuser |
12908 |
#如果 $conf["orderItem"] 有設置
|
|
|
12909 |
if(isset($conf["orderItem"])){
|
| 226 |
liveuser |
12910 |
|
| 3 |
liveuser |
12911 |
$conf["db"]["fastGetDbData"]["orderItem"]=$conf["orderItem"];#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
| 226 |
liveuser |
12912 |
|
| 3 |
liveuser |
12913 |
}#if end
|
| 226 |
liveuser |
12914 |
|
| 3 |
liveuser |
12915 |
#如果 $conf["ascORdesc"] 有設置
|
|
|
12916 |
if(isset($conf["ascORdesc"])){
|
| 226 |
liveuser |
12917 |
|
| 3 |
liveuser |
12918 |
$conf["db"]["fastGetDbData"]["ascORdesc"]=$conf["ascORdesc"];#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
| 226 |
liveuser |
12919 |
|
| 3 |
liveuser |
12920 |
}#if end
|
| 226 |
liveuser |
12921 |
|
| 3 |
liveuser |
12922 |
#如果 $conf["numberStart"] 有設置
|
|
|
12923 |
if(isset($conf["numberStart"])){
|
| 226 |
liveuser |
12924 |
|
| 3 |
liveuser |
12925 |
$conf["db"]["fastGetDbData"]["numberStart"]=$conf["numberStart"];#為從第幾筆開始讀取,預設為0,代筆第一筆。
|
| 226 |
liveuser |
12926 |
|
| 3 |
liveuser |
12927 |
}#if end
|
| 226 |
liveuser |
12928 |
|
| 3 |
liveuser |
12929 |
#如果 $conf["numLimit"] 有設置
|
|
|
12930 |
if(isset($conf["numLimit"])){
|
| 226 |
liveuser |
12931 |
|
| 3 |
liveuser |
12932 |
$conf["db"]["fastGetDbData"]["numLimit"]=$conf["numLimit"];#為要取幾筆資料,可以省略,省略則表示不限制數目。
|
| 226 |
liveuser |
12933 |
|
| 3 |
liveuser |
12934 |
}#if end
|
| 226 |
liveuser |
12935 |
|
| 3 |
liveuser |
12936 |
#如果 $conf["groupBy"] 有設置
|
|
|
12937 |
if(isset($conf["groupBy"])){
|
| 226 |
liveuser |
12938 |
|
| 3 |
liveuser |
12939 |
$conf["db"]["fastGetDbData"]["groupBy"]=$conf["groupBy"];#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
| 226 |
liveuser |
12940 |
|
| 3 |
liveuser |
12941 |
}#if end
|
| 226 |
liveuser |
12942 |
|
| 3 |
liveuser |
12943 |
#如果 $conf["whereIn"] 存在
|
|
|
12944 |
if(isset($conf["whereIn"])){
|
| 226 |
liveuser |
12945 |
|
| 177 |
liveuser |
12946 |
#where in 條件
|
| 3 |
liveuser |
12947 |
$conf["db"]["fastGetDbData"]["whereIn"]=$conf["whereIn"];
|
| 226 |
liveuser |
12948 |
|
| 3 |
liveuser |
12949 |
}#if end
|
| 226 |
liveuser |
12950 |
|
| 3 |
liveuser |
12951 |
#如果 $conf["whereNotIn"] 存在
|
|
|
12952 |
if(isset($conf["whereNotIn"])){
|
| 226 |
liveuser |
12953 |
|
|
|
12954 |
#where not in 條件
|
| 3 |
liveuser |
12955 |
$conf["db"]["fastGetDbData"]["whereNotIn"]=$conf["whereNotIn"];
|
| 226 |
liveuser |
12956 |
|
| 3 |
liveuser |
12957 |
}#if end
|
| 226 |
liveuser |
12958 |
|
| 3 |
liveuser |
12959 |
#儲存到 $result["mainTable"] 陣列裡面
|
|
|
12960 |
$result["parentTable"]=db::fastGetDbData($conf["db"]["fastGetDbData"]);
|
|
|
12961 |
unset($conf["db"]["fastGetDbData"]);
|
| 226 |
liveuser |
12962 |
|
| 3 |
liveuser |
12963 |
#如果 $result["mainTable"]["status"] 為 "false"
|
|
|
12964 |
if($result["parentTable"]["status"]=="false"){
|
| 226 |
liveuser |
12965 |
|
| 3 |
liveuser |
12966 |
#取得錯誤訊息
|
|
|
12967 |
$result["error"]=$result["parentTable"]["error"];
|
| 226 |
liveuser |
12968 |
|
| 3 |
liveuser |
12969 |
#設置執行結果為 "false"
|
|
|
12970 |
$result["status"]="false";
|
| 226 |
liveuser |
12971 |
|
| 3 |
liveuser |
12972 |
#回傳結果
|
|
|
12973 |
return $result;
|
| 226 |
liveuser |
12974 |
|
| 3 |
liveuser |
12975 |
}#if end
|
| 226 |
liveuser |
12976 |
|
| 3 |
liveuser |
12977 |
#根據 $conf["linkColumnName"] 的數量
|
|
|
12978 |
for($i=0;$i<count($conf["linkColumnName"]);$i++){
|
| 226 |
liveuser |
12979 |
|
| 3 |
liveuser |
12980 |
#取得父資料表的關聯欄位名稱
|
|
|
12981 |
$parentTableLinkColumnName=$conf["linkColumnName"][$i][0];
|
| 226 |
liveuser |
12982 |
|
| 3 |
liveuser |
12983 |
#取得子資料表的關聯欄位名稱
|
|
|
12984 |
$childTableLinkColumnName=$conf["linkColumnName"][$i][1];
|
| 226 |
liveuser |
12985 |
|
| 3 |
liveuser |
12986 |
#根據父資料表的資料筆數
|
|
|
12987 |
for($j=0;$j<$result["parentTable"]["dataCount"];$j++){
|
| 226 |
liveuser |
12988 |
|
| 3 |
liveuser |
12989 |
#如果要連結的欄位不在 select 的欄位裡面
|
|
|
12990 |
if(!isset($result["parentTable"]["dataContent"][$parentTableLinkColumnName])){
|
| 226 |
liveuser |
12991 |
|
| 3 |
liveuser |
12992 |
#設置執行錯誤
|
|
|
12993 |
$result["status"]="false";
|
|
|
12994 |
|
|
|
12995 |
#設置執行錯誤內容
|
|
|
12996 |
$result["error"]="欄位 ".$parentTableLinkColumnName." 必須在參數 columnYouWant 裡面.";
|
| 226 |
liveuser |
12997 |
|
| 3 |
liveuser |
12998 |
#回傳結果
|
|
|
12999 |
return $result;
|
| 226 |
liveuser |
13000 |
|
| 3 |
liveuser |
13001 |
}#if end
|
| 226 |
liveuser |
13002 |
|
| 3 |
liveuser |
13003 |
#父資料表第$j筆資料關聯欄位的數值內容
|
|
|
13004 |
$parentTableLinkColumnValue=$result["parentTable"]["dataContent"][$parentTableLinkColumnName][$j];
|
| 226 |
liveuser |
13005 |
|
| 3 |
liveuser |
13006 |
#var_dump($parentTableLinkColumnValue);
|
| 226 |
liveuser |
13007 |
|
| 3 |
liveuser |
13008 |
#根據第$j筆資料的父關聯欄位數值來尋找子關聯資料表的欄位數值
|
|
|
13009 |
#函式說明:
|
|
|
13010 |
#一次取得資料庫、表的資料
|
|
|
13011 |
#回傳結果:
|
|
|
13012 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
13013 |
#$result["error"],錯誤訊息陣列。
|
|
|
13014 |
#$result["dataContent"],爲資料的內容。
|
|
|
13015 |
#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
13016 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
13017 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
13018 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
13019 |
#必填參數:
|
|
|
13020 |
$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"][$i+1];#爲dbServer的位置。
|
|
|
13021 |
$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"][$i+1];#爲登入dbServer的帳號。
|
|
|
13022 |
$conf["db"]["fastGetDbData"]["dbName"]=$conf["dbName"][$i+1];#爲要存取的資料庫名稱
|
|
|
13023 |
$conf["db"]["fastGetDbData"]["tableName"]=$conf["tableName"][$i+1];#爲要存取的資料表名稱
|
|
|
13024 |
$conf["db"]["fastGetDbData"]["columnYouWant"]=$conf["columnYouWant"][$i+1];#你想要的欄位!
|
|
|
13025 |
#可省略參數:
|
| 226 |
liveuser |
13026 |
|
| 3 |
liveuser |
13027 |
#如果 $conf["dbPassword"][$i+1] 有設定
|
|
|
13028 |
if(isset($conf["dbPassword"][$i+1])){
|
| 226 |
liveuser |
13029 |
|
| 3 |
liveuser |
13030 |
#則設置其連線密碼
|
|
|
13031 |
$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"][$i+1];#爲要存取dbServer的密碼
|
| 226 |
liveuser |
13032 |
|
| 3 |
liveuser |
13033 |
}#if end
|
| 226 |
liveuser |
13034 |
|
| 3 |
liveuser |
13035 |
#如果 $conf["dbPort"][$i+1] 有設定
|
|
|
13036 |
if(isset($conf["dbPort"][$i+1])){
|
| 226 |
liveuser |
13037 |
|
| 3 |
liveuser |
13038 |
#則設置其連線的 port
|
|
|
13039 |
$conf["db"]["fastGetDbData"]["dbPort"]=$conf["dbPort"][$i+1];#爲要存取dbServer的port
|
| 226 |
liveuser |
13040 |
|
| 3 |
liveuser |
13041 |
}#if end
|
| 226 |
liveuser |
13042 |
|
| 3 |
liveuser |
13043 |
$conf["db"]["fastGetDbData"]["WhereColumnName"]=array($childTableLinkColumnName);#用於判斷語句的欄位項目陣列。
|
|
|
13044 |
$conf["db"]["fastGetDbData"]["WhereColumnValue"]=array($parentTableLinkColumnValue);#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
|
|
13045 |
#$conf["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
13046 |
#$conf["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
13047 |
#$conf["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
13048 |
#$conf["orderItem"]="";#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
|
|
13049 |
#$conf["ascORdesc"]="";#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
|
|
13050 |
#$conf["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
|
|
|
13051 |
#$conf["numLimit"]="30";#為要取幾筆資料,可以省略,省略則表示不限制數目。
|
|
|
13052 |
#$conf["groupBy"]=array("");#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
|
|
13053 |
$childTable[$j]=db::fastGetDbData($conf["db"]["fastGetDbData"]);
|
|
|
13054 |
unset($conf["db"]["fastGetDbData"]);
|
| 226 |
liveuser |
13055 |
|
| 3 |
liveuser |
13056 |
#如果取得資料失敗
|
|
|
13057 |
if($childTable[$j]["status"]=="false"){
|
| 226 |
liveuser |
13058 |
|
| 3 |
liveuser |
13059 |
#取得錯誤訊息
|
|
|
13060 |
$result["error"]=$childTable[$j];
|
| 226 |
liveuser |
13061 |
|
| 3 |
liveuser |
13062 |
#設置執行結果為 "false"
|
|
|
13063 |
$result["status"]="false";
|
| 226 |
liveuser |
13064 |
|
| 3 |
liveuser |
13065 |
#回傳結果
|
|
|
13066 |
return $result;
|
| 226 |
liveuser |
13067 |
|
| 3 |
liveuser |
13068 |
}#if end
|
| 226 |
liveuser |
13069 |
|
| 3 |
liveuser |
13070 |
#如果 $childTable[$j]["dataContent"] 有設置,則代表有符合的資料
|
|
|
13071 |
if(isset($childTable[$j]["dataContent"])){
|
| 226 |
liveuser |
13072 |
|
| 3 |
liveuser |
13073 |
#針對每個取得的新欄位
|
|
|
13074 |
foreach($childTable[$j]["dataContent"] as $newColumnNameArray=>$newColumnNameValue){
|
| 226 |
liveuser |
13075 |
|
| 3 |
liveuser |
13076 |
#新增第$j筆的欄位名稱與數值
|
|
|
13077 |
$result["parentTable"]["dataContent"][$conf["tableName"][$i+1].".".$newColumnNameArray][$j]=$newColumnNameValue[0];
|
| 226 |
liveuser |
13078 |
|
| 3 |
liveuser |
13079 |
}#foreach end
|
| 226 |
liveuser |
13080 |
|
| 3 |
liveuser |
13081 |
}#if end
|
| 226 |
liveuser |
13082 |
|
| 3 |
liveuser |
13083 |
#反之代表 $childTable[$j]["dataContent"] 沒有設置,沒有符合的資料
|
|
|
13084 |
else{
|
| 226 |
liveuser |
13085 |
|
| 3 |
liveuser |
13086 |
#根據每個要取得的欄位名稱
|
|
|
13087 |
foreach($conf["columnYouWant"][$i+1] as $newColumnName){
|
| 226 |
liveuser |
13088 |
|
| 3 |
liveuser |
13089 |
#新增第$j筆的欄位名稱與數值
|
|
|
13090 |
$result["parentTable"]["dataContent"][$conf["tableName"][$i+1].".".$newColumnName][$j]="";
|
| 226 |
liveuser |
13091 |
|
| 3 |
liveuser |
13092 |
}#foreach end
|
| 226 |
liveuser |
13093 |
|
| 3 |
liveuser |
13094 |
}#else end
|
| 226 |
liveuser |
13095 |
|
| 3 |
liveuser |
13096 |
}#for end
|
| 226 |
liveuser |
13097 |
|
| 3 |
liveuser |
13098 |
}#for end
|
| 226 |
liveuser |
13099 |
|
| 3 |
liveuser |
13100 |
#執行到這邊代表執行成功
|
|
|
13101 |
#設置執行結果為 "true"
|
|
|
13102 |
$result["status"]="true";
|
| 226 |
liveuser |
13103 |
|
| 3 |
liveuser |
13104 |
#回傳結果
|
|
|
13105 |
return $result;
|
| 226 |
liveuser |
13106 |
|
| 3 |
liveuser |
13107 |
}#function fastGetMutiLinkedDbData end
|
| 226 |
liveuser |
13108 |
|
| 3 |
liveuser |
13109 |
/*
|
|
|
13110 |
#函式說明:
|
|
|
13111 |
#透過php來join多張資料表資料,提供各個欄位的包含資料庫、資料表、的資訊,會產生sql inner join的效果,資料會越來越多.
|
|
|
13112 |
#回傳結果:
|
|
|
13113 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
13114 |
#$result["error"],錯誤訊息陣列。
|
|
|
13115 |
#$reuslt["function"],當前執行的函數
|
|
|
13116 |
#$result["content"],爲合併了子資料表欄位的父資料表的內容。
|
|
|
13117 |
#$result["content"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
13118 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
13119 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
13120 |
#$result["parentTable"]["dataCount"],爲取得的資料筆數。
|
|
|
13121 |
#必填參數:
|
|
|
13122 |
#$conf["dbInfo"]["資料庫名稱"],字串陣列,爲要存取的"資料庫名稱"的連線資訊.
|
|
|
13123 |
#$conf["dbIfno"]["資料庫名稱"]["dbAddr"],字串,dbServer的位置.
|
|
|
13124 |
#$conf["dbInfo"]["資料庫名稱"]["dbAddr"]="";
|
|
|
13125 |
#$conf["dbIfno"]["資料庫名稱"]["dbAcct"],字串,dbServer的連線帳號.
|
| 207 |
liveuser |
13126 |
#$conf["dbInfo"]["資料庫名稱"]["dbAcct"]="";
|
| 3 |
liveuser |
13127 |
#$conf["mainTable"],字串,為 主資料庫.資料表 的名稱,例如 "dbA.dtA".
|
|
|
13128 |
$conf["mainTable"]="";
|
| 207 |
liveuser |
13129 |
#可省略參數:
|
| 3 |
liveuser |
13130 |
#$conf["linkColumnName"],二字串陣列,為資料表間相連結的欄位名稱,格式為 array("mergedDb.mergedDt.mergedCol","linkDb.linkDt.linkCol") 就代表當前組好的欄位 mergedDb.mergedDt.mergedCol 跟資料庫 linkDB 表 linkDt 欄位 linkCol 進行資料的配對。
|
| 207 |
liveuser |
13131 |
#$conf["linkColumnName"]=array(array(""));
|
| 3 |
liveuser |
13132 |
#$conf["dbInfo"]["資料庫名稱"]["dbPass"],字串,dbServer的連線密碼.
|
|
|
13133 |
#$conf["dbInfo"]["資料庫名稱"]["dbPass"]="";
|
|
|
13134 |
#$conf["dbInfo"]["資料庫名稱"]["dbPort"],字串,db連線用的port.
|
|
|
13135 |
#$conf["dbInfo"]["資料庫名稱"]["dbPort"]="";
|
|
|
13136 |
#$conf["columnYouWant"],字串陣列,為想要的資料表欄位,格式為 "dbName.dtName.colName".
|
|
|
13137 |
#$conf["columnYouWant"]=array();
|
|
|
13138 |
#$conf["mainDtWhereColName"],字串陣列,用於主表判斷語句的欄位項目陣列.
|
|
|
13139 |
#$conf["mainDtWhereColName"]=array("");
|
|
|
13140 |
#$conf["mainDtWhereColVal"]=,字串陣列,用於主表判斷語句的欄位項目數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容.
|
|
|
13141 |
#$conf["mainDtWhereColVal"]=array("");
|
|
|
13142 |
#$conf["mainDtWhereColCombine"],字串陣列,用於主表判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
13143 |
#$conf["mainDtWhereColCombine"]=array("");
|
|
|
13144 |
#$conf["mainWhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
13145 |
#$conf["mainWhereColumnOperator"]=array("");
|
|
|
13146 |
#$conf["mainWhereColumnAndOr"],字串陣列,用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
13147 |
#$conf["mainWhereColumnAndOr"]=array("");
|
|
|
13148 |
#$conf["mainWhereIn"],字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
|
|
|
13149 |
#$conf["mainWhereIn"]=array(array("colName",array("a","b","c")));
|
|
|
13150 |
#$conf["mainWhereNotIn"],字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
|
|
|
13151 |
#$conf["mainWhereNotIn"]=array(array("colName",array("a","b","c")));
|
|
|
13152 |
#$conf["mainNumberStart"],字串,從第幾筆開始讀取,預設為"0",代筆第一筆。
|
|
|
13153 |
#$conf["mainNumberStart"]="0";
|
|
|
13154 |
#$conf["mainNumLimit"],字串,要取幾筆資料,可以省略,省略則表示不限制數目.
|
|
|
13155 |
#$conf["mainNumLimit"]="30";
|
|
|
13156 |
#$conf["mainGroupBy"],字串陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
|
|
13157 |
#$conf["mainGroupBy"]=array();
|
|
|
13158 |
#$conf["mainOrderItem"],字串,組好的資料的排序項目依據
|
|
|
13159 |
#$conf["mainOrderItem"]="";
|
|
|
13160 |
#$conf["mainAscORdesc"],字串,組好的資料要低增還是遞減排序,asc爲遞增;desc爲遞減,預設不做處理.
|
| 207 |
liveuser |
13161 |
#$conf["mainAscORdesc"]="";
|
| 3 |
liveuser |
13162 |
#參考資料:
|
|
|
13163 |
#無.
|
|
|
13164 |
#備註:
|
|
|
13165 |
#無.
|
|
|
13166 |
*/
|
|
|
13167 |
public static function joinByPHP(&$conf=array()){
|
| 226 |
liveuser |
13168 |
|
| 3 |
liveuser |
13169 |
#初始化要回傳的內容
|
|
|
13170 |
$result=array();
|
|
|
13171 |
|
|
|
13172 |
#取得當前執行的函數名稱
|
|
|
13173 |
$result["function"]=__FUNCTION__;
|
|
|
13174 |
|
|
|
13175 |
#如果 $conf 不為陣列
|
|
|
13176 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
13177 |
|
| 3 |
liveuser |
13178 |
#設置執行失敗
|
|
|
13179 |
$result["status"]="false";
|
| 226 |
liveuser |
13180 |
|
| 3 |
liveuser |
13181 |
#設置執行錯誤訊息
|
|
|
13182 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
13183 |
|
|
|
13184 |
#如果傳入的參數為 null
|
|
|
13185 |
if($conf==null){
|
| 226 |
liveuser |
13186 |
|
| 3 |
liveuser |
13187 |
#設置執行錯誤訊息
|
|
|
13188 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
13189 |
|
| 3 |
liveuser |
13190 |
}#if end
|
|
|
13191 |
|
|
|
13192 |
#回傳結果
|
|
|
13193 |
return $result;
|
| 226 |
liveuser |
13194 |
|
| 3 |
liveuser |
13195 |
}#if end
|
| 226 |
liveuser |
13196 |
|
| 3 |
liveuser |
13197 |
#檢查參數
|
|
|
13198 |
#函式說明:
|
|
|
13199 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
13200 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13201 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
13202 |
#$result["function"],當前執行的函式名稱.
|
|
|
13203 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
13204 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
13205 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
13206 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
13207 |
#必填參數:
|
|
|
13208 |
#$conf["variableCheck.checkArguments"]["varInput"],陣列變數,要檢查的陣列變數.
|
|
|
13209 |
$conf["variableCheck.checkArguments"]["varInput"]=&$conf;
|
|
|
13210 |
#$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
13211 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("dbInfo","mainTable","linkColumnName");
|
| 226 |
liveuser |
13212 |
#$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
13213 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array("array","string","array");
|
|
|
13214 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
13215 |
$conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
|
|
|
13216 |
#可省略參數:
|
|
|
13217 |
#$conf["variableCheck.checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
|
|
|
13218 |
#$conf["variableCheck.checkArguments"]["canBeEmptyString"]="false";
|
|
|
13219 |
#$conf["variableCheck.checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 207 |
liveuser |
13220 |
$conf["variableCheck.checkArguments"]["skipableVariableName"]=array("linkColumnName","columnYouWant","mainDtWhereColName","mainDtWhereColVal","mainDtWhereColCombine","mainWhereColumnOperator","mainWhereColumnAndOr","mainWhereIn","mainWhereNotIn","mainNumberStart","mainNumLimit","mainGroupBy","mainOrderItem","mainAscORdesc");
|
| 226 |
liveuser |
13221 |
#$conf["variableCheck.checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 207 |
liveuser |
13222 |
$conf["variableCheck.checkArguments"]["skipableVariableType"]=array("array","array","array","array","array","array","array","array","array","string","string","array","string","string");
|
| 3 |
liveuser |
13223 |
#$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定.
|
| 207 |
liveuser |
13224 |
$conf["variableCheck.checkArguments"]["skipableVarDefaultValue"]=array(array(),null,null,null,null,null,null,null,null,null,null,null,null,null);
|
| 3 |
liveuser |
13225 |
$checkResult=variableCheck::checkArguments($conf["variableCheck.checkArguments"]);
|
|
|
13226 |
unset($conf["variableCheck.checkArguments"]);
|
| 226 |
liveuser |
13227 |
|
| 3 |
liveuser |
13228 |
#如果檢查出錯
|
|
|
13229 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
13230 |
|
| 3 |
liveuser |
13231 |
#設置錯誤識別
|
|
|
13232 |
$result["status"]="false";
|
| 226 |
liveuser |
13233 |
|
| 3 |
liveuser |
13234 |
#設置錯誤訊息
|
|
|
13235 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
13236 |
|
| 3 |
liveuser |
13237 |
#回傳結果
|
|
|
13238 |
return $result;
|
| 226 |
liveuser |
13239 |
|
| 3 |
liveuser |
13240 |
}#if end
|
| 226 |
liveuser |
13241 |
|
| 3 |
liveuser |
13242 |
#如果檢查出錯
|
|
|
13243 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
13244 |
|
| 3 |
liveuser |
13245 |
#設置錯誤識別
|
|
|
13246 |
$result["status"]="false";
|
| 226 |
liveuser |
13247 |
|
| 3 |
liveuser |
13248 |
#設置錯誤訊息
|
|
|
13249 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
13250 |
|
| 3 |
liveuser |
13251 |
#回傳結果
|
|
|
13252 |
return $result;
|
| 226 |
liveuser |
13253 |
|
| 3 |
liveuser |
13254 |
}#if end
|
| 226 |
liveuser |
13255 |
|
| 3 |
liveuser |
13256 |
#取得 $conf["mainTable"] 的資料
|
| 226 |
liveuser |
13257 |
|
| 3 |
liveuser |
13258 |
#檢查主表是否為 db.dt 的
|
|
|
13259 |
$foundDot=strpos($conf["mainTable"],'.');
|
| 226 |
liveuser |
13260 |
|
| 3 |
liveuser |
13261 |
#如果不是
|
|
|
13262 |
if(!$foundDot){
|
| 226 |
liveuser |
13263 |
|
| 3 |
liveuser |
13264 |
#設置錯誤識別
|
|
|
13265 |
$result["status"]="false";
|
| 226 |
liveuser |
13266 |
|
| 3 |
liveuser |
13267 |
#設置錯誤訊息
|
|
|
13268 |
$result["error"][]="參數 \$conf[\"mainTable\"] 必須為 資料庫名稱.資料表名稱";
|
| 226 |
liveuser |
13269 |
|
| 3 |
liveuser |
13270 |
#回傳結果
|
|
|
13271 |
return $result;
|
| 226 |
liveuser |
13272 |
|
| 3 |
liveuser |
13273 |
}#if end
|
| 226 |
liveuser |
13274 |
|
| 3 |
liveuser |
13275 |
#反之
|
|
|
13276 |
else{
|
| 226 |
liveuser |
13277 |
|
| 3 |
liveuser |
13278 |
#用 . 去切割字串
|
|
|
13279 |
$dbdtsplitedstr=explode('.',$conf["mainTable"]);
|
| 226 |
liveuser |
13280 |
|
| 3 |
liveuser |
13281 |
#如果切割出來不等於兩段
|
|
|
13282 |
if(count($dbdtsplitedstr)!==2){
|
| 226 |
liveuser |
13283 |
|
| 3 |
liveuser |
13284 |
#設置錯誤識別
|
|
|
13285 |
$result["status"]="false";
|
| 226 |
liveuser |
13286 |
|
| 3 |
liveuser |
13287 |
#設置錯誤訊息
|
|
|
13288 |
$result["error"][]="參數 \$conf[\"mainTable\"] 必須為 資料庫名稱.資料表名稱";
|
| 226 |
liveuser |
13289 |
|
| 3 |
liveuser |
13290 |
#回傳結果
|
|
|
13291 |
return $result;
|
| 226 |
liveuser |
13292 |
|
| 3 |
liveuser |
13293 |
}#if end
|
| 226 |
liveuser |
13294 |
|
| 3 |
liveuser |
13295 |
#取得 mainTable 的 db name
|
|
|
13296 |
$mainDb=&$dbdtsplitedstr[0];
|
| 226 |
liveuser |
13297 |
|
| 3 |
liveuser |
13298 |
#取得 mainTable 的名稱
|
|
|
13299 |
$mainDt=&$dbdtsplitedstr[1];
|
| 226 |
liveuser |
13300 |
|
| 3 |
liveuser |
13301 |
}#else end
|
| 226 |
liveuser |
13302 |
|
| 3 |
liveuser |
13303 |
#若主資料表連線參數不存在
|
|
|
13304 |
if(!isset($conf["dbInfo"][$mainDb])){
|
| 226 |
liveuser |
13305 |
|
| 3 |
liveuser |
13306 |
#設置錯誤識別
|
|
|
13307 |
$result["status"]="false";
|
| 226 |
liveuser |
13308 |
|
| 3 |
liveuser |
13309 |
#設置錯誤訊息
|
|
|
13310 |
$result["error"][]="參數 \$conf[\"dbInfo\"][$mainDb] 必須提供";
|
| 226 |
liveuser |
13311 |
|
| 3 |
liveuser |
13312 |
#回傳結果
|
|
|
13313 |
return $result;
|
| 226 |
liveuser |
13314 |
|
| 3 |
liveuser |
13315 |
}#if end
|
| 226 |
liveuser |
13316 |
|
| 3 |
liveuser |
13317 |
#檢查主表的參數
|
|
|
13318 |
#函式說明:
|
|
|
13319 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
13320 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13321 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
13322 |
#$result["function"],當前執行的函式名稱.
|
|
|
13323 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
13324 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
13325 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
13326 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
13327 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
13328 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
13329 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
13330 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
13331 |
#必填參數:
|
|
|
13332 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
13333 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf["dbInfo"][$mainDb];
|
| 3 |
liveuser |
13334 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
13335 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
13336 |
#可以省略的參數:
|
|
|
13337 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
13338 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddr","dbAcct");
|
|
|
13339 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
13340 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
13341 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
13342 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
13343 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
13344 |
#$conf["canNotBeEmpty"]=array();
|
|
|
13345 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
13346 |
#$conf["canBeEmpty"]=array();
|
|
|
13347 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
13348 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("dbPass","dbPort");
|
|
|
13349 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
13350 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPass","dbPort");
|
| 226 |
liveuser |
13351 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
13352 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
13353 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
13354 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null);
|
|
|
13355 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
13356 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
13357 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
13358 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
13359 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
13360 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
13361 |
#參考資料:
|
|
|
13362 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
13363 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
13364 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
13365 |
|
| 3 |
liveuser |
13366 |
#如果執行失敗
|
|
|
13367 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
13368 |
|
| 3 |
liveuser |
13369 |
#設置錯誤識別
|
|
|
13370 |
$result["status"]="false";
|
| 226 |
liveuser |
13371 |
|
| 3 |
liveuser |
13372 |
#設置錯誤訊息
|
|
|
13373 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
13374 |
|
| 3 |
liveuser |
13375 |
#回傳結果
|
|
|
13376 |
return $result;
|
| 226 |
liveuser |
13377 |
|
| 3 |
liveuser |
13378 |
}#if end
|
| 226 |
liveuser |
13379 |
|
| 3 |
liveuser |
13380 |
#如果檢查不通過
|
|
|
13381 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
13382 |
|
| 3 |
liveuser |
13383 |
#設置錯誤識別
|
|
|
13384 |
$result["status"]="false";
|
| 226 |
liveuser |
13385 |
|
| 3 |
liveuser |
13386 |
#設置錯誤訊息
|
|
|
13387 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
13388 |
|
| 3 |
liveuser |
13389 |
#回傳結果
|
|
|
13390 |
return $result;
|
| 226 |
liveuser |
13391 |
|
| 3 |
liveuser |
13392 |
}#if end
|
| 226 |
liveuser |
13393 |
|
| 3 |
liveuser |
13394 |
#函式說明:
|
|
|
13395 |
#一次取得資料庫、表的資料
|
|
|
13396 |
#回傳結果:
|
|
|
13397 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
13398 |
#$result["error"],錯誤訊息陣列。
|
|
|
13399 |
#$result["function"],當前執行的漢書名稱.
|
|
|
13400 |
#$result["dataColumnName"],抓取的資料欄位名稱陣列.
|
|
|
13401 |
#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
|
|
|
13402 |
#$result["dataContent"],爲資料的內容。
|
|
|
13403 |
#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
13404 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
13405 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
13406 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
13407 |
#$result["sql"],執行的sql字串.
|
|
|
13408 |
#必填參數:
|
|
|
13409 |
$conf["db::fastGetDbData"]["dbAddress"]=$conf["dbInfo"][$mainDb]["dbAddr"];#爲dbServer的位置。
|
|
|
13410 |
$conf["db::fastGetDbData"]["dbAccount"]=$conf["dbInfo"][$mainDb]["dbAcct"];#爲登入dbServer的帳號。
|
|
|
13411 |
$conf["db::fastGetDbData"]["dbName"]=$mainDb;#爲要存取的資料庫名稱
|
|
|
13412 |
$conf["db::fastGetDbData"]["tableName"]=$mainDt;#爲要存取的資料表名稱
|
|
|
13413 |
$conf["db::fastGetDbData"]["columnYouWant"]=array("*");#你想要的欄位!,若設為「array("*")」則代表全部欄位.
|
|
|
13414 |
#可省略參數:
|
| 226 |
liveuser |
13415 |
|
| 3 |
liveuser |
13416 |
#如果有給予連線密碼
|
|
|
13417 |
if(isset($conf["dbInfo"][$mainDb]["dbPass"])){
|
| 226 |
liveuser |
13418 |
|
| 3 |
liveuser |
13419 |
$conf["db::fastGetDbData"]["dbPassword"]=$conf["dbInfo"][$mainDb]["dbPass"];#爲要存取dbServer的密碼
|
| 226 |
liveuser |
13420 |
|
| 3 |
liveuser |
13421 |
}#if end
|
| 226 |
liveuser |
13422 |
|
| 3 |
liveuser |
13423 |
#如果有給予連線port
|
|
|
13424 |
if(isset($conf["dbInfo"][$mainDb]["dbPort"])){
|
| 226 |
liveuser |
13425 |
|
| 3 |
liveuser |
13426 |
$conf["db::fastGetDbData"]["dbPort"]=$conf["dbInfo"][$mainDb]["dbPort"];#爲要存取dbServer的port
|
| 226 |
liveuser |
13427 |
|
| 3 |
liveuser |
13428 |
}#if end
|
| 226 |
liveuser |
13429 |
|
| 3 |
liveuser |
13430 |
#如果有設置 $conf["mainDtWhereColName"]
|
|
|
13431 |
if(isset($conf["mainDtWhereColName"])){
|
| 226 |
liveuser |
13432 |
|
| 3 |
liveuser |
13433 |
#設置參數
|
|
|
13434 |
$conf["db::fastGetDbData"]["WhereColumnName"]=$conf["mainDtWhereColName"];
|
| 226 |
liveuser |
13435 |
|
| 3 |
liveuser |
13436 |
}#if end
|
| 226 |
liveuser |
13437 |
|
| 3 |
liveuser |
13438 |
#如果有設置 $conf["mainDtWhereColVal"]
|
|
|
13439 |
if(isset($conf["mainDtWhereColVal"])){
|
| 226 |
liveuser |
13440 |
|
| 3 |
liveuser |
13441 |
#設置參數
|
|
|
13442 |
$conf["db::fastGetDbData"]["WhereColumnValue"]=$conf["mainDtWhereColVal"];#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
| 226 |
liveuser |
13443 |
|
| 3 |
liveuser |
13444 |
}#if end
|
| 226 |
liveuser |
13445 |
|
| 3 |
liveuser |
13446 |
#如果有設置 $conf["mainDtWhereColCombine"]
|
|
|
13447 |
if(isset($conf["mainDtWhereColCombine"])){
|
| 226 |
liveuser |
13448 |
|
| 3 |
liveuser |
13449 |
#設置參數
|
|
|
13450 |
$conf["db::fastGetDbData"]["WhereColumnCombine"]=$conf["mainDtWhereColCombine"];#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
| 226 |
liveuser |
13451 |
|
| 3 |
liveuser |
13452 |
}#if end
|
| 226 |
liveuser |
13453 |
|
| 3 |
liveuser |
13454 |
#如果有設置 $conf["mainWhereColumnOperator"]
|
|
|
13455 |
if(isset($conf["mainWhereColumnOperator"])){
|
| 226 |
liveuser |
13456 |
|
| 3 |
liveuser |
13457 |
#設置參數
|
|
|
13458 |
$conf["db::fastGetDbData"]["WhereColumnOperator"]=$conf["mainWhereColumnOperator"];#用於判斷語句的比較符號陣列,可以用的符號有「"="、"!="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
| 226 |
liveuser |
13459 |
|
| 3 |
liveuser |
13460 |
}#if end
|
| 226 |
liveuser |
13461 |
|
| 3 |
liveuser |
13462 |
#如果有設置 $conf["mainWhereColumnAndOr"]
|
|
|
13463 |
if(isset($conf["mainWhereColumnAndOr"])){
|
| 226 |
liveuser |
13464 |
|
| 3 |
liveuser |
13465 |
#設置參數
|
|
|
13466 |
$conf["db::fastGetDbData"]["WhereColumnAndOr"]=$conf["mainWhereColumnAndOr"];#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
13467 |
|
|
|
13468 |
}#if end
|
| 226 |
liveuser |
13469 |
|
| 3 |
liveuser |
13470 |
#如果有設置 $conf["mainWhereIn"]
|
|
|
13471 |
if(isset($conf["mainWhereIn"])){
|
| 226 |
liveuser |
13472 |
|
| 3 |
liveuser |
13473 |
#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
|
|
|
13474 |
$conf["db::fastGetDbData"]["whereIn"]=$conf["mainWhereIn"];
|
| 226 |
liveuser |
13475 |
|
| 3 |
liveuser |
13476 |
}#if end
|
| 226 |
liveuser |
13477 |
|
| 3 |
liveuser |
13478 |
#如果有設置 $conf["mainWhereNotIn"]
|
|
|
13479 |
if(isset($conf["mainWhereNotIn"])){
|
| 226 |
liveuser |
13480 |
|
| 3 |
liveuser |
13481 |
#設置參數
|
|
|
13482 |
#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
|
|
|
13483 |
$conf["db::fastGetDbData"]["whereNotIn"]=$conf["mainWhereNotIn"];
|
| 226 |
liveuser |
13484 |
|
| 3 |
liveuser |
13485 |
}#if end
|
| 226 |
liveuser |
13486 |
|
| 3 |
liveuser |
13487 |
#如果有設置 $conf["mainNumberStart"]
|
|
|
13488 |
if(isset($conf["mainNumberStart"])){
|
| 226 |
liveuser |
13489 |
|
| 3 |
liveuser |
13490 |
#設置參數
|
|
|
13491 |
$conf["db::fastGetDbData"]["numberStart"]=$conf["mainNumberStart"];#為從第幾筆開始讀取,預設為0,代筆第一筆。
|
| 226 |
liveuser |
13492 |
|
| 3 |
liveuser |
13493 |
}#if end
|
| 226 |
liveuser |
13494 |
|
| 3 |
liveuser |
13495 |
#如果有設置 $conf["mainNumLimit"]
|
|
|
13496 |
if(isset($conf["mainNumLimit"])){
|
| 226 |
liveuser |
13497 |
|
| 3 |
liveuser |
13498 |
#設置參數
|
|
|
13499 |
$conf["db::fastGetDbData"]["numLimit"]=$conf["mainNumLimit"];#為要取幾筆資料,可以省略,省略則表示不限制數目。
|
| 226 |
liveuser |
13500 |
|
| 3 |
liveuser |
13501 |
}#if end
|
| 226 |
liveuser |
13502 |
|
| 3 |
liveuser |
13503 |
#如果有設置 $conf["mainGroupBy"]
|
|
|
13504 |
if(isset($conf["mainGroupBy"])){
|
| 226 |
liveuser |
13505 |
|
| 3 |
liveuser |
13506 |
#設置參數
|
|
|
13507 |
$conf["db::fastGetDbData"]["groupBy"]=$conf["mainGroupBy"];#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
| 226 |
liveuser |
13508 |
|
| 3 |
liveuser |
13509 |
}#if end
|
| 226 |
liveuser |
13510 |
|
| 3 |
liveuser |
13511 |
#如果有設置 $conf["mainOrderItem"]
|
|
|
13512 |
if(isset($conf["mainOrderItem"])){
|
| 226 |
liveuser |
13513 |
|
| 3 |
liveuser |
13514 |
#設置參數
|
|
|
13515 |
$conf["db::fastGetDbData"]["orderItem"]=$conf["mainOrderItem"];#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
| 226 |
liveuser |
13516 |
|
| 3 |
liveuser |
13517 |
}#if end
|
| 226 |
liveuser |
13518 |
|
| 3 |
liveuser |
13519 |
#如果有設置 $conf["mainAscORdesc"]
|
|
|
13520 |
if(isset($conf["mainAscORdesc"])){
|
| 226 |
liveuser |
13521 |
|
| 3 |
liveuser |
13522 |
#設置參數
|
|
|
13523 |
#$conf["mainAscORdesc"],字串,組好的資料要低增還是遞減排序,asc爲遞增;desc爲遞減,預設不做處理.
|
|
|
13524 |
$conf["db::fastGetDbData"]["mainAscORdesc"]=$conf["mainAscORdesc"];
|
| 226 |
liveuser |
13525 |
|
| 3 |
liveuser |
13526 |
}#if end
|
| 226 |
liveuser |
13527 |
|
| 3 |
liveuser |
13528 |
$fastGetDbData=db::fastGetDbData($conf["db::fastGetDbData"]);
|
|
|
13529 |
unset($conf["db::fastGetDbData"]);
|
| 226 |
liveuser |
13530 |
|
| 3 |
liveuser |
13531 |
#如果執行失敗
|
|
|
13532 |
if($fastGetDbData["status"]==="false"){
|
| 226 |
liveuser |
13533 |
|
| 3 |
liveuser |
13534 |
#設置錯誤識別
|
|
|
13535 |
$result["status"]="false";
|
| 226 |
liveuser |
13536 |
|
| 3 |
liveuser |
13537 |
#設置錯誤訊息
|
|
|
13538 |
$result["error"]=$fastGetDbData;
|
| 226 |
liveuser |
13539 |
|
| 3 |
liveuser |
13540 |
#回傳結果
|
|
|
13541 |
return $result;
|
| 226 |
liveuser |
13542 |
|
| 3 |
liveuser |
13543 |
}#if end
|
| 226 |
liveuser |
13544 |
|
| 3 |
liveuser |
13545 |
#var_dump($fastGetDbData);
|
| 226 |
liveuser |
13546 |
|
| 3 |
liveuser |
13547 |
#初始化儲存合併好的資料
|
|
|
13548 |
$merged=array();
|
| 226 |
liveuser |
13549 |
|
| 3 |
liveuser |
13550 |
#如果該存在的變數不存在
|
|
|
13551 |
if(!isset($fastGetDbData["dataColumnName"])){
|
| 226 |
liveuser |
13552 |
|
| 3 |
liveuser |
13553 |
#設置錯誤識別
|
|
|
13554 |
$result["status"]="false";
|
| 226 |
liveuser |
13555 |
|
| 3 |
liveuser |
13556 |
#設置錯誤訊息
|
|
|
13557 |
$result["error"]=$fastGetDbData;
|
| 226 |
liveuser |
13558 |
|
| 3 |
liveuser |
13559 |
#回傳結果
|
|
|
13560 |
return $result;
|
| 226 |
liveuser |
13561 |
|
| 3 |
liveuser |
13562 |
}#if end
|
| 226 |
liveuser |
13563 |
|
| 3 |
liveuser |
13564 |
#針對每個欄位
|
|
|
13565 |
foreach($fastGetDbData["dataColumnName"] as $colName){
|
| 226 |
liveuser |
13566 |
|
| 3 |
liveuser |
13567 |
#將當前資料的欄位用 dbName.dtName.dataColName 儲存
|
|
|
13568 |
$merged[$mainDb.".".$mainDt.".".$colName]=$fastGetDbData["dataContent"][$colName];
|
| 226 |
liveuser |
13569 |
|
| 3 |
liveuser |
13570 |
}#foreach end
|
| 226 |
liveuser |
13571 |
|
| 3 |
liveuser |
13572 |
#移除變數節省記憶體
|
|
|
13573 |
unset($fastGetDbData);
|
| 226 |
liveuser |
13574 |
|
| 3 |
liveuser |
13575 |
#取得陣列元素數目
|
|
|
13576 |
$mergedCount=count($merged);
|
| 226 |
liveuser |
13577 |
|
| 3 |
liveuser |
13578 |
#移除以數字為欄位索引的變數
|
|
|
13579 |
for($i=0;$i<$mergedCount/2;$i++){
|
| 226 |
liveuser |
13580 |
|
| 3 |
liveuser |
13581 |
#移除索引
|
|
|
13582 |
unset($merged[$i]);
|
| 226 |
liveuser |
13583 |
|
| 3 |
liveuser |
13584 |
}#for end
|
| 226 |
liveuser |
13585 |
|
| 3 |
liveuser |
13586 |
#var_dump($merged);exit;
|
| 226 |
liveuser |
13587 |
|
|
|
13588 |
#針對每個 $conf["linkColumnName"]
|
| 3 |
liveuser |
13589 |
foreach($conf["linkColumnName"] as $linkCondition){
|
| 226 |
liveuser |
13590 |
|
| 3 |
liveuser |
13591 |
#如果不是陣列
|
|
|
13592 |
if(gettype($linkCondition)!=="array"){
|
| 226 |
liveuser |
13593 |
|
| 3 |
liveuser |
13594 |
#設置錯誤識別
|
|
|
13595 |
$result["status"]="false";
|
| 226 |
liveuser |
13596 |
|
| 3 |
liveuser |
13597 |
#設置錯誤訊息
|
|
|
13598 |
$result["error"][]="參數 linkColumnName 的陣列元素應該為陣列.";
|
| 226 |
liveuser |
13599 |
|
| 3 |
liveuser |
13600 |
#回傳結果
|
|
|
13601 |
return $result;
|
| 226 |
liveuser |
13602 |
|
| 3 |
liveuser |
13603 |
}#if end
|
| 226 |
liveuser |
13604 |
|
| 3 |
liveuser |
13605 |
#如果數量不為2
|
|
|
13606 |
if(count($linkCondition)!==2){
|
| 226 |
liveuser |
13607 |
|
| 3 |
liveuser |
13608 |
#設置錯誤識別
|
|
|
13609 |
$result["status"]="false";
|
| 226 |
liveuser |
13610 |
|
| 3 |
liveuser |
13611 |
#設置錯誤訊息
|
|
|
13612 |
$result["error"][]="參數 linkColumnName 的陣列元素應為有兩個元素的陣列.";
|
| 226 |
liveuser |
13613 |
|
| 3 |
liveuser |
13614 |
#回傳結果
|
|
|
13615 |
return $result;
|
| 226 |
liveuser |
13616 |
|
| 3 |
liveuser |
13617 |
}#if end
|
| 226 |
liveuser |
13618 |
|
| 3 |
liveuser |
13619 |
#取得原始欄位的名稱
|
| 226 |
liveuser |
13620 |
$oriCol=&$linkCondition[0];
|
|
|
13621 |
|
| 3 |
liveuser |
13622 |
#如果用來比對的原欄位不存在
|
|
|
13623 |
if(!isset($merged[$oriCol])){
|
| 226 |
liveuser |
13624 |
|
| 3 |
liveuser |
13625 |
#設置錯誤識別
|
|
|
13626 |
$result["status"]="false";
|
| 226 |
liveuser |
13627 |
|
| 3 |
liveuser |
13628 |
#設置錯誤訊息
|
|
|
13629 |
$result["error"][]="用來比對的原始資料沒有欄位 「".$oriCol."」 存在.";
|
| 226 |
liveuser |
13630 |
|
| 3 |
liveuser |
13631 |
#回傳結果
|
|
|
13632 |
return $result;
|
| 226 |
liveuser |
13633 |
|
| 3 |
liveuser |
13634 |
}#if end
|
| 226 |
liveuser |
13635 |
|
| 3 |
liveuser |
13636 |
#取得要增加的欄位名稱
|
| 226 |
liveuser |
13637 |
$newCol=&$linkCondition[1];
|
|
|
13638 |
|
| 3 |
liveuser |
13639 |
#檢查增加的欄位名稱是否有 "."
|
|
|
13640 |
$foundDot=strpos($newCol,'.');
|
| 226 |
liveuser |
13641 |
|
| 3 |
liveuser |
13642 |
#如果不是
|
|
|
13643 |
if(!$foundDot){
|
| 226 |
liveuser |
13644 |
|
| 3 |
liveuser |
13645 |
#設置錯誤識別
|
|
|
13646 |
$result["status"]="false";
|
| 226 |
liveuser |
13647 |
|
| 3 |
liveuser |
13648 |
#設置錯誤訊息
|
|
|
13649 |
$result["error"][]="參數 linkColumnName 的欄位格式 ".$newCol." 必須為 資料庫名稱.資料表名稱.資料欄位名稱";
|
| 226 |
liveuser |
13650 |
|
| 3 |
liveuser |
13651 |
#回傳結果
|
|
|
13652 |
return $result;
|
| 226 |
liveuser |
13653 |
|
| 3 |
liveuser |
13654 |
}#if end
|
| 226 |
liveuser |
13655 |
|
| 3 |
liveuser |
13656 |
#反之
|
|
|
13657 |
else{
|
| 226 |
liveuser |
13658 |
|
| 3 |
liveuser |
13659 |
#用 . 去切割字串
|
|
|
13660 |
$dbdtsplitedstr=explode('.',$newCol);
|
| 226 |
liveuser |
13661 |
|
| 3 |
liveuser |
13662 |
#如果切割出來不等於兩段
|
|
|
13663 |
if(count($dbdtsplitedstr)!==3){
|
| 226 |
liveuser |
13664 |
|
| 3 |
liveuser |
13665 |
#設置錯誤識別
|
|
|
13666 |
$result["status"]="false";
|
| 226 |
liveuser |
13667 |
|
| 3 |
liveuser |
13668 |
#設置錯誤訊息
|
|
|
13669 |
$result["error"][]="參數 linkColumnName 的欄位格式 ".$newCol." 必須為 資料庫名稱.資料表名稱.資料欄位名稱";
|
| 226 |
liveuser |
13670 |
|
| 3 |
liveuser |
13671 |
#回傳結果
|
|
|
13672 |
return $result;
|
| 226 |
liveuser |
13673 |
|
| 3 |
liveuser |
13674 |
}#if end
|
| 226 |
liveuser |
13675 |
|
| 3 |
liveuser |
13676 |
#取得 linkTable 的 db name
|
|
|
13677 |
$linkDb=&$dbdtsplitedstr[0];
|
| 226 |
liveuser |
13678 |
|
| 3 |
liveuser |
13679 |
#取得 linkTable 的名稱
|
|
|
13680 |
$linkDt=&$dbdtsplitedstr[1];
|
| 226 |
liveuser |
13681 |
|
| 3 |
liveuser |
13682 |
#取得 linkCol 的名稱
|
|
|
13683 |
$linkCol=&$dbdtsplitedstr[2];
|
| 226 |
liveuser |
13684 |
|
| 3 |
liveuser |
13685 |
}#else end
|
| 226 |
liveuser |
13686 |
|
| 3 |
liveuser |
13687 |
#檢查次表的參數
|
|
|
13688 |
#函式說明:
|
|
|
13689 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
13690 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
13691 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
13692 |
#$result["function"],當前執行的函式名稱.
|
|
|
13693 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
13694 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
13695 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
13696 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
13697 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
13698 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
13699 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
13700 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
13701 |
#必填參數:
|
|
|
13702 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
| 226 |
liveuser |
13703 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf["dbInfo"][$linkDb];
|
| 3 |
liveuser |
13704 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
13705 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
13706 |
#可以省略的參數:
|
|
|
13707 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
13708 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddr","dbAcct");
|
|
|
13709 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
13710 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string");
|
|
|
13711 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
13712 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
13713 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
13714 |
#$conf["canNotBeEmpty"]=array();
|
|
|
13715 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
13716 |
#$conf["canBeEmpty"]=array();
|
|
|
13717 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
13718 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("dbPass");
|
|
|
13719 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
13720 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPass");
|
| 226 |
liveuser |
13721 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
13722 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
|
|
13723 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
13724 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null);
|
|
|
13725 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
13726 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
13727 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
13728 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
13729 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
13730 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
13731 |
#參考資料:
|
|
|
13732 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
13733 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
13734 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
13735 |
|
| 3 |
liveuser |
13736 |
#var_dump($checkArguments);
|
|
|
13737 |
#exit;
|
| 226 |
liveuser |
13738 |
|
| 3 |
liveuser |
13739 |
#如果執行失敗
|
|
|
13740 |
if($checkArguments["status"]==="false"){
|
| 226 |
liveuser |
13741 |
|
| 3 |
liveuser |
13742 |
#設置錯誤識別
|
|
|
13743 |
$result["status"]="false";
|
| 226 |
liveuser |
13744 |
|
| 3 |
liveuser |
13745 |
#設置錯誤訊息
|
|
|
13746 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
13747 |
|
| 3 |
liveuser |
13748 |
#回傳結果
|
|
|
13749 |
return $result;
|
| 226 |
liveuser |
13750 |
|
| 3 |
liveuser |
13751 |
}#if end
|
| 226 |
liveuser |
13752 |
|
| 3 |
liveuser |
13753 |
#如果檢查不通過
|
|
|
13754 |
if($checkArguments["passed"]==="false"){
|
| 226 |
liveuser |
13755 |
|
| 3 |
liveuser |
13756 |
#設置錯誤識別
|
|
|
13757 |
$result["status"]="false";
|
| 226 |
liveuser |
13758 |
|
| 3 |
liveuser |
13759 |
#設置錯誤訊息
|
|
|
13760 |
$result["error"]=$checkArguments;
|
| 226 |
liveuser |
13761 |
|
| 3 |
liveuser |
13762 |
#回傳結果
|
|
|
13763 |
return $result;
|
| 226 |
liveuser |
13764 |
|
| 3 |
liveuser |
13765 |
}#if end
|
| 226 |
liveuser |
13766 |
|
| 3 |
liveuser |
13767 |
#初始化新合併過後的資料
|
|
|
13768 |
$newMerged=&$merged;
|
| 226 |
liveuser |
13769 |
|
| 3 |
liveuser |
13770 |
#初始化儲存既有的欄位名稱
|
|
|
13771 |
$mergedColName=array_keys($merged);
|
| 226 |
liveuser |
13772 |
|
| 3 |
liveuser |
13773 |
#取得既有的欄位的數量
|
| 207 |
liveuser |
13774 |
$mergedColCount=count($mergedColName);
|
| 226 |
liveuser |
13775 |
|
| 3 |
liveuser |
13776 |
#主表有幾筆資料就執行幾次
|
|
|
13777 |
foreach($merged[$oriCol] as $index=>$mainColVal){
|
| 226 |
liveuser |
13778 |
|
| 3 |
liveuser |
13779 |
#函式說明:
|
|
|
13780 |
#一次取得資料庫、表的資料
|
|
|
13781 |
#回傳結果:
|
|
|
13782 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
13783 |
#$result["error"],錯誤訊息陣列。
|
|
|
13784 |
#$result["function"],當前執行的漢書名稱.
|
|
|
13785 |
#$result["dataColumnName"],抓取的資料欄位名稱陣列.
|
|
|
13786 |
#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
|
|
|
13787 |
#$result["dataContent"],爲資料的內容。
|
|
|
13788 |
#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
13789 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
13790 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
13791 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
13792 |
#$result["sql"],執行的sql字串.
|
|
|
13793 |
#必填參數:
|
|
|
13794 |
$conf["db::fastGetDbData"]["dbAddress"]=$conf["dbInfo"][$linkDb]["dbAddr"];#爲dbServer的位置。
|
|
|
13795 |
$conf["db::fastGetDbData"]["dbAccount"]=$conf["dbInfo"][$linkDb]["dbAcct"];#爲登入dbServer的帳號。
|
|
|
13796 |
$conf["db::fastGetDbData"]["dbName"]=$linkDb;#爲要存取的資料庫名稱
|
|
|
13797 |
$conf["db::fastGetDbData"]["tableName"]=$linkDt;#爲要存取的資料表名稱
|
|
|
13798 |
$conf["db::fastGetDbData"]["columnYouWant"]=array("*");#你想要的欄位!,若設為「array("*")」則代表全部欄位.
|
|
|
13799 |
#可省略參數:
|
| 226 |
liveuser |
13800 |
|
| 3 |
liveuser |
13801 |
#如果有設置次表的密碼
|
|
|
13802 |
if(isset($conf["dbInfo"][$linkDb]["dbPass"])){
|
| 226 |
liveuser |
13803 |
|
| 3 |
liveuser |
13804 |
$conf["db::fastGetDbData"]["dbPassword"]=$conf["dbInfo"][$linkDb]["dbPass"];#爲要存取dbServer的密碼
|
| 226 |
liveuser |
13805 |
|
| 207 |
liveuser |
13806 |
}#if end
|
| 226 |
liveuser |
13807 |
|
| 3 |
liveuser |
13808 |
$conf["db::fastGetDbData"]["WhereColumnName"]=array($linkCol);#用於判斷語句的欄位項目陣列。
|
|
|
13809 |
$conf["db::fastGetDbData"]["WhereColumnValue"]=array($mainColVal);#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
|
|
13810 |
#$conf["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
13811 |
#$conf["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、"!="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
13812 |
#$conf["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
13813 |
#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
|
|
|
13814 |
#$conf["whereIn"]=array(array("colName",array("a","b","c")));
|
|
|
13815 |
#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
|
|
|
13816 |
#$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
|
|
|
13817 |
#$conf["orderItem"]="";#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
|
|
13818 |
#$conf["ascORdesc"]="";#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
|
|
13819 |
#$conf["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
|
|
|
13820 |
#$conf["db::fastGetDbData"]["numLimit"]="1";#為要取幾筆資料,可以省略,省略則表示不限制數目。
|
|
|
13821 |
#$conf["groupBy"]=array("");#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
|
|
13822 |
$fastGetDbData=db::fastGetDbData($conf["db::fastGetDbData"]);
|
|
|
13823 |
unset($conf["db::fastGetDbData"]);
|
| 226 |
liveuser |
13824 |
|
| 3 |
liveuser |
13825 |
#如果query失敗
|
|
|
13826 |
if($fastGetDbData["status"]==="false"){
|
| 226 |
liveuser |
13827 |
|
| 3 |
liveuser |
13828 |
#設置執行失敗
|
|
|
13829 |
$result["status"]="false";
|
| 226 |
liveuser |
13830 |
|
| 3 |
liveuser |
13831 |
#設置錯誤訊息
|
|
|
13832 |
$result["error"]=$fastGetDbData;
|
| 226 |
liveuser |
13833 |
|
| 3 |
liveuser |
13834 |
#回傳結果;
|
|
|
13835 |
return $result;
|
| 226 |
liveuser |
13836 |
|
| 3 |
liveuser |
13837 |
}#if end
|
| 226 |
liveuser |
13838 |
|
| 3 |
liveuser |
13839 |
#如果如果沒有符合的資料
|
|
|
13840 |
if($fastGetDbData["dataCount"]===0){
|
| 226 |
liveuser |
13841 |
|
| 3 |
liveuser |
13842 |
#如果有欄位名稱存在
|
|
|
13843 |
if(isset($fastGetDbData["dataColumnName"])){
|
| 226 |
liveuser |
13844 |
|
| 3 |
liveuser |
13845 |
#次表有幾個欄位就執行幾次
|
|
|
13846 |
foreach($fastGetDbData["dataColumnName"] as $linkedColName){
|
| 226 |
liveuser |
13847 |
|
| 3 |
liveuser |
13848 |
#給予NULL
|
|
|
13849 |
$newMerged[$linkDb.".".$linkDt.".".$linkedColName][$index]=NULL;
|
| 226 |
liveuser |
13850 |
|
| 207 |
liveuser |
13851 |
}#foreach end
|
| 226 |
liveuser |
13852 |
|
| 3 |
liveuser |
13853 |
}#if end
|
| 226 |
liveuser |
13854 |
|
| 3 |
liveuser |
13855 |
}#if end
|
| 226 |
liveuser |
13856 |
|
| 3 |
liveuser |
13857 |
#反之有資料
|
|
|
13858 |
else{
|
| 226 |
liveuser |
13859 |
|
| 3 |
liveuser |
13860 |
#次表有幾個欄位就執行幾次
|
|
|
13861 |
foreach($fastGetDbData["dataColumnName"] as $linkedColName){
|
| 226 |
liveuser |
13862 |
|
| 3 |
liveuser |
13863 |
#設置新的欄位資料
|
|
|
13864 |
$newMerged[$linkDb.".".$linkDt.".".$linkedColName][$index]=$fastGetDbData["dataContent"][$linkedColName][0];
|
| 226 |
liveuser |
13865 |
|
| 3 |
liveuser |
13866 |
}#foreach end
|
| 226 |
liveuser |
13867 |
|
| 3 |
liveuser |
13868 |
#有幾筆資料就執行幾次
|
|
|
13869 |
for($i=1;$i<$fastGetDbData["dataCount"];$i++){
|
| 226 |
liveuser |
13870 |
|
| 3 |
liveuser |
13871 |
#取得資新料的索引
|
|
|
13872 |
$newMergedDataIndex=count($newMerged[$mergedColName[0]]);
|
| 226 |
liveuser |
13873 |
|
| 3 |
liveuser |
13874 |
#有幾個欄位就執行幾次
|
|
|
13875 |
for($j=0;$j<$mergedColCount;$j++){
|
| 226 |
liveuser |
13876 |
|
| 3 |
liveuser |
13877 |
#複製既有的欄位資料
|
|
|
13878 |
$newMerged[$mergedColName[$j]][$newMergedDataIndex]=$newMerged[$mergedColName[$j]][$index];
|
| 226 |
liveuser |
13879 |
|
| 207 |
liveuser |
13880 |
}#for end
|
| 226 |
liveuser |
13881 |
|
| 3 |
liveuser |
13882 |
#次表有幾個欄位就執行幾次
|
| 226 |
liveuser |
13883 |
foreach($fastGetDbData["dataColumnName"] as $linkedColName){
|
|
|
13884 |
|
| 3 |
liveuser |
13885 |
#加上新的欄位資料
|
|
|
13886 |
$newMerged[$linkDb.".".$linkDt.".".$linkedColName][$newMergedDataIndex]=$fastGetDbData["dataContent"][$linkedColName][$i];
|
| 226 |
liveuser |
13887 |
|
| 3 |
liveuser |
13888 |
}#foreach end
|
| 226 |
liveuser |
13889 |
|
| 207 |
liveuser |
13890 |
}#for end
|
| 226 |
liveuser |
13891 |
|
| 3 |
liveuser |
13892 |
}#else end
|
| 226 |
liveuser |
13893 |
|
| 3 |
liveuser |
13894 |
}#foreach end
|
| 226 |
liveuser |
13895 |
|
| 3 |
liveuser |
13896 |
}#foreach end
|
| 226 |
liveuser |
13897 |
|
| 3 |
liveuser |
13898 |
#如果有設置要的欄位
|
|
|
13899 |
if(isset($conf["columnYouWant"])){
|
| 226 |
liveuser |
13900 |
|
| 3 |
liveuser |
13901 |
#初始化儲存僅需要的欄位
|
|
|
13902 |
$filteredCol=array();
|
| 226 |
liveuser |
13903 |
|
| 3 |
liveuser |
13904 |
#依照每個需要的欄位
|
|
|
13905 |
foreach($conf["columnYouWant"] as $colYouWant){
|
| 226 |
liveuser |
13906 |
|
| 3 |
liveuser |
13907 |
#如果要的欄位不存在
|
|
|
13908 |
if(!isset($newMerged[$colYouWant])){
|
| 226 |
liveuser |
13909 |
|
|
|
13910 |
#設置執行不正常;
|
| 3 |
liveuser |
13911 |
$result["status"]="false";
|
| 226 |
liveuser |
13912 |
|
| 3 |
liveuser |
13913 |
#設置錯誤訊息
|
|
|
13914 |
$result["error"][]="欄位 ".$colYouWant." 不存在於查詢後的結果!";
|
| 226 |
liveuser |
13915 |
|
| 3 |
liveuser |
13916 |
#回傳結果
|
|
|
13917 |
return $result;
|
| 226 |
liveuser |
13918 |
|
| 3 |
liveuser |
13919 |
}#if end
|
| 226 |
liveuser |
13920 |
|
| 3 |
liveuser |
13921 |
#取得欄位內容
|
|
|
13922 |
$filteredCol[$colYouWant]=&$newMerged[$colYouWant];
|
| 226 |
liveuser |
13923 |
|
| 3 |
liveuser |
13924 |
}#foreach end
|
| 226 |
liveuser |
13925 |
|
| 3 |
liveuser |
13926 |
#置換成篩選過後的欄位資訊
|
|
|
13927 |
$newMerged=$filteredCol;
|
| 226 |
liveuser |
13928 |
|
| 3 |
liveuser |
13929 |
}#if end
|
| 226 |
liveuser |
13930 |
|
| 3 |
liveuser |
13931 |
#設置執行正常
|
|
|
13932 |
$result["status"]="true";
|
| 226 |
liveuser |
13933 |
|
| 3 |
liveuser |
13934 |
#設置join完的資料;
|
|
|
13935 |
$result["content"]=$merged;
|
| 226 |
liveuser |
13936 |
|
| 3 |
liveuser |
13937 |
#回傳結果
|
|
|
13938 |
return $result;
|
| 226 |
liveuser |
13939 |
|
| 3 |
liveuser |
13940 |
}#function joinByPHP end
|
| 226 |
liveuser |
13941 |
|
| 3 |
liveuser |
13942 |
/*
|
|
|
13943 |
#函式說明:
|
|
|
13944 |
#取得該資料表總共有幾筆資料
|
|
|
13945 |
#回傳變數:
|
|
|
13946 |
#$result["status"],爲執行是否正常,若爲"true"則成功,若爲"false"則表示失敗了
|
|
|
13947 |
#$result["function"],當前執行的函數名稱
|
|
|
13948 |
#$result["error"],錯誤訊息
|
|
|
13949 |
#$result["dataCount"],資料表裏面的資料筆數。
|
|
|
13950 |
#必填參數:
|
|
|
13951 |
#$conf["dbAddress"],字串,爲mysql-Server的位置.
|
|
|
13952 |
$conf["dbAddress"]=$dbAddress;
|
|
|
13953 |
#$conf["dbAccount"]字串,爲用於連入mysql-Server時要使用的帳號.
|
|
|
13954 |
$conf["dbAccount"]=$dbAccount;
|
| 226 |
liveuser |
13955 |
#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱
|
| 3 |
liveuser |
13956 |
$conf["selectedDataBaseName"]=$dbName;
|
|
|
13957 |
#$conf["selectedDataTableName"],字串,為要計算的對象資料表
|
|
|
13958 |
$conf["selectedDataTableName"]="";#為要計算的對象資料表
|
|
|
13959 |
#可省略參數:
|
|
|
13960 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
13961 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
13962 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表用預設的 port 3306.
|
|
|
13963 |
#$conf["dbPort"]=$dbPort;
|
|
|
13964 |
#參考資料:
|
|
|
13965 |
#無.
|
|
|
13966 |
#備註:
|
|
|
13967 |
#無.
|
| 226 |
liveuser |
13968 |
*/
|
| 3 |
liveuser |
13969 |
public static function getDataCountsInTable($conf){
|
|
|
13970 |
|
|
|
13971 |
#初始化要回傳的內容
|
|
|
13972 |
$result=array();
|
|
|
13973 |
|
|
|
13974 |
#取得當前執行的函數名稱
|
|
|
13975 |
$result["function"]=__FUNCTION__;
|
|
|
13976 |
|
|
|
13977 |
#如果 $conf 不為陣列
|
|
|
13978 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
13979 |
|
| 3 |
liveuser |
13980 |
#設置執行失敗
|
|
|
13981 |
$result["status"]="false";
|
| 226 |
liveuser |
13982 |
|
| 3 |
liveuser |
13983 |
#設置執行錯誤訊息
|
|
|
13984 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
13985 |
|
|
|
13986 |
#如果傳入的參數為 null
|
|
|
13987 |
if($conf==null){
|
| 226 |
liveuser |
13988 |
|
| 3 |
liveuser |
13989 |
#設置執行錯誤訊息
|
|
|
13990 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
13991 |
|
| 3 |
liveuser |
13992 |
}#if end
|
|
|
13993 |
|
|
|
13994 |
#回傳結果
|
|
|
13995 |
return $result;
|
| 226 |
liveuser |
13996 |
|
| 3 |
liveuser |
13997 |
}#if end
|
|
|
13998 |
|
|
|
13999 |
#檢查參數
|
|
|
14000 |
#函式說明:
|
|
|
14001 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
14002 |
#回傳結果:
|
|
|
14003 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14004 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
14005 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
14006 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
14007 |
#必填參數:
|
|
|
14008 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
14009 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbPassword","selectedDataBaseName","selectedDataTableName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
14010 |
#可省略參數:
|
| 226 |
liveuser |
14011 |
#$conf["variableCheck"]["isexistMuti"]["variableType"]=array();#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
14012 |
#$conf["variableCheck"]["isexistMuti"]"canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
14013 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
14014 |
unset($conf["variableCheck"]["isexistMuti"]);
|
|
|
14015 |
|
|
|
14016 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
14017 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
14018 |
|
| 3 |
liveuser |
14019 |
#設置錯識別
|
|
|
14020 |
$result["status"]="false";
|
| 226 |
liveuser |
14021 |
|
| 3 |
liveuser |
14022 |
#設置錯誤訊息
|
|
|
14023 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
14024 |
|
| 3 |
liveuser |
14025 |
#回傳結果
|
|
|
14026 |
return $result;
|
| 226 |
liveuser |
14027 |
|
| 3 |
liveuser |
14028 |
}#if end
|
| 226 |
liveuser |
14029 |
|
| 3 |
liveuser |
14030 |
#如果 $checkResult["passed"] 等於 "false"
|
|
|
14031 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
14032 |
|
| 3 |
liveuser |
14033 |
#設置錯識別
|
|
|
14034 |
$result["passed"]="false";
|
| 226 |
liveuser |
14035 |
|
| 3 |
liveuser |
14036 |
#設置錯誤訊息
|
|
|
14037 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
14038 |
|
| 3 |
liveuser |
14039 |
#回傳結果
|
|
|
14040 |
return $result;
|
| 226 |
liveuser |
14041 |
|
| 3 |
liveuser |
14042 |
}#if end
|
|
|
14043 |
|
|
|
14044 |
#函式說明:
|
|
|
14045 |
#執行mysql指令
|
|
|
14046 |
#回傳結果::
|
|
|
14047 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
14048 |
#$result["error"],錯誤訊息的陣列
|
|
|
14049 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
14050 |
#$result["queryString"],mysql查詢的語言
|
|
|
14051 |
#查詢號的解果,需要解析。
|
|
|
14052 |
#必填參數:
|
|
|
14053 |
$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
14054 |
$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
14055 |
$conf["db"]["execMysqlQuery"]["dbSql"]="select count(*) from ".$conf["selectedDataBaseName"].".".$conf["selectedDataTableName"]." ;";#要執行sql語法
|
|
|
14056 |
#可省略參數:
|
| 226 |
liveuser |
14057 |
|
| 3 |
liveuser |
14058 |
#如果 $conf["dbPassword"] 有設定
|
|
|
14059 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
14060 |
|
| 3 |
liveuser |
14061 |
$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
14062 |
|
| 3 |
liveuser |
14063 |
}#if end
|
| 226 |
liveuser |
14064 |
|
| 3 |
liveuser |
14065 |
#如果 $conf["dbPort"] 有設定
|
|
|
14066 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
14067 |
|
| 3 |
liveuser |
14068 |
$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的 port.
|
| 226 |
liveuser |
14069 |
|
| 3 |
liveuser |
14070 |
}#if end
|
| 226 |
liveuser |
14071 |
|
|
|
14072 |
#執行查尋
|
| 3 |
liveuser |
14073 |
$countResult=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
|
|
|
14074 |
unset($conf["db"]["execMysqlQuery"]);
|
|
|
14075 |
|
|
|
14076 |
#如果執行失敗
|
|
|
14077 |
if($countResult["status"]=="false"){
|
| 226 |
liveuser |
14078 |
|
| 3 |
liveuser |
14079 |
#設置錯誤識別
|
|
|
14080 |
$result["status"]="false";
|
| 226 |
liveuser |
14081 |
|
| 3 |
liveuser |
14082 |
#設置錯誤訊息
|
|
|
14083 |
$result["error"]=$countResult;
|
| 226 |
liveuser |
14084 |
|
| 3 |
liveuser |
14085 |
#回傳結果
|
|
|
14086 |
return $result;
|
| 226 |
liveuser |
14087 |
|
| 3 |
liveuser |
14088 |
}#if end
|
| 226 |
liveuser |
14089 |
|
| 3 |
liveuser |
14090 |
#解析 dataTableSelect($conf) 後的結果,亦即將執行sql語法後所得到的結果解析放進變數裏面
|
|
|
14091 |
#回傳結果:
|
|
|
14092 |
#$result["status"],執行結果"true"為成功;"false"為失敗
|
|
|
14093 |
#$result["error"],錯誤訊息
|
|
|
14094 |
#$result["dataColumnName"],為資料欄位的名稱陣列.
|
|
|
14095 |
#$result["dataColumnName"][$i]代表第一個欄位名稱.
|
|
|
14096 |
#$result["dataContent"],爲資料的內容。
|
|
|
14097 |
#$result["dataContent"][$conf["tableValueName"][$i]][$dataSetNum],
|
|
|
14098 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
14099 |
#$conf["tableValueName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
14100 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
14101 |
#必填參數:
|
|
|
14102 |
$conf["db"]["sendQueryDataToVariabele"]["sqlQueryResult"]=$countResult["queryResource"];#爲執行sql語法所獲得的查詢結果。
|
|
|
14103 |
$conf["db"]["sendQueryDataToVariabele"]["tableValueName"]=array("count(*)");#爲該資料表列項目的每一項名稱,須爲陣列值,若為「array("*")」則代表所有欄位.
|
|
|
14104 |
$conf["db"]["sendQueryDataToVariabele"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
14105 |
$conf["db"]["sendQueryDataToVariabele"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
14106 |
#可省略參數:
|
| 226 |
liveuser |
14107 |
|
| 3 |
liveuser |
14108 |
#如果 $conf["dbPassword"] 有設置
|
|
|
14109 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
14110 |
|
| 3 |
liveuser |
14111 |
$conf["db"]["sendQueryDataToVariabele"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
14112 |
|
| 3 |
liveuser |
14113 |
}#if end
|
| 226 |
liveuser |
14114 |
|
| 3 |
liveuser |
14115 |
#如果 $conf["dbPort"] 有設置
|
|
|
14116 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
14117 |
|
| 3 |
liveuser |
14118 |
$conf["db"]["sendQueryDataToVariabele"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的port 3306
|
| 226 |
liveuser |
14119 |
|
| 3 |
liveuser |
14120 |
}#if end
|
| 226 |
liveuser |
14121 |
|
| 3 |
liveuser |
14122 |
$conf["db"]["sendQueryDataToVariabele"]["valueName"]=array("count");#陣列,爲該資料表列項目的每一項所要對應的變數名稱,預設為欄位的名稱($conf["tableValueName"]).
|
|
|
14123 |
#參考資料:
|
|
|
14124 |
#http://www.w3school.com.cn/php/func_mysql_fetch_array.asp => 解析取得的資料表欄位時,能夠選擇回傳含有欄位名稱與數字代表的key.
|
|
|
14125 |
$getCountResult=db::sendQueryDataToVariabele($conf["db"]["sendQueryDataToVariabele"]);
|
|
|
14126 |
unset($conf["db"]["sendQueryDataToVariabele"]);
|
|
|
14127 |
|
|
|
14128 |
#如果 $getCountResult["status"] 等於 "false"
|
|
|
14129 |
if($getCountResult["status"]=="false"){
|
| 226 |
liveuser |
14130 |
|
| 3 |
liveuser |
14131 |
#設置錯誤識別
|
|
|
14132 |
$result["status"]="false";
|
| 226 |
liveuser |
14133 |
|
| 3 |
liveuser |
14134 |
#設置錯誤訊息
|
|
|
14135 |
$result["error"]=$getCountResult;
|
| 226 |
liveuser |
14136 |
|
| 3 |
liveuser |
14137 |
#回傳結果
|
|
|
14138 |
return $result;
|
| 226 |
liveuser |
14139 |
|
| 3 |
liveuser |
14140 |
}#if end
|
|
|
14141 |
|
|
|
14142 |
#取得資料筆數
|
|
|
14143 |
$result["dataCount"]=$getCountResult["dataContent"]["count"][0];
|
| 226 |
liveuser |
14144 |
|
| 3 |
liveuser |
14145 |
#執行到這邊代表執行正常
|
|
|
14146 |
$result["status"]="true";
|
|
|
14147 |
|
| 226 |
liveuser |
14148 |
#回傳查詢的結果;
|
|
|
14149 |
return $result;
|
|
|
14150 |
|
| 3 |
liveuser |
14151 |
}#function getDataCountsInTable end
|
|
|
14152 |
|
|
|
14153 |
/*
|
|
|
14154 |
#函式說明:
|
|
|
14155 |
#插入資料到指定的資料表裡面,插入資料完畢可以選擇是否要進行轉址。
|
| 226 |
liveuser |
14156 |
#回傳結果:
|
| 3 |
liveuser |
14157 |
#$result["status"],爲查詢是否成功,若爲"true"則成功,若爲"false"則表示失敗了.
|
|
|
14158 |
#$result["error"],錯誤訊息.
|
|
|
14159 |
#$result["sql"],執行的sql語法.
|
|
|
14160 |
#$result["lastInsertId"],新增的資料id.
|
|
|
14161 |
#$result["function"],當前執行的涵式
|
|
|
14162 |
#必填參數:
|
|
|
14163 |
#$conf["dbAddress"],字串,爲mysql-Server的位置
|
|
|
14164 |
$conf["dbAddress"]=$dbAddress;
|
|
|
14165 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
|
|
|
14166 |
$conf["dbAccount"]=$dbAccount;
|
|
|
14167 |
#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱
|
|
|
14168 |
$conf["selectedDataBaseName"]=$dbName;
|
|
|
14169 |
#$conf["tableName"],字串,爲要插入資料的資料表名稱
|
|
|
14170 |
$conf["tableName"]="";
|
|
|
14171 |
#$conf["columnName"],字串陣列,爲資料表的項目名稱.例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
|
|
|
14172 |
$conf["columnName"]=array();
|
|
|
14173 |
#$conf["insertValue"],字串陣列,爲要插入度數值.#例如:$conf["insertValue"]=array("insertValue1","insertValue2","insertValue3",...);
|
|
|
14174 |
$conf["insertValue"]=array();
|
|
|
14175 |
#可省略參數:
|
|
|
14176 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
14177 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
14178 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表用預設的 3306 port.
|
|
|
14179 |
#$conf["dbPort"]=$dbPort;
|
|
|
14180 |
#參考資料:
|
|
|
14181 |
#http://www.javaworld.com.tw/jute/post/view?bid=21&id=173738&sty=1
|
|
|
14182 |
#備註:
|
|
|
14183 |
#無.
|
| 226 |
liveuser |
14184 |
*/
|
| 3 |
liveuser |
14185 |
public static function insertData($conf){
|
| 226 |
liveuser |
14186 |
|
| 3 |
liveuser |
14187 |
#初始化要回傳的內容
|
|
|
14188 |
$result=array();
|
|
|
14189 |
|
|
|
14190 |
#取得當前執行的函數名稱
|
|
|
14191 |
$result["function"]=__FUNCTION__;
|
|
|
14192 |
|
|
|
14193 |
#如果 $conf 不為陣列
|
|
|
14194 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
14195 |
|
| 3 |
liveuser |
14196 |
#設置執行失敗
|
|
|
14197 |
$result["status"]="false";
|
| 226 |
liveuser |
14198 |
|
| 3 |
liveuser |
14199 |
#設置執行錯誤訊息
|
|
|
14200 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
14201 |
|
|
|
14202 |
#如果傳入的參數為 null
|
|
|
14203 |
if($conf==null){
|
| 226 |
liveuser |
14204 |
|
| 3 |
liveuser |
14205 |
#設置執行錯誤訊息
|
|
|
14206 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
14207 |
|
| 3 |
liveuser |
14208 |
}#if end
|
|
|
14209 |
|
|
|
14210 |
#回傳結果
|
|
|
14211 |
return $result;
|
| 226 |
liveuser |
14212 |
|
| 3 |
liveuser |
14213 |
}#if end
|
| 226 |
liveuser |
14214 |
|
| 3 |
liveuser |
14215 |
#函式說明:
|
|
|
14216 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
14217 |
#回傳結果:
|
|
|
14218 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
14219 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
14220 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
14221 |
#必填參數:
|
|
|
14222 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
14223 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","selectedDataBaseName","tableName","columnName","insertValue");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
14224 |
#可省略參數:
|
| 226 |
liveuser |
14225 |
$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string","string","string","array","array");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
14226 |
#$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
14227 |
#備註:
|
|
|
14228 |
#功能與checkExistAndType函式相同
|
|
|
14229 |
$variableCheck=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
14230 |
unset($conf["variableCheck"]["isexistMuti"]);
|
|
|
14231 |
|
|
|
14232 |
#如果 $variableCheck["status"] 等於 "false"
|
|
|
14233 |
if($variableCheck["status"]=="false"){
|
| 226 |
liveuser |
14234 |
|
| 3 |
liveuser |
14235 |
#設置執行錯誤的識別
|
|
|
14236 |
$result["status"]="false";
|
| 226 |
liveuser |
14237 |
|
| 3 |
liveuser |
14238 |
#設置執行錯誤的訊息
|
|
|
14239 |
$result["error"]=$variableCheck;
|
| 226 |
liveuser |
14240 |
|
| 3 |
liveuser |
14241 |
#回傳結果
|
|
|
14242 |
return $result;
|
| 226 |
liveuser |
14243 |
|
| 3 |
liveuser |
14244 |
}#if end
|
|
|
14245 |
|
|
|
14246 |
#如果 $variableCheck["passed"] 等於 "false"
|
|
|
14247 |
if($variableCheck["passed"]=="false"){
|
| 226 |
liveuser |
14248 |
|
| 3 |
liveuser |
14249 |
#設置執行錯誤的識別
|
|
|
14250 |
$result["status"]="false";
|
| 226 |
liveuser |
14251 |
|
| 3 |
liveuser |
14252 |
#設置執行錯誤的訊息
|
|
|
14253 |
$result["error"]=$variableCheck;
|
| 226 |
liveuser |
14254 |
|
| 3 |
liveuser |
14255 |
#回傳結果
|
|
|
14256 |
return $result;
|
| 226 |
liveuser |
14257 |
|
| 3 |
liveuser |
14258 |
}#if end
|
|
|
14259 |
|
|
|
14260 |
#連線到資料庫
|
|
|
14261 |
#函式說明:
|
|
|
14262 |
#連線到資料庫,結果會回傳一個陣列
|
|
|
14263 |
#$result["status"],若連線成功則爲"true",連線失敗則爲"false".
|
|
|
14264 |
#$result["connectInformation"],爲回傳的mysql連線資訊.
|
|
|
14265 |
#$result["error"],錯誤訊息 .
|
| 226 |
liveuser |
14266 |
#$result["function"],當前執行的函數名稱.
|
| 3 |
liveuser |
14267 |
#必填參數:
|
|
|
14268 |
$conf["db"]["dbConnect"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
14269 |
$conf["db"]["dbConnect"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
14270 |
#$conf["dbName"],字串,爲要連的資料庫名稱
|
|
|
14271 |
$conf["db"]["dbConnect"]["dbName"]=$conf["selectedDataBaseName"];
|
|
|
14272 |
#可省略參數:
|
| 226 |
liveuser |
14273 |
|
| 3 |
liveuser |
14274 |
#如果 $conf["dbPassword"] 有設定
|
|
|
14275 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
14276 |
|
| 3 |
liveuser |
14277 |
$conf["db"]["dbConnect"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
14278 |
|
| 3 |
liveuser |
14279 |
}#if end
|
| 226 |
liveuser |
14280 |
|
| 3 |
liveuser |
14281 |
#如果 $conf["dbPort"] 有設定
|
|
|
14282 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
14283 |
|
| 3 |
liveuser |
14284 |
$conf["db"]["dbConnect"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
14285 |
|
| 3 |
liveuser |
14286 |
}#if end
|
| 226 |
liveuser |
14287 |
|
| 3 |
liveuser |
14288 |
$con=db::dbConnect($conf["db"]["dbConnect"]);
|
|
|
14289 |
unset($conf["db"]);
|
|
|
14290 |
|
|
|
14291 |
#如果連線到資料庫失敗
|
|
|
14292 |
if($con["status"]==="false"){
|
| 226 |
liveuser |
14293 |
|
| 3 |
liveuser |
14294 |
#設置執行失敗
|
|
|
14295 |
$result["status"]="false";
|
| 226 |
liveuser |
14296 |
|
| 3 |
liveuser |
14297 |
#設置執行錯誤訊息
|
|
|
14298 |
$result["error"]=$con;
|
| 226 |
liveuser |
14299 |
|
| 3 |
liveuser |
14300 |
#回傳結果
|
|
|
14301 |
return $result;
|
| 226 |
liveuser |
14302 |
|
| 3 |
liveuser |
14303 |
}#if end
|
| 226 |
liveuser |
14304 |
|
| 183 |
liveuser |
14305 |
#var_dump($con);
|
| 226 |
liveuser |
14306 |
|
| 3 |
liveuser |
14307 |
#取得mysqli物件
|
|
|
14308 |
$mysqli=$con["connectInformation"];
|
|
|
14309 |
|
|
|
14310 |
#輸入資料到 資料表 board 的語法
|
|
|
14311 |
$str1="insert into `".$conf["selectedDataBaseName"]."`.`".$conf["tableName"]."`(";
|
| 226 |
liveuser |
14312 |
|
| 3 |
liveuser |
14313 |
#取得一筆資料有幾個項目
|
|
|
14314 |
$count=count($conf["columnName"]);
|
|
|
14315 |
|
|
|
14316 |
#跑 $count-1 次,插入第一筆到最倒數第二筆
|
|
|
14317 |
for($i=0;$i<=($count-2);$i++){
|
| 226 |
liveuser |
14318 |
|
| 183 |
liveuser |
14319 |
#放入欲插入的項目名稱
|
| 3 |
liveuser |
14320 |
$str1=$str1."`".$conf["columnName"][$i]."`".",";
|
| 226 |
liveuser |
14321 |
|
| 3 |
liveuser |
14322 |
}#for end
|
|
|
14323 |
|
|
|
14324 |
#插入最後一筆項目名稱
|
|
|
14325 |
$lastItem = ($count-1);
|
| 226 |
liveuser |
14326 |
$str1=$str1."`".$conf["columnName"][$lastItem]."`)";
|
|
|
14327 |
|
| 3 |
liveuser |
14328 |
#要插入的數值語法開始
|
|
|
14329 |
$str2=" values (";
|
|
|
14330 |
|
|
|
14331 |
#跑 $count-1 次
|
|
|
14332 |
for($i=0;$i<=($count-2);$i++){
|
|
|
14333 |
|
| 226 |
liveuser |
14334 |
#插入第一筆到最倒數第二筆的資料內容
|
| 3 |
liveuser |
14335 |
$str2=$str2."'".mysqli_real_escape_string($mysqli,$conf["insertValue"][$i])."',";
|
| 226 |
liveuser |
14336 |
|
| 3 |
liveuser |
14337 |
}#for end
|
|
|
14338 |
|
|
|
14339 |
#插入最後一筆的資料內容
|
|
|
14340 |
$lastItem = ($count-1);
|
| 226 |
liveuser |
14341 |
$str2=$str2."'".mysqli_real_escape_string($mysqli,$conf["insertValue"][$lastItem])."');";
|
| 3 |
liveuser |
14342 |
|
|
|
14343 |
#合併要執行的sql語法
|
|
|
14344 |
$sqlString=$str1.$str2;
|
| 226 |
liveuser |
14345 |
|
| 3 |
liveuser |
14346 |
#執行sql語法
|
|
|
14347 |
#函式說明:
|
|
|
14348 |
#執行mysql指令
|
|
|
14349 |
#回傳結果::
|
|
|
14350 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
14351 |
#$result["error"],錯誤訊息的陣列
|
|
|
14352 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
14353 |
#$result["queryConn"],用於資料庫操作的變數.
|
|
|
14354 |
#$result["queryString"],mysql查詢的語言
|
|
|
14355 |
#查詢號的解果,需要解析。
|
|
|
14356 |
#必填參數:
|
|
|
14357 |
$conf["db::execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
14358 |
$conf["db::execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
14359 |
$conf["db::execMysqlQuery"]["dbSql"]=$sqlString;#要執行sql語法
|
| 226 |
liveuser |
14360 |
#可省略參數:
|
|
|
14361 |
|
| 3 |
liveuser |
14362 |
#如果 $conf["dbPassword"] 有設置
|
|
|
14363 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
14364 |
|
| 3 |
liveuser |
14365 |
$conf["db::execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
14366 |
|
| 3 |
liveuser |
14367 |
}#if end
|
| 226 |
liveuser |
14368 |
|
| 3 |
liveuser |
14369 |
#如果 $conf["dbPort"] 有設置
|
|
|
14370 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
14371 |
|
| 3 |
liveuser |
14372 |
$conf["db::execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的3306 port.
|
| 226 |
liveuser |
14373 |
|
| 3 |
liveuser |
14374 |
}#if end
|
| 226 |
liveuser |
14375 |
|
| 3 |
liveuser |
14376 |
#$conf["dbLink"],物件,mysqli物件,由mysqli_connect()回傳的物件內容,若為數值則改用賬號密碼等資訊進行連線,反之則沿用連線物件.
|
|
|
14377 |
$conf["db::execMysqlQuery"]["dbLink"]=$mysqli;
|
|
|
14378 |
#$conf["autoClose],字串,"true"代表要自動斷線,預設為"true"會自動斷線
|
|
|
14379 |
$conf["db::execMysqlQuery"]["autoClose"]="false";
|
|
|
14380 |
$mysqlQueryResult=db::execMysqlQuery($conf["db::execMysqlQuery"]);
|
|
|
14381 |
unset($conf["db::execMysqlQuery"]);
|
| 226 |
liveuser |
14382 |
|
| 3 |
liveuser |
14383 |
#若執行 query 語法失敗
|
|
|
14384 |
if($mysqlQueryResult["status"]=="false"){
|
| 226 |
liveuser |
14385 |
|
| 3 |
liveuser |
14386 |
#設置執行錯誤識別
|
|
|
14387 |
$result["status"]="false";
|
| 226 |
liveuser |
14388 |
|
| 3 |
liveuser |
14389 |
#設置錯誤訊息
|
| 226 |
liveuser |
14390 |
$result["error"]=$mysqlQueryResult;
|
| 3 |
liveuser |
14391 |
|
|
|
14392 |
#回傳結果
|
|
|
14393 |
return $result;
|
|
|
14394 |
|
|
|
14395 |
}#else end
|
| 226 |
liveuser |
14396 |
|
| 3 |
liveuser |
14397 |
#取得新增的該筆記錄id
|
|
|
14398 |
$result["lastInsertId"]=mysqli_insert_id($mysqlQueryResult["queryConn"]);
|
|
|
14399 |
|
|
|
14400 |
#取得執行的sql字串
|
|
|
14401 |
$result["sql"]=$mysqlQueryResult["queryString"];
|
|
|
14402 |
|
|
|
14403 |
#執行到這邊代表執行成功
|
|
|
14404 |
$result["status"]="true";
|
|
|
14405 |
|
|
|
14406 |
#回傳結果
|
|
|
14407 |
return $result;
|
| 226 |
liveuser |
14408 |
|
| 3 |
liveuser |
14409 |
}#function insertData end
|
|
|
14410 |
|
|
|
14411 |
/*
|
| 226 |
liveuser |
14412 |
#函式說明:
|
| 3 |
liveuser |
14413 |
#更新資料表裏面的資料
|
| 226 |
liveuser |
14414 |
#回傳結果:
|
| 3 |
liveuser |
14415 |
#$result["status"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了
|
|
|
14416 |
#$result["error"],錯誤訊息
|
|
|
14417 |
#$result["function"],當前執行的函數名稱
|
|
|
14418 |
#$result["sql"],執行的sql語法.
|
|
|
14419 |
#$result["argu"],使用的參數.
|
|
|
14420 |
#必填參數:
|
|
|
14421 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
14422 |
$conf["fileArgu"]=__FILE__;
|
|
|
14423 |
#$conf["dbAddress"],字串,爲mysql-Server的位置
|
|
|
14424 |
$conf["dbAddress"]=$dbAddress;
|
|
|
14425 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
|
|
|
14426 |
$conf["dbAccount"]=$dbAccount;
|
|
|
14427 |
#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱
|
|
|
14428 |
$conf["selectedDataBaseName"]=$dbName;
|
|
|
14429 |
#$conf["tableName"],字串,要修改的資料表名稱
|
|
|
14430 |
$conf["tableName"]="";
|
|
|
14431 |
#$conf["whereColumn"],字串陣列,爲用來判斷要更新的哪筆資料的欄位名稱,須爲陣列值
|
|
|
14432 |
$conf["whereColumn"]=array("");
|
|
|
14433 |
#$conf["whereValue"],字串陣列,為用來判斷是要更新哪筆資料的欄位對應數值,須爲陣列值
|
|
|
14434 |
$conf["whereValue"]=array("");
|
|
|
14435 |
#$conf["tableColumnName"],字串陣列,資料表項目的名稱陣列
|
|
|
14436 |
$conf["tableColumnName"]=array("");
|
|
|
14437 |
#$conf["updateDataValue"],字串陣列,要更改成對應資料表項目的內容,須為陣列值
|
|
|
14438 |
$conf["updateDataValue"]=array("");
|
|
|
14439 |
#可省略參數:
|
|
|
14440 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼.
|
|
|
14441 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
14442 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
|
|
|
14443 |
#$conf["dbPort"]=$dbPort;
|
|
|
14444 |
#參考資料:
|
|
|
14445 |
#無.
|
|
|
14446 |
#備註:
|
| 183 |
liveuser |
14447 |
#建議修改 whereValue 參數為多維陣列,每個元素為有兩個元素的陣列,其元素的key為operator者代表運算子,其value可以為"=","<>",">","<",預設為"=";key為value者代表運算元,亦即用來比較的數字、字串等.
|
| 3 |
liveuser |
14448 |
*/
|
|
|
14449 |
public static function updateDataTableContent($conf){
|
| 226 |
liveuser |
14450 |
|
| 3 |
liveuser |
14451 |
#初始化要回傳的內容
|
|
|
14452 |
$result=array();
|
|
|
14453 |
|
|
|
14454 |
#取得當前執行的函數名稱
|
|
|
14455 |
$result["function"]=__FUNCTION__;
|
|
|
14456 |
|
|
|
14457 |
#如果 $conf 不為陣列
|
|
|
14458 |
if(gettype($conf)!=="array"){
|
| 226 |
liveuser |
14459 |
|
| 3 |
liveuser |
14460 |
#設置執行失敗
|
|
|
14461 |
$result["status"]="false";
|
| 226 |
liveuser |
14462 |
|
| 3 |
liveuser |
14463 |
#設置執行錯誤訊息
|
|
|
14464 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
14465 |
|
|
|
14466 |
#如果傳入的參數為 null
|
|
|
14467 |
if($conf==null){
|
| 226 |
liveuser |
14468 |
|
| 3 |
liveuser |
14469 |
#設置執行錯誤訊息
|
|
|
14470 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
14471 |
|
| 3 |
liveuser |
14472 |
}#if end
|
|
|
14473 |
|
|
|
14474 |
#回傳結果
|
|
|
14475 |
return $result;
|
| 226 |
liveuser |
14476 |
|
| 3 |
liveuser |
14477 |
}#if end
|
| 226 |
liveuser |
14478 |
|
| 3 |
liveuser |
14479 |
#儲存使用的參數
|
|
|
14480 |
$result["argu"]=$conf;
|
| 226 |
liveuser |
14481 |
|
| 3 |
liveuser |
14482 |
#函式說明:
|
|
|
14483 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
14484 |
#回傳結果:
|
|
|
14485 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14486 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
14487 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
14488 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
14489 |
#必填參數:
|
|
|
14490 |
$conf["variableCheck"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
14491 |
$conf["variableCheck"]["isexistMuti"]["variableCheck"]=array("fileArgu","dbAddress","dbAccount","selectedDataBaseName","tableName","whereColumn","whereValue","tableColumnName","updateDataValue");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
14492 |
#可省略參數:
|
| 226 |
liveuser |
14493 |
$conf["variableCheck"]["isexistMuti"]["variableType"]=array("string","string","string","string","string","array","array","array","array");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
14494 |
#$conf["variableCheck"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
14495 |
$checkResult=variableCheck::isexistMulti($conf["variableCheck"]["isexistMuti"]);
|
|
|
14496 |
unset($conf["variableCheck"]["isexistMuti"]);
|
| 226 |
liveuser |
14497 |
|
| 3 |
liveuser |
14498 |
#如果檢查參數作業出錯
|
|
|
14499 |
if($checkResult["status"]==="false"){
|
| 226 |
liveuser |
14500 |
|
| 3 |
liveuser |
14501 |
#設置執行錯誤識別
|
|
|
14502 |
$result["status"]="false";
|
| 226 |
liveuser |
14503 |
|
| 3 |
liveuser |
14504 |
#設置錯誤訊息
|
|
|
14505 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
14506 |
|
| 3 |
liveuser |
14507 |
#回傳結果
|
|
|
14508 |
return $result;
|
| 226 |
liveuser |
14509 |
|
| 3 |
liveuser |
14510 |
}#if end
|
| 226 |
liveuser |
14511 |
|
| 3 |
liveuser |
14512 |
#如果檢查沒通過
|
|
|
14513 |
if($checkResult["passed"]==="false"){
|
| 226 |
liveuser |
14514 |
|
| 3 |
liveuser |
14515 |
#設置執行錯誤識別
|
|
|
14516 |
$result["status"]="false";
|
| 226 |
liveuser |
14517 |
|
| 3 |
liveuser |
14518 |
#設置錯誤訊息
|
|
|
14519 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
14520 |
|
| 3 |
liveuser |
14521 |
#回傳結果
|
|
|
14522 |
return $result;
|
| 226 |
liveuser |
14523 |
|
| 3 |
liveuser |
14524 |
}#if end
|
|
|
14525 |
|
|
|
14526 |
#將陣列變數 $conf["whereColumn"] 與 $conf["whereValue"] 對應的變數中不存在的 $conf["whereValue"][$i] 元素去掉,並同時調整 $conf["whereColumn"] 使兩者變數的元素數量均相同。
|
|
|
14527 |
#函式說明:
|
|
|
14528 |
#比對兩個陣列變數,如果其中一個陣列變數的元素不存在,則將之消去,然後進行替補。另一個陣列變數則也要做同步的動作。
|
|
|
14529 |
#回傳結果::
|
|
|
14530 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常。
|
|
|
14531 |
#$result["error"],錯誤訊息。
|
|
|
14532 |
#$result["content"],組合成新值的一維陣列。
|
|
|
14533 |
#$result["function"],當前執行的函數名稱。
|
|
|
14534 |
#必填參數:
|
|
|
14535 |
$conf_compareAndModify2Arrays["arraysA"]=$conf["tableColumnName"];#用來跟陣列變數B比較的陣列變數A
|
|
|
14536 |
$conf_compareAndModify2Arrays["arraysB"]=$conf["updateDataValue"];#用來跟陣列變數A比較的陣列變數B
|
|
|
14537 |
$compareAndModifyTwoArrays=arrays::compareAndModifyTwoArrays($conf_compareAndModify2Arrays);
|
|
|
14538 |
unset($conf_compareAndModify2Arrays);
|
|
|
14539 |
|
|
|
14540 |
#如果 arrays::compareAndModifyTwoArrays 執行失敗
|
|
|
14541 |
if($compareAndModifyTwoArrays["status"]==="false"){
|
| 226 |
liveuser |
14542 |
|
| 3 |
liveuser |
14543 |
#設置執行錯誤識別
|
|
|
14544 |
$result["status"]="false";
|
| 226 |
liveuser |
14545 |
|
| 3 |
liveuser |
14546 |
#設置錯誤訊息
|
|
|
14547 |
$result["error"]=$compareAndModifyTwoArrays;
|
| 226 |
liveuser |
14548 |
|
| 3 |
liveuser |
14549 |
#回傳結果
|
|
|
14550 |
return $result;
|
| 226 |
liveuser |
14551 |
|
| 3 |
liveuser |
14552 |
}#if end
|
|
|
14553 |
|
|
|
14554 |
#將整理好的 $result["compareAndModify2Arrays"]["A"] 放到 $conf["whereColumn"] ; $result["compareAndModify2Arrays"]["B"] 放到 $conf["whereValue"]
|
|
|
14555 |
$conf["tableColumnName"]=$compareAndModifyTwoArrays["newArraysA"];
|
|
|
14556 |
$conf["updateDataValue"]=$compareAndModifyTwoArrays["newArraysB"];
|
|
|
14557 |
|
|
|
14558 |
#更新 $conf["selectedDatabaseName"].$tableName 資料表
|
| 226 |
liveuser |
14559 |
$selectUpdateTableSql="UPDATE `".$conf["selectedDataBaseName"]."`.`".$conf["tableName"]."` ";
|
|
|
14560 |
|
| 3 |
liveuser |
14561 |
#更新資料表資料語法的一部分
|
|
|
14562 |
$chooseColumnSql="SET ";
|
|
|
14563 |
|
|
|
14564 |
#取得一筆資料有幾個項目
|
|
|
14565 |
$counts=count($conf["tableColumnName"]);
|
|
|
14566 |
|
|
|
14567 |
#儲存宣告shell變數的指令陣列
|
|
|
14568 |
$shellVarDefined=array();
|
|
|
14569 |
|
|
|
14570 |
#儲存要宣告的變數
|
|
|
14571 |
$varDefined=array();
|
|
|
14572 |
|
|
|
14573 |
#有$count欄項目,
|
|
|
14574 |
for($i=0;$i<$counts;$i++){
|
|
|
14575 |
|
|
|
14576 |
#如果是最後一項要更新的資料
|
|
|
14577 |
if($i==($counts-1)){
|
|
|
14578 |
|
|
|
14579 |
#如果內容不為字串
|
|
|
14580 |
if(gettype($conf["updateDataValue"][$i])!=="string"){
|
| 226 |
liveuser |
14581 |
|
| 3 |
liveuser |
14582 |
#設置執行錯誤識別
|
|
|
14583 |
$result["status"]="false";
|
| 226 |
liveuser |
14584 |
|
| 3 |
liveuser |
14585 |
#設置錯誤訊息
|
|
|
14586 |
$result["error"][]="欲使用的變數不為字串";
|
| 226 |
liveuser |
14587 |
|
| 3 |
liveuser |
14588 |
#設置錯誤訊息
|
|
|
14589 |
$result["error"][]=$conf["updateDataValue"][$i];
|
| 226 |
liveuser |
14590 |
|
| 3 |
liveuser |
14591 |
#回傳結果
|
|
|
14592 |
return $result;
|
| 226 |
liveuser |
14593 |
|
| 3 |
liveuser |
14594 |
}#if end
|
|
|
14595 |
|
|
|
14596 |
#定義 shell script 變數
|
|
|
14597 |
$shellVarDefined[]=array("cmd"=>"x".$i."=","param"=>array($conf["updateDataValue"][$i]));
|
| 226 |
liveuser |
14598 |
|
| 183 |
liveuser |
14599 |
#定義sql變數
|
|
|
14600 |
$varDefined[]="select @x".$i." := '\${x".$i."}';";
|
| 3 |
liveuser |
14601 |
|
| 183 |
liveuser |
14602 |
#將要更新的內容字串串接,結尾無逗號
|
| 3 |
liveuser |
14603 |
$chooseColumnSql = $chooseColumnSql."`".$conf["tableColumnName"][$i]."`= @x".$i." ";
|
| 226 |
liveuser |
14604 |
|
| 3 |
liveuser |
14605 |
}#判斷式結束
|
|
|
14606 |
|
|
|
14607 |
#如果不是最後一項要更新的資料
|
|
|
14608 |
if($i!=($counts-1)){
|
|
|
14609 |
|
|
|
14610 |
#定義 shell script 變數
|
|
|
14611 |
$shellVarDefined[]=array("cmd"=>"x".$i."=","param"=>array($conf["updateDataValue"][$i]));
|
| 226 |
liveuser |
14612 |
|
| 183 |
liveuser |
14613 |
#定義sql變數
|
|
|
14614 |
$varDefined[]="select @x".$i." := '\${x".$i."}';";
|
| 3 |
liveuser |
14615 |
|
|
|
14616 |
#將要更新的內容字串串接,結尾有逗號
|
|
|
14617 |
$chooseColumnSql = $chooseColumnSql."`".$conf["tableColumnName"][$i]."`= @x".$i." ,";
|
| 226 |
liveuser |
14618 |
|
| 3 |
liveuser |
14619 |
}#判斷式結束
|
| 226 |
liveuser |
14620 |
|
| 3 |
liveuser |
14621 |
}#回圈結束
|
|
|
14622 |
|
|
|
14623 |
#取得條件有幾項
|
| 183 |
liveuser |
14624 |
$conditionArrayCounts=count($conf["whereColumn"]);
|
| 3 |
liveuser |
14625 |
|
|
|
14626 |
#構成條件式
|
|
|
14627 |
for($i=0;$i<$conditionArrayCounts;$i++){
|
|
|
14628 |
|
|
|
14629 |
#如果是第一筆
|
| 183 |
liveuser |
14630 |
if($i===0){
|
| 3 |
liveuser |
14631 |
|
|
|
14632 |
#尋找的條件式
|
|
|
14633 |
$condition="WHERE `".$conf["whereColumn"][$i]."` = '".$conf["whereValue"][$i]."'";
|
|
|
14634 |
|
|
|
14635 |
#測試有無抓到第一個條件
|
|
|
14636 |
#var_dump($condition);
|
|
|
14637 |
|
|
|
14638 |
}#判斷式結束
|
|
|
14639 |
|
|
|
14640 |
#如果不是第一筆
|
| 183 |
liveuser |
14641 |
if($i!==0){
|
| 3 |
liveuser |
14642 |
|
|
|
14643 |
#其它條件
|
|
|
14644 |
$condition=$condition." AND `".$conf["whereColumn"][$i]."` = '".$conf["whereValue"][$i]."'";
|
|
|
14645 |
|
|
|
14646 |
#測試有無抓到其它條件
|
|
|
14647 |
#var_dump($condition);
|
| 226 |
liveuser |
14648 |
|
| 3 |
liveuser |
14649 |
}#判斷式結束
|
|
|
14650 |
|
|
|
14651 |
}#迴圈結束
|
|
|
14652 |
|
|
|
14653 |
#初始化定義變數的sql
|
|
|
14654 |
$varDefineStr="";
|
|
|
14655 |
|
|
|
14656 |
#針對每個要使用的數值
|
|
|
14657 |
foreach($varDefined as $index=>$var){
|
| 226 |
liveuser |
14658 |
|
| 3 |
liveuser |
14659 |
#累加定義變數的sql
|
|
|
14660 |
$varDefineStr=$varDefineStr.$var;
|
| 226 |
liveuser |
14661 |
|
| 3 |
liveuser |
14662 |
}#foreach end
|
|
|
14663 |
|
| 226 |
liveuser |
14664 |
#合併所有的語法成一句完整的語法
|
| 3 |
liveuser |
14665 |
$sqlString = $varDefineStr.$selectUpdateTableSql.$chooseColumnSql.$condition;
|
|
|
14666 |
|
| 183 |
liveuser |
14667 |
#debug
|
|
|
14668 |
#var_dump(__LINE__,$sqlString);
|
|
|
14669 |
|
| 3 |
liveuser |
14670 |
#設置取得執行的sql語法
|
|
|
14671 |
$result["sql"]=$sqlString;
|
|
|
14672 |
|
|
|
14673 |
#函式說明:
|
|
|
14674 |
#用shell執行mysql指令.
|
|
|
14675 |
#回傳結果::
|
|
|
14676 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
14677 |
#$result["error"],錯誤訊息的陣列
|
|
|
14678 |
#$result["function"],當前執行的涵式
|
|
|
14679 |
#$result["queryString"],mysql查詢的語言.
|
|
|
14680 |
#必填參數:
|
|
|
14681 |
#$conf["fileArgu"],字串,變數__FILE__的內容.
|
|
|
14682 |
$conf["db::shell"]["fileArgu"]=$conf["fileArgu"];
|
|
|
14683 |
#$conf["dbSql"],字串,要執行sql語法
|
|
|
14684 |
$conf["db::shell"]["dbSql"]=$sqlString;
|
|
|
14685 |
#$conf["dbAddress"],字串,爲mysql-Server的位置。
|
|
|
14686 |
$conf["db::shell"]["dbAddress"]=$conf["dbAddress"];
|
|
|
14687 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號。
|
| 226 |
liveuser |
14688 |
$conf["db::shell"]["dbAccount"]=$conf["dbAccount"];
|
| 3 |
liveuser |
14689 |
#可省略參數:
|
|
|
14690 |
$conf["db::shell"]["pre"]=$shellVarDefined;
|
| 226 |
liveuser |
14691 |
|
| 3 |
liveuser |
14692 |
#如果有設定密碼
|
|
|
14693 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
14694 |
|
| 3 |
liveuser |
14695 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼。
|
|
|
14696 |
$conf["db::shell"]["dbPassword"]=$conf["dbPassword"];
|
| 226 |
liveuser |
14697 |
|
| 3 |
liveuser |
14698 |
}#if end
|
| 226 |
liveuser |
14699 |
|
| 3 |
liveuser |
14700 |
#$conf["dbName"],字串,爲要連的資料庫名稱
|
|
|
14701 |
$conf["db::shell"]["dbName"]=$conf["selectedDataBaseName"];
|
| 226 |
liveuser |
14702 |
|
| 3 |
liveuser |
14703 |
#如果有設定port
|
|
|
14704 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
14705 |
|
| 3 |
liveuser |
14706 |
#$conf["dbPort"],字串,為連線到mysql-Server時對應的port,可省略,預設為3306.
|
|
|
14707 |
$conf["db::shell"]["dbPort"]=$conf["dbPort"];
|
| 226 |
liveuser |
14708 |
|
| 3 |
liveuser |
14709 |
}#if end
|
| 226 |
liveuser |
14710 |
|
| 3 |
liveuser |
14711 |
$shell=db::shell($conf["db::shell"]);
|
|
|
14712 |
unset($conf["db::shell"]);
|
| 226 |
liveuser |
14713 |
|
| 3 |
liveuser |
14714 |
#如果執行sql失敗
|
|
|
14715 |
if($shell["status"]==="false"){
|
| 226 |
liveuser |
14716 |
|
| 3 |
liveuser |
14717 |
#設置執行不正常
|
| 183 |
liveuser |
14718 |
$result["status"]="false";
|
| 226 |
liveuser |
14719 |
|
| 3 |
liveuser |
14720 |
#設置錯誤訊息
|
|
|
14721 |
$result["error"]=$shell;
|
| 226 |
liveuser |
14722 |
|
| 3 |
liveuser |
14723 |
#回傳結果
|
|
|
14724 |
return $result;
|
| 226 |
liveuser |
14725 |
|
| 3 |
liveuser |
14726 |
}#if end
|
| 226 |
liveuser |
14727 |
|
| 3 |
liveuser |
14728 |
#設置執行正常
|
|
|
14729 |
$result["status"]="true";
|
| 226 |
liveuser |
14730 |
|
| 3 |
liveuser |
14731 |
#回傳結果
|
|
|
14732 |
return $result;
|
|
|
14733 |
|
|
|
14734 |
}#function updateDataTableContent end
|
|
|
14735 |
|
|
|
14736 |
/*
|
|
|
14737 |
#函式說明:
|
|
|
14738 |
#將滿足條件的資料從資料表中刪除
|
| 226 |
liveuser |
14739 |
#回傳結果:
|
| 3 |
liveuser |
14740 |
#$result["status"],爲查詢是否成功,若爲0則成功,若爲1則表示失敗了
|
|
|
14741 |
#$result["function"],當前執行的函數名稱.
|
|
|
14742 |
#$result["error"],錯誤訊息
|
|
|
14743 |
#$result["sql"],執行的語法
|
|
|
14744 |
#必填參數:
|
|
|
14745 |
#$conf["dbAddress"],字串,爲mysql-Server的位置
|
|
|
14746 |
$conf["dbAddress"]=$dbAddress;
|
|
|
14747 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
|
|
|
14748 |
$conf["dbAccount"]=$dbAccount;
|
|
|
14749 |
#$conf["selectedDataBaseName"],字串,要選取的資料庫名稱
|
|
|
14750 |
$conf["selectedDataBaseName"]=$dbName;
|
|
|
14751 |
#$conf["selectedDataTableName"],字串,要選取的資料表的名稱
|
|
|
14752 |
$conf["selectedDataTableName"]="";
|
|
|
14753 |
#$conf["whereColumn"],字串陣列,爲用來判斷要刪除的哪筆資料的欄位名稱,須爲陣列值
|
|
|
14754 |
$conf["whereColumn"]=array("");
|
|
|
14755 |
#$conf["whereValue"]=,字串陣列,為用來判斷是要刪除哪筆資料的欄位對應數值,須爲陣列值
|
| 226 |
liveuser |
14756 |
$conf["whereValue"]=array("");
|
| 3 |
liveuser |
14757 |
#可省略參數:
|
|
|
14758 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
14759 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
14760 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
|
|
|
14761 |
#$conf["dbPort"]=$dbPort;
|
|
|
14762 |
#$conf["WhereColumnOperator"],字串陣列,用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
14763 |
#$conf["WhereColumnOperator"]=array("");
|
|
|
14764 |
#$conf["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值,預設皆爲AND。其數量應爲要判斷的欄位數量減一。
|
|
|
14765 |
#$conf["WhereColumnAndOr"]=array("");
|
|
|
14766 |
#參考資料:
|
|
|
14767 |
#無.
|
|
|
14768 |
#備註:
|
|
|
14769 |
#無.
|
| 226 |
liveuser |
14770 |
*/
|
| 3 |
liveuser |
14771 |
public static function deleteDataFromTable(&$conf){
|
| 226 |
liveuser |
14772 |
|
| 3 |
liveuser |
14773 |
#初始化要回傳的內容
|
|
|
14774 |
$result=array();
|
|
|
14775 |
|
|
|
14776 |
#取得當前執行的函數名稱
|
|
|
14777 |
$result["function"]=__FUNCTION__;
|
|
|
14778 |
|
|
|
14779 |
#如果 $conf 不為陣列
|
|
|
14780 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
14781 |
|
| 3 |
liveuser |
14782 |
#設置執行失敗
|
|
|
14783 |
$result["status"]="false";
|
| 226 |
liveuser |
14784 |
|
| 3 |
liveuser |
14785 |
#設置執行錯誤訊息
|
|
|
14786 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
14787 |
|
|
|
14788 |
#如果傳入的參數為 null
|
|
|
14789 |
if($conf==null){
|
| 226 |
liveuser |
14790 |
|
| 3 |
liveuser |
14791 |
#設置執行錯誤訊息
|
|
|
14792 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
14793 |
|
| 3 |
liveuser |
14794 |
}#if end
|
|
|
14795 |
|
|
|
14796 |
#回傳結果
|
|
|
14797 |
return $result;
|
| 226 |
liveuser |
14798 |
|
| 3 |
liveuser |
14799 |
}#if end
|
|
|
14800 |
|
|
|
14801 |
#檢查參數
|
|
|
14802 |
#函式說明:
|
|
|
14803 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
14804 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14805 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
14806 |
#$result["function"],當前執行的函式名稱.
|
|
|
14807 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
14808 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
14809 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
14810 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
14811 |
#必填參數:
|
|
|
14812 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
14813 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
14814 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
14815 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","selectedDataBaseName","selectedDataTableName","whereColumn","whereValue");
|
| 226 |
liveuser |
14816 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
14817 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","array","array");
|
|
|
14818 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
14819 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
14820 |
#可省略參數:
|
|
|
14821 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
14822 |
#$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
14823 |
#$conf["variableCheck::checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
14824 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort","WhereColumnOperator","WhereColumnAndOr");
|
| 226 |
liveuser |
14825 |
#$conf["variableCheck::checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
14826 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","array","array");
|
|
|
14827 |
#$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
14828 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null,null,null);
|
|
|
14829 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
14830 |
#$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("WhereColumnOperator","WhereColumnAndOr");
|
|
|
14831 |
#var_dump($conf["variableCheck::checkArguments"]);
|
|
|
14832 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
14833 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
14834 |
|
|
|
14835 |
#如果檢查作業出出錯
|
|
|
14836 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
14837 |
|
| 3 |
liveuser |
14838 |
#設置錯誤識別
|
|
|
14839 |
$result["status"]="false";
|
| 226 |
liveuser |
14840 |
|
| 3 |
liveuser |
14841 |
#設置錯誤訊息
|
|
|
14842 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
14843 |
|
| 3 |
liveuser |
14844 |
#回傳結果
|
|
|
14845 |
return $result;
|
| 226 |
liveuser |
14846 |
|
| 3 |
liveuser |
14847 |
}#if end
|
| 226 |
liveuser |
14848 |
|
| 3 |
liveuser |
14849 |
#如果檢查作業出出錯
|
|
|
14850 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
14851 |
|
| 3 |
liveuser |
14852 |
#設置錯誤識別
|
|
|
14853 |
$result["status"]="false";
|
| 226 |
liveuser |
14854 |
|
| 3 |
liveuser |
14855 |
#設置錯誤訊息
|
|
|
14856 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
14857 |
|
| 3 |
liveuser |
14858 |
#回傳結果
|
|
|
14859 |
return $result;
|
| 226 |
liveuser |
14860 |
|
| 3 |
liveuser |
14861 |
}#if end
|
|
|
14862 |
|
|
|
14863 |
#刪除資料的語法開始,指定了表格的名稱
|
|
|
14864 |
$sql="DELETE FROM `".$conf["selectedDataBaseName"]."`.`".$conf["selectedDataTableName"]."` ";
|
|
|
14865 |
|
|
|
14866 |
#取得有幾個條件
|
|
|
14867 |
$counts=count($conf["whereColumn"]);
|
|
|
14868 |
|
|
|
14869 |
#連線到資料庫
|
|
|
14870 |
#函式說明:
|
|
|
14871 |
#連線到資料庫,結果會回傳一個陣列
|
|
|
14872 |
#$result["status"],若連線成功則爲"true",連線失敗則爲"false".
|
|
|
14873 |
#$result["connectInformation"],爲回傳的mysql連線資訊.
|
|
|
14874 |
#$result["error"],錯誤訊息 .
|
| 226 |
liveuser |
14875 |
#$result["function"],當前執行的函數名稱.
|
| 3 |
liveuser |
14876 |
#必填參數:
|
|
|
14877 |
$conf["db"]["dbConnect"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
14878 |
$conf["db"]["dbConnect"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
14879 |
#$conf["dbName"],字串,爲要連的資料庫名稱
|
|
|
14880 |
$conf["db"]["dbConnect"]["dbName"]=$conf["selectedDataBaseName"];
|
|
|
14881 |
#可省略參數:
|
| 226 |
liveuser |
14882 |
|
| 3 |
liveuser |
14883 |
#如果 $conf["dbPassword"] 有設定
|
|
|
14884 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
14885 |
|
| 3 |
liveuser |
14886 |
$conf["db"]["dbConnect"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
14887 |
|
| 3 |
liveuser |
14888 |
}#if end
|
| 226 |
liveuser |
14889 |
|
| 3 |
liveuser |
14890 |
#如果 $conf["dbPort"] 有設定
|
|
|
14891 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
14892 |
|
| 3 |
liveuser |
14893 |
$conf["db"]["dbConnect"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
14894 |
|
| 3 |
liveuser |
14895 |
}#if end
|
| 226 |
liveuser |
14896 |
|
| 3 |
liveuser |
14897 |
$con=db::dbConnect($conf["db"]["dbConnect"]);
|
|
|
14898 |
unset($conf["db"]);
|
|
|
14899 |
|
|
|
14900 |
#如果連線到資料庫失敗
|
|
|
14901 |
if($con["status"]==="false"){
|
| 226 |
liveuser |
14902 |
|
| 3 |
liveuser |
14903 |
#設置執行失敗
|
|
|
14904 |
$result["status"]="false";
|
| 226 |
liveuser |
14905 |
|
| 3 |
liveuser |
14906 |
#設置執行錯誤訊息
|
|
|
14907 |
$result["error"]=$con;
|
| 226 |
liveuser |
14908 |
|
| 3 |
liveuser |
14909 |
#回傳結果
|
|
|
14910 |
return $result;
|
| 226 |
liveuser |
14911 |
|
| 3 |
liveuser |
14912 |
}#if end
|
| 226 |
liveuser |
14913 |
|
|
|
14914 |
#var_dump($con);
|
|
|
14915 |
|
| 3 |
liveuser |
14916 |
#取得mysqli物件
|
|
|
14917 |
$mysqli=$con["connectInformation"];
|
|
|
14918 |
|
|
|
14919 |
#條件語句
|
|
|
14920 |
for($i=0;$i<$counts;$i++){
|
| 226 |
liveuser |
14921 |
|
| 3 |
liveuser |
14922 |
#如果 $conf["WhereColumnOperator"] 不存在
|
|
|
14923 |
if(!isset($conf["WhereColumnOperator"])){
|
| 226 |
liveuser |
14924 |
|
| 3 |
liveuser |
14925 |
#如果 $conf["WhereColumnOperator"][$i] 不存在
|
|
|
14926 |
if(!isset($conf["WhereColumnOperator"][$i])){
|
| 226 |
liveuser |
14927 |
|
| 3 |
liveuser |
14928 |
#設置為 "="
|
|
|
14929 |
$conf["WhereColumnOperator"][$i]="=";
|
| 226 |
liveuser |
14930 |
|
| 3 |
liveuser |
14931 |
}#if end
|
| 226 |
liveuser |
14932 |
|
| 3 |
liveuser |
14933 |
}#if end
|
| 226 |
liveuser |
14934 |
|
| 3 |
liveuser |
14935 |
#反之若 $conf["WhereColumnOperator"][$i] 不存在
|
|
|
14936 |
else if(!isset($conf["WhereColumnOperator"][$i])){
|
| 226 |
liveuser |
14937 |
|
| 3 |
liveuser |
14938 |
#設置為 "="
|
|
|
14939 |
$conf["WhereColumnOperator"][$i]="=";
|
| 226 |
liveuser |
14940 |
|
| 3 |
liveuser |
14941 |
}#if end
|
| 226 |
liveuser |
14942 |
|
| 3 |
liveuser |
14943 |
#以下變數應該要為字串
|
|
|
14944 |
$checkedVar["whereColumn"]=$conf["whereColumn"][$i];
|
|
|
14945 |
$checkedVar["WhereColumnOperator"]=$conf["WhereColumnOperator"][$i];
|
|
|
14946 |
$checkedVar["whereValue"]=$conf["whereValue"][$i];
|
| 226 |
liveuser |
14947 |
|
| 3 |
liveuser |
14948 |
#函式說明:
|
|
|
14949 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
14950 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
14951 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
14952 |
#$result["function"],當前執行的函式名稱.
|
|
|
14953 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
14954 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
14955 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
14956 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
14957 |
#必填參數:
|
|
|
14958 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
14959 |
$conf["variableCheck::checkArguments"]["varInput"]=&$checkedVar;
|
|
|
14960 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
14961 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("whereColumn","WhereColumnOperator","whereValue");
|
| 226 |
liveuser |
14962 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
14963 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
14964 |
#$conf["variableCheck::checkArguments"]["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
14965 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
14966 |
#可省略參數:
|
|
|
14967 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true"。
|
|
|
14968 |
#$conf["canBeEmptyString"]="false";
|
|
|
14969 |
#$conf["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
14970 |
#$conf["skipableVariableName"]=array();
|
| 226 |
liveuser |
14971 |
#$conf["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
14972 |
#$conf["skipableVariableType"]=array();
|
|
|
14973 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
14974 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
14975 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
14976 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
14977 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
14978 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
14979 |
|
| 3 |
liveuser |
14980 |
#如果檢查失敗
|
|
|
14981 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
14982 |
|
| 3 |
liveuser |
14983 |
#設置執行錯誤
|
|
|
14984 |
$result["status"]="false";
|
| 226 |
liveuser |
14985 |
|
| 3 |
liveuser |
14986 |
#設置執行錯誤訊息
|
|
|
14987 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
14988 |
|
| 3 |
liveuser |
14989 |
#回傳結果
|
|
|
14990 |
return $result;
|
| 226 |
liveuser |
14991 |
|
| 3 |
liveuser |
14992 |
}#if end
|
| 226 |
liveuser |
14993 |
|
| 3 |
liveuser |
14994 |
#如果檢查失敗
|
|
|
14995 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
14996 |
|
| 3 |
liveuser |
14997 |
#設置執行錯誤
|
|
|
14998 |
$result["status"]="false";
|
| 226 |
liveuser |
14999 |
|
| 3 |
liveuser |
15000 |
#設置執行錯誤訊息
|
|
|
15001 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
15002 |
|
| 3 |
liveuser |
15003 |
#回傳結果
|
|
|
15004 |
return $result;
|
| 226 |
liveuser |
15005 |
|
| 3 |
liveuser |
15006 |
}#if end
|
| 226 |
liveuser |
15007 |
|
| 3 |
liveuser |
15008 |
#如果是第一筆
|
|
|
15009 |
if($i==0){
|
|
|
15010 |
|
|
|
15011 |
#如果 $conf["WhereColumnOperator"] 存在
|
|
|
15012 |
if(isset($conf["WhereColumnOperator"])){
|
|
|
15013 |
|
|
|
15014 |
#設定第一個條件
|
|
|
15015 |
$sql = $sql." WHERE `".$conf["whereColumn"][$i]. "` ".$conf["WhereColumnOperator"][$i]." '". mysqli_real_escape_string($mysqli,$conf["whereValue"][$i])."'";
|
| 226 |
liveuser |
15016 |
|
| 3 |
liveuser |
15017 |
}#if end
|
|
|
15018 |
|
|
|
15019 |
#反之 $conf["WhereColumnOperator"] 不存在
|
|
|
15020 |
else{
|
|
|
15021 |
|
|
|
15022 |
#設定第一個條件
|
| 226 |
liveuser |
15023 |
$sql = $sql." WHERE `".$conf["whereColumn"][$i]. "` = '". mysqli_real_escape_string($mysqli,$conf["whereValue"][$i])."'";
|
| 3 |
liveuser |
15024 |
|
|
|
15025 |
}#else end
|
| 226 |
liveuser |
15026 |
|
| 3 |
liveuser |
15027 |
}#判斷式
|
|
|
15028 |
|
|
|
15029 |
#如果不是第一個條件
|
|
|
15030 |
if($i!=0){
|
|
|
15031 |
|
| 226 |
liveuser |
15032 |
#如果 $conf["WhereColumnAndOr"] 不存在
|
| 3 |
liveuser |
15033 |
if(!isset($conf["WhereColumnAndOr"])){
|
|
|
15034 |
|
|
|
15035 |
#將 $conf["WhereColumnAndOr"] 裏面的元素置換爲 AND
|
|
|
15036 |
#函式說明:
|
|
|
15037 |
#建立一個陣列,可以指派陣列的內容,然後回傳
|
|
|
15038 |
#回傳結果::
|
|
|
15039 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15040 |
#$result["function"],當前執行的函數名稱.
|
|
|
15041 |
#$result["error"],錯誤訊息陣列.
|
|
|
15042 |
#$result["content"],爲陣列變數內容
|
|
|
15043 |
#必填參數:
|
|
|
15044 |
$conf_arrays_create["arrayContent"]=array("AND");#陣列元素的內容,須爲陣列值。
|
|
|
15045 |
#可省略參數:
|
|
|
15046 |
$conf_arrays_create["arrayCounts"]=$counts-1;#爲陣列的元素有幾個,若沒設定,則數量爲$conf["arrayContent"]裏的元素數量
|
|
|
15047 |
$conf_arrays_create["theSameAs"]="true";#若設爲"true",則所有元素內容都跟第一個元素內容相同
|
|
|
15048 |
$create=arrays::create($conf_arrays_create);
|
|
|
15049 |
unset($conf_arrays_create);
|
| 226 |
liveuser |
15050 |
|
| 3 |
liveuser |
15051 |
#如果建立陣列失敗
|
|
|
15052 |
if($create["status"]=="false"){
|
| 226 |
liveuser |
15053 |
|
| 3 |
liveuser |
15054 |
#設置執行錯誤
|
|
|
15055 |
$result["status"]="false";
|
| 226 |
liveuser |
15056 |
|
| 3 |
liveuser |
15057 |
#設置執行錯誤訊息
|
|
|
15058 |
$result["error"]=$create;
|
| 226 |
liveuser |
15059 |
|
| 3 |
liveuser |
15060 |
#回傳結果
|
|
|
15061 |
return $result;
|
| 226 |
liveuser |
15062 |
|
| 3 |
liveuser |
15063 |
}#if end
|
|
|
15064 |
|
|
|
15065 |
#取得 $conf["WhereColumnAndOr"] 參數內容
|
|
|
15066 |
$conf["WhereColumnAndOr"]=$create["content"];
|
|
|
15067 |
|
|
|
15068 |
}#if end
|
|
|
15069 |
|
|
|
15070 |
#如果 $conf["WhereColumnOperator"] 存在
|
|
|
15071 |
if(isset($conf["WhereColumnOperator"])){
|
|
|
15072 |
|
|
|
15073 |
#設定其它條件
|
| 226 |
liveuser |
15074 |
$sql=$sql." ".$conf["WhereColumnAndOr"][$i-1]." `".$conf["whereColumn"][$i]. "` ".$conf["WhereColumnOperator"][$i]." '".mysqli_real_escape_string($mysqli,$conf["whereValue"][$i])."'";
|
| 3 |
liveuser |
15075 |
|
| 226 |
liveuser |
15076 |
}#if end
|
| 3 |
liveuser |
15077 |
|
|
|
15078 |
#反之 $conf["WhereColumnOperator"] 不存在
|
|
|
15079 |
else{
|
|
|
15080 |
|
|
|
15081 |
#設定其它條件
|
| 226 |
liveuser |
15082 |
$sql=$sql." ".$conf["WhereColumnAndOr"][$i-1]." `".$conf["whereColumn"][$i]. "` = '".mysqli_real_escape_string($mysqli,$conf["whereValue"][$i])."'";
|
| 3 |
liveuser |
15083 |
|
|
|
15084 |
}#else end
|
|
|
15085 |
|
|
|
15086 |
}#判斷式
|
|
|
15087 |
|
|
|
15088 |
}#迴圈結束
|
|
|
15089 |
|
|
|
15090 |
#sql語法結束
|
| 226 |
liveuser |
15091 |
$sqlString=$sql.";";
|
| 3 |
liveuser |
15092 |
|
|
|
15093 |
#執行sql語法
|
|
|
15094 |
#函式說明:
|
|
|
15095 |
#執行mysql指令
|
|
|
15096 |
#回傳結果::
|
|
|
15097 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
15098 |
#$result["error"],錯誤訊息的陣列
|
|
|
15099 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
15100 |
#$result["queryString"],mysql查詢的語言
|
|
|
15101 |
#查詢號的解果,需要解析。
|
|
|
15102 |
#必填參數:
|
|
|
15103 |
$conf["db"]["execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
15104 |
$conf["db"]["execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
15105 |
$conf["db"]["execMysqlQuery"]["dbSql"]=$sqlString;#要執行sql語法
|
| 226 |
liveuser |
15106 |
#可省略參數:
|
|
|
15107 |
|
| 3 |
liveuser |
15108 |
#如果 $conf["dbPassword"] 有設置
|
|
|
15109 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
15110 |
|
| 3 |
liveuser |
15111 |
$conf["db"]["execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
15112 |
|
| 3 |
liveuser |
15113 |
}#if end
|
| 226 |
liveuser |
15114 |
|
| 3 |
liveuser |
15115 |
#如果 $conf["dbPort"] 有設置
|
|
|
15116 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
15117 |
|
| 3 |
liveuser |
15118 |
$conf["db"]["execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的 3306 port.
|
| 226 |
liveuser |
15119 |
|
| 3 |
liveuser |
15120 |
}#if end
|
| 226 |
liveuser |
15121 |
|
| 3 |
liveuser |
15122 |
#$conf["dbLink"],物件,mysqli物件,由mysqli_connect()回傳的物件內容,若為數值則改用賬號密碼等資訊進行連線,反之則沿用連線物件.
|
|
|
15123 |
$conf["db"]["execMysqlQuery"]["dbLink"]=$mysqli;
|
| 226 |
liveuser |
15124 |
|
| 3 |
liveuser |
15125 |
$db["execMysqlQuery"]=db::execMysqlQuery($conf["db"]["execMysqlQuery"]);
|
|
|
15126 |
unset($conf["db"]["execMysqlQuery"]);
|
|
|
15127 |
|
|
|
15128 |
#如果sql執行有誤
|
|
|
15129 |
if($db["execMysqlQuery"]["status"]=="false"){
|
| 226 |
liveuser |
15130 |
|
| 3 |
liveuser |
15131 |
#設置錯誤識別
|
|
|
15132 |
$result["status"]="false";
|
| 226 |
liveuser |
15133 |
|
| 3 |
liveuser |
15134 |
#設置錯誤訊息
|
|
|
15135 |
$result["error"]=$db["execMysqlQuery"];
|
| 226 |
liveuser |
15136 |
|
| 3 |
liveuser |
15137 |
#回傳結果
|
|
|
15138 |
return $result;
|
| 226 |
liveuser |
15139 |
|
| 3 |
liveuser |
15140 |
}#if end
|
| 226 |
liveuser |
15141 |
|
| 3 |
liveuser |
15142 |
#取得執行的sql語法
|
|
|
15143 |
$result["sql"]=$db["execMysqlQuery"]["queryString"];
|
| 226 |
liveuser |
15144 |
|
| 3 |
liveuser |
15145 |
#執行到這邊表執行成功
|
|
|
15146 |
$result["status"]="true";
|
|
|
15147 |
|
|
|
15148 |
#回傳結果
|
|
|
15149 |
return $result;
|
| 226 |
liveuser |
15150 |
|
| 3 |
liveuser |
15151 |
}#函式結束
|
| 226 |
liveuser |
15152 |
|
| 3 |
liveuser |
15153 |
/*
|
|
|
15154 |
#函式說明:
|
|
|
15155 |
#取得目標資料庫底下所有資料表的索引鍵,可作為foreign key的可用欄位,欄位必須為index key或primary key.
|
|
|
15156 |
#回傳結果::
|
|
|
15157 |
#$result["status"],執行是否成功"true"為執行成功,"false"為執行失敗。
|
|
|
15158 |
#$result["error"],執行的錯誤訊息.
|
|
|
15159 |
#$result["function"],當前執行函式名稱.
|
|
|
15160 |
#$result["content"][$i]["tableName"],欄位所屬的資料表名稱.
|
|
|
15161 |
#$result["content"][$i]["columnKey"],是"primary key"還是"index key".
|
|
|
15162 |
#$result["content"][$i]["columnName"],欄位名稱.
|
|
|
15163 |
#$result["content"][$i]["typeAndLength"],欄位儲存形態與長度限制.
|
|
|
15164 |
#$result["content"][$i]["tableDotColumnName"],欄位的「鍵所屬資料表名稱.鍵欄位名稱」.
|
|
|
15165 |
#$result["content"][$i]["tableDotColumnVarType"],「資料索引鍵所屬資料表名稱.索引鍵欄位名稱 儲存變數型別與長度」.
|
|
|
15166 |
#$result["indexKey"]["tableName"],index key欄位所屬的資料表陣列
|
|
|
15167 |
#$result["indexKey"]["columnName"],index key的欄位名稱陣列
|
|
|
15168 |
#$result["indexKey"]["typeAndLength"],index key的欄位儲存型態與長度限制陣列
|
|
|
15169 |
#$result["indexKey"]["tableDotColumnName"],index key的 「資料索引鍵所屬資料表名稱.索引鍵欄位名稱」 陣列
|
|
|
15170 |
#$result["indexKey"]["tableDotColumnVarType"],index key的 「資料索引鍵所屬資料表名稱.索引鍵欄位名稱 儲存變數型別與長度」 陣列
|
|
|
15171 |
#$result["primaryKey"][$tableCount]["dtName"],主鍵所屬的資料表名稱,若沒有主鍵則為null.
|
|
|
15172 |
#$result["primaryKey"][$tableCount]["columnName"],資料表的主鍵欄位名稱,若沒有主鍵則為null.
|
|
|
15173 |
#$result["primaryKey"][$tableCount]["columnVarType"],資料表的主鍵欄位的儲存形態,若沒有主鍵則為null..
|
|
|
15174 |
#$result["primaryKey"][$tableCount]["columnVarLengthLimit"],資料表的主鍵欄位的儲存長度限制,若沒有主鍵則為null.
|
|
|
15175 |
#$result["primaryKey"][$tableCount]["columnVarTypeAndLengthLimit"],儲存當前資料表的主鍵欄位的儲存形態與長度限制,若沒有主鍵則為null.
|
|
|
15176 |
#必填參數:
|
|
|
15177 |
#$conf["dbAddress"],字串,爲mysql-Server的位置
|
|
|
15178 |
$conf["dbAddress"]=$dbAddress;
|
|
|
15179 |
#$conf["dbAccount"],字串,爲用於連入mysql-Server時要使用的帳號
|
|
|
15180 |
$conf["dbAccount"]=$dbAccount;
|
|
|
15181 |
#$conf["selectedDataBaseName"],字串,爲目標資料表所屬的資料庫
|
|
|
15182 |
$conf["selectedDataBaseName"]="";#
|
|
|
15183 |
#可省略參數:
|
|
|
15184 |
#$conf["dbPassword"],字串,爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
|
|
15185 |
#$conf["dbPassword"]=$dbPassword;#
|
|
|
15186 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
|
|
|
15187 |
#$conf["dbPort"]=$dbPort;
|
|
|
15188 |
#參考資料:
|
|
|
15189 |
#無.
|
|
|
15190 |
#備註:
|
|
|
15191 |
#目前只能取得一個資料庫的所有索引鍵.
|
|
|
15192 |
*/
|
|
|
15193 |
public static function getAllIndexKeyInAllDataBase(&$conf){
|
| 226 |
liveuser |
15194 |
|
| 3 |
liveuser |
15195 |
#初始化要回傳的內容
|
|
|
15196 |
$result=array();
|
|
|
15197 |
|
|
|
15198 |
#取得當前執行的函數名稱
|
|
|
15199 |
$result["function"]=__FUNCTION__;
|
|
|
15200 |
|
|
|
15201 |
#如果 $conf 不為陣列
|
|
|
15202 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
15203 |
|
| 3 |
liveuser |
15204 |
#設置執行失敗
|
|
|
15205 |
$result["status"]="false";
|
| 226 |
liveuser |
15206 |
|
| 3 |
liveuser |
15207 |
#設置執行錯誤訊息
|
|
|
15208 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
15209 |
|
|
|
15210 |
#如果傳入的參數為 null
|
|
|
15211 |
if($conf==null){
|
| 226 |
liveuser |
15212 |
|
| 3 |
liveuser |
15213 |
#設置執行錯誤訊息
|
|
|
15214 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
15215 |
|
| 3 |
liveuser |
15216 |
}#if end
|
|
|
15217 |
|
|
|
15218 |
#回傳結果
|
|
|
15219 |
return $result;
|
| 226 |
liveuser |
15220 |
|
| 3 |
liveuser |
15221 |
}#if end
|
| 226 |
liveuser |
15222 |
|
| 3 |
liveuser |
15223 |
#檢查參數
|
|
|
15224 |
#函式說明:
|
|
|
15225 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
15226 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15227 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
15228 |
#$result["function"],當前執行的函式名稱.
|
|
|
15229 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
15230 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
15231 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
15232 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
15233 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
15234 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
15235 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
15236 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
15237 |
#必填參數:
|
|
|
15238 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
15239 |
$conf["variableCheck::checkArguments"]["varInput"]=&$conf;
|
|
|
15240 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
15241 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","selectedDataBaseName");
|
|
|
15242 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
15243 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string");
|
|
|
15244 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
15245 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
15246 |
#可省略參數:
|
|
|
15247 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
15248 |
#$conf["canBeEmptyString"]="false";
|
|
|
15249 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或集合.
|
|
|
15250 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("dbPassword","dbPort");
|
|
|
15251 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
15252 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort");
|
| 226 |
liveuser |
15253 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
15254 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
15255 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
15256 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array(null,null);
|
|
|
15257 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
15258 |
#$conf["arrayCountEqualCheck"][]=array();
|
|
|
15259 |
#參考資料:
|
|
|
15260 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
15261 |
$checkResult=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
15262 |
unset($conf["variableCheck::checkArguments"]);
|
| 226 |
liveuser |
15263 |
|
| 3 |
liveuser |
15264 |
#如果檢查有誤
|
|
|
15265 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
15266 |
|
| 3 |
liveuser |
15267 |
#設置執行錯誤的識別
|
|
|
15268 |
$result["status"]="false";
|
| 226 |
liveuser |
15269 |
|
| 3 |
liveuser |
15270 |
#設置錯誤訊息
|
|
|
15271 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
15272 |
|
| 3 |
liveuser |
15273 |
#回傳結果
|
|
|
15274 |
return $result;
|
| 226 |
liveuser |
15275 |
|
| 3 |
liveuser |
15276 |
}#if end
|
|
|
15277 |
|
|
|
15278 |
#如果檢查不通過
|
|
|
15279 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
15280 |
|
| 3 |
liveuser |
15281 |
#設置執行錯誤的識別
|
|
|
15282 |
$result["status"]="false";
|
| 226 |
liveuser |
15283 |
|
| 3 |
liveuser |
15284 |
#設置錯誤訊息
|
|
|
15285 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
15286 |
|
| 3 |
liveuser |
15287 |
#回傳結果
|
|
|
15288 |
return $result;
|
| 226 |
liveuser |
15289 |
|
| 3 |
liveuser |
15290 |
}#if end
|
| 226 |
liveuser |
15291 |
|
| 3 |
liveuser |
15292 |
#取得資料表列表
|
|
|
15293 |
#查詢特定資料庫裡的資料表列表,會回傳查詢的結果
|
|
|
15294 |
#$result["connectStatus"],若成功則爲0,失敗則爲1。
|
|
|
15295 |
#$result["connectInformation"],爲回傳的mysql連線資訊。
|
|
|
15296 |
#$result["tableName"] 爲查詢的資料庫名稱陣列,
|
|
|
15297 |
#第一筆資料庫名稱爲$result["tableName"][0],
|
|
|
15298 |
#第二筆資料庫名稱爲$result["tableName"][1],
|
|
|
15299 |
#其餘以此類推。
|
|
|
15300 |
#$result["dataCounts"] 爲資料庫的總筆數
|
|
|
15301 |
#必填參數:
|
|
|
15302 |
$conf["db"]["getDataTableList"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
15303 |
$conf["db"]["getDataTableList"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
15304 |
$conf["db"]["getDataTableList"]["selectedDataBaseName"]=$conf["selectedDataBaseName"];#爲指定的資料庫名稱
|
|
|
15305 |
#可省略參數:
|
| 226 |
liveuser |
15306 |
|
| 3 |
liveuser |
15307 |
#如果有設定 $conf["dbPassword"]
|
|
|
15308 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
15309 |
|
| 3 |
liveuser |
15310 |
#則套用設定
|
|
|
15311 |
$conf["db"]["getDataTableList"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
15312 |
|
| 3 |
liveuser |
15313 |
}#if end
|
| 226 |
liveuser |
15314 |
|
| 3 |
liveuser |
15315 |
#如果有設定 $conf["dbPort"]
|
|
|
15316 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
15317 |
|
| 3 |
liveuser |
15318 |
#則套用設定
|
|
|
15319 |
$conf["db"]["getDataTableList"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,預設為3306.
|
| 226 |
liveuser |
15320 |
|
| 3 |
liveuser |
15321 |
}#if end
|
| 226 |
liveuser |
15322 |
|
| 3 |
liveuser |
15323 |
#原始語法:
|
|
|
15324 |
#show tables FROM databaseName,代表檢視databaseName裡面的資料表清單。
|
|
|
15325 |
$tableList=db::getDataTableList($conf["db"]["getDataTableList"]);
|
|
|
15326 |
unset($conf["db"]);
|
| 226 |
liveuser |
15327 |
|
| 3 |
liveuser |
15328 |
#debug
|
|
|
15329 |
#var_dump($tableList);
|
| 226 |
liveuser |
15330 |
|
| 3 |
liveuser |
15331 |
#如果 資料表清單 取得失敗
|
|
|
15332 |
if($tableList["status"]=="false"){
|
| 226 |
liveuser |
15333 |
|
| 3 |
liveuser |
15334 |
#設置執行錯誤的識別
|
|
|
15335 |
$result["status"]="fasle";
|
| 226 |
liveuser |
15336 |
|
| 3 |
liveuser |
15337 |
#設置錯誤訊息
|
|
|
15338 |
$result["error"]="取得資料表清單失敗";
|
| 226 |
liveuser |
15339 |
|
| 3 |
liveuser |
15340 |
#回傳結果
|
|
|
15341 |
return $result;
|
| 226 |
liveuser |
15342 |
|
| 3 |
liveuser |
15343 |
}#if end
|
| 226 |
liveuser |
15344 |
|
| 3 |
liveuser |
15345 |
#初始化資料表的計數變數
|
|
|
15346 |
$tableCount=0;
|
| 226 |
liveuser |
15347 |
|
| 3 |
liveuser |
15348 |
#初始化儲存 index key
|
|
|
15349 |
$result["indexKey"]=array();
|
|
|
15350 |
|
| 226 |
liveuser |
15351 |
#初始化儲存index key所屬的表格
|
| 3 |
liveuser |
15352 |
$result["indexKey"]["tableName"]=array();
|
|
|
15353 |
|
|
|
15354 |
#根據每個資料表
|
|
|
15355 |
foreach($tableList["tableName"] as $tableName){
|
| 226 |
liveuser |
15356 |
|
| 3 |
liveuser |
15357 |
#取得該資料表的欄位資訊
|
|
|
15358 |
#函式說明:
|
|
|
15359 |
#取得資料表所有欄位的詳細資訊
|
|
|
15360 |
#回傳的內容:
|
|
|
15361 |
#$result["status"],執行結果,"true"代表執行成功;"false"代表執行失敗
|
|
|
15362 |
#$result["error"],錯誤訊息陣列
|
|
|
15363 |
#$result["sql"],執行的sql語法
|
|
|
15364 |
#$result["oriInput"],原始的資料表欄位資訊
|
|
|
15365 |
#$result["everyLine"],逐行的欄位資訊
|
|
|
15366 |
#$result["tableName"],當前查詢的資料表名稱
|
|
|
15367 |
#$result["engine"],資料表使用的儲存引擎
|
|
|
15368 |
#$result["charset"],資料表預設的編碼
|
|
|
15369 |
#$result["columnName"][$i],各欄位的名稱陣列,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
15370 |
#$result["columnVarTypeAndLengthLimit"][$i],各欄位儲存的變數形態與長度限制,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
15371 |
#$result["columnVarType"][$i],各欄位變數儲存的型態,$i爲1開始的數字,也可以使用欄位的名稱.
|
|
|
15372 |
#$result["columnVarLengthLimit"][$i],個欄位變數的長度限制,若不存在其限制,則為"",$i爲1開始的數字,也可以使用欄位的名稱.
|
|
|
15373 |
#$result["columnNotNull"][$i],各欄位是否可以不爲null,"true"爲可以不爲null;"false"爲可以爲"null",$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
15374 |
#$result["columnAutoIncrement"][$i],各欄位是否會自動加1,"true"爲會;"false"爲不會,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
15375 |
#$result["columnDefault"][$i],各欄位的預設內容,若無則爲"沒有指定",$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
15376 |
#$result["columnOnUpdateAction"][$i],當資料有修改時,該欄位的內容要怎麼因應,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
15377 |
#$result["columnCharacterSet"][$i],各欄位使用的CharacterSet,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
15378 |
#$result["columnCollate"][$i],各欄位使用的Collate,$i爲0開始的數字,也可以使用欄位的名稱。
|
|
|
15379 |
#$result["key"]["exist"],該資料表是否有索引鍵,"true"代表有;"false"代表沒有。
|
|
|
15380 |
#$result["key"][$j],該資料表的索引鍵陣列,$j爲0開始的數字,也可以使用欄位的名稱。
|
|
|
15381 |
#$result["keyConstraintName"][$j],該資料表用於識別索引鍵的CONSTRAINT名稱陣列,$j爲0開始的數字,也可以使用欄位的名稱。
|
|
|
15382 |
#$result["primaryKey"],該資料表的主鍵
|
|
|
15383 |
#$result["foreignKey"]["exist"],該資料表是否有foreign key,"true"代表有;"fasle"代表沒有。
|
|
|
15384 |
#$result["foreignKey"]["constraintName"][$k],用來識別外鍵的CONSTRAINT名稱陣列,$k爲0開始的數字,也可以使用欄位的名稱。
|
|
|
15385 |
#$result["foreignKey"]["columnName"][$k],外鍵的名稱陣列,$k爲0開始的數字,也可以使用欄位的名稱。
|
|
|
15386 |
#$result["foreignKey"]["referencesTable"][$k],外鍵參照的欄位,$k爲0開始的數字
|
|
|
15387 |
#$result["foreignKey"]["referencesColumn"][$k],外鍵參照的欄位屬於哪個資料表,$k爲0開始的數字
|
|
|
15388 |
#$result["foreignKey"]["OnUpdateAction"][$l],當參照的欄位資料更新時,會怎麼同步,$l爲0開始的數字
|
|
|
15389 |
#$result["foreignKey"]["OnDeleteAction"][$m],當參照的欄位資料移除時,會怎麼同步,$m爲0開始的數字
|
|
|
15390 |
#必填參數:
|
|
|
15391 |
$conf["db"]["getTableColumnDetailInfo"]["dbAddress"]=$conf["dbAddress"];#資料庫的網路位置
|
|
|
15392 |
$conf["db"]["getTableColumnDetailInfo"]["dbAccount"]=$conf["dbAccount"];#連線到資料庫要用的帳號
|
|
|
15393 |
$conf["db"]["getTableColumnDetailInfo"]["selectedDataBase"]=$conf["selectedDataBaseName"];#連線到資料庫要選擇的資料庫
|
|
|
15394 |
$conf["db"]["getTableColumnDetailInfo"]["selectedDataTable"]=$tableName;#連線到資料庫要檢視的資料表
|
|
|
15395 |
#可省略參數:
|
| 226 |
liveuser |
15396 |
|
| 3 |
liveuser |
15397 |
#如果有設定 $conf["dbPassword"]
|
|
|
15398 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
15399 |
|
| 3 |
liveuser |
15400 |
#則套用設定
|
|
|
15401 |
$conf["db"]["getTableColumnDetailInfo"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
15402 |
|
| 3 |
liveuser |
15403 |
}#if end
|
| 226 |
liveuser |
15404 |
|
| 3 |
liveuser |
15405 |
#如果有設定 $conf["dbPort"]
|
|
|
15406 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
15407 |
|
| 3 |
liveuser |
15408 |
#則套用設定
|
|
|
15409 |
$conf["db"]["getTableColumnDetailInfo"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,預設為3306.
|
| 226 |
liveuser |
15410 |
|
| 3 |
liveuser |
15411 |
}#if end
|
| 226 |
liveuser |
15412 |
|
| 3 |
liveuser |
15413 |
$columnData=db::getTableColumnDetailInfo($conf["db"]["getTableColumnDetailInfo"]);
|
|
|
15414 |
unset($conf["db"]["getTableColumnDetailInfo"]);
|
| 226 |
liveuser |
15415 |
|
| 3 |
liveuser |
15416 |
#如果取得資料表結構詳細資訊失敗
|
|
|
15417 |
if($columnData["status"]=="false"){
|
| 226 |
liveuser |
15418 |
|
| 3 |
liveuser |
15419 |
#設置執行錯誤的識別
|
|
|
15420 |
$result["status"]="fasle";
|
| 226 |
liveuser |
15421 |
|
| 3 |
liveuser |
15422 |
#設置錯誤訊息
|
|
|
15423 |
$result["error"]=$columnData;
|
| 226 |
liveuser |
15424 |
|
| 3 |
liveuser |
15425 |
#回傳結果
|
|
|
15426 |
return $result;
|
| 226 |
liveuser |
15427 |
|
| 3 |
liveuser |
15428 |
}#if end
|
| 226 |
liveuser |
15429 |
|
| 3 |
liveuser |
15430 |
#儲存當前資料表的主鍵所屬資料表名稱
|
|
|
15431 |
$result["primaryKey"][$tableCount]["dtName"]=$tableName;
|
| 226 |
liveuser |
15432 |
|
| 3 |
liveuser |
15433 |
#如果該資料表沒有主鍵
|
|
|
15434 |
if(!isset($columnData["primaryKey"])){
|
| 226 |
liveuser |
15435 |
|
| 3 |
liveuser |
15436 |
#將數值設為null
|
| 226 |
liveuser |
15437 |
|
| 3 |
liveuser |
15438 |
#儲存當前資料表的主鍵欄位名稱
|
|
|
15439 |
$result["primaryKey"][$tableCount]["columnName"]=null;
|
| 226 |
liveuser |
15440 |
|
| 3 |
liveuser |
15441 |
#儲存當前資料表的主鍵欄位的儲存形態
|
|
|
15442 |
$result["primaryKey"][$tableCount]["columnVarType"]=null;
|
| 226 |
liveuser |
15443 |
|
| 3 |
liveuser |
15444 |
#儲存當前資料表的主鍵欄位的儲存長度限制
|
|
|
15445 |
$result["primaryKey"][$tableCount]["columnVarLengthLimit"]=null;
|
| 226 |
liveuser |
15446 |
|
| 3 |
liveuser |
15447 |
#儲存當前資料表的主鍵欄位的儲存形態與長度限制
|
|
|
15448 |
$result["primaryKey"][$tableCount]["columnVarTypeAndLengthLimit"]=null;
|
| 226 |
liveuser |
15449 |
|
| 3 |
liveuser |
15450 |
}#if end
|
| 226 |
liveuser |
15451 |
|
| 3 |
liveuser |
15452 |
#反之有主鍵
|
|
|
15453 |
else{
|
| 226 |
liveuser |
15454 |
|
| 3 |
liveuser |
15455 |
#儲存當前資料表的主鍵欄位名稱
|
|
|
15456 |
$result["primaryKey"][$tableCount]["columnName"]=$columnData["primaryKey"];
|
| 226 |
liveuser |
15457 |
|
| 3 |
liveuser |
15458 |
#儲存當前資料表的主鍵欄位的儲存形態
|
|
|
15459 |
$result["primaryKey"][$tableCount]["columnVarType"]=$columnData["columnVarType"][$columnData["primaryKey"]];
|
| 226 |
liveuser |
15460 |
|
| 3 |
liveuser |
15461 |
#儲存當前資料表的主鍵欄位的儲存長度限制
|
|
|
15462 |
$result["primaryKey"][$tableCount]["columnVarLengthLimit"]=$columnData["columnVarLengthLimit"][$columnData["primaryKey"]];
|
| 226 |
liveuser |
15463 |
|
| 3 |
liveuser |
15464 |
#儲存當前資料表的主鍵欄位的儲存形態與長度限制
|
|
|
15465 |
$result["primaryKey"][$tableCount]["columnVarTypeAndLengthLimit"]=$columnData["columnVarTypeAndLengthLimit"][$columnData["primaryKey"]];
|
| 226 |
liveuser |
15466 |
|
| 3 |
liveuser |
15467 |
}#else end
|
| 226 |
liveuser |
15468 |
|
| 3 |
liveuser |
15469 |
#資料表計數加1
|
| 226 |
liveuser |
15470 |
$tableCount++;
|
|
|
15471 |
|
| 3 |
liveuser |
15472 |
#如果有index key
|
|
|
15473 |
if($columnData["key"]["exist"]=="true"){
|
| 226 |
liveuser |
15474 |
|
| 3 |
liveuser |
15475 |
#依據每個index key
|
|
|
15476 |
for($i=0;$i<count($columnData["key"]);$i++){
|
| 226 |
liveuser |
15477 |
|
| 3 |
liveuser |
15478 |
#如果該元素不存在
|
|
|
15479 |
if(!isset($columnData["key"][$i])){
|
| 226 |
liveuser |
15480 |
|
| 3 |
liveuser |
15481 |
#中斷迴圈
|
|
|
15482 |
break;
|
| 226 |
liveuser |
15483 |
|
| 3 |
liveuser |
15484 |
}#if end
|
| 226 |
liveuser |
15485 |
|
| 3 |
liveuser |
15486 |
#取得其index key欄位
|
|
|
15487 |
$tempColumnName=$result["indexKey"]["columnName"][]=$columnData["key"][$i];
|
| 226 |
liveuser |
15488 |
|
| 3 |
liveuser |
15489 |
#如果 $columnData["columnVarTypeAndLengthLimit"][$i] 有設置
|
|
|
15490 |
if(isset($columnData["columnVarTypeAndLengthLimit"][$tempColumnName])){
|
| 226 |
liveuser |
15491 |
|
| 3 |
liveuser |
15492 |
#取得該欄位的儲存變數型別與長度限制
|
|
|
15493 |
$result["indexKey"]["typeAndLength"][]=$columnData["columnVarTypeAndLengthLimit"][$tempColumnName];
|
| 226 |
liveuser |
15494 |
|
| 3 |
liveuser |
15495 |
}#if end
|
| 226 |
liveuser |
15496 |
|
| 3 |
liveuser |
15497 |
#反之
|
|
|
15498 |
else{
|
| 226 |
liveuser |
15499 |
|
| 3 |
liveuser |
15500 |
#將 得該欄位的儲存變數型別與長度限制 設為 ""
|
|
|
15501 |
$result["indexKey"]["typeAndLength"][]="";
|
| 226 |
liveuser |
15502 |
|
|
|
15503 |
}#else end
|
|
|
15504 |
|
| 3 |
liveuser |
15505 |
#取得其index key的所屬資料表
|
|
|
15506 |
$result["indexKey"]["tableName"][]=$tableName;
|
| 226 |
liveuser |
15507 |
|
| 3 |
liveuser |
15508 |
}#for end
|
| 226 |
liveuser |
15509 |
|
| 3 |
liveuser |
15510 |
}#if end
|
| 226 |
liveuser |
15511 |
|
| 3 |
liveuser |
15512 |
}#foreach end
|
| 226 |
liveuser |
15513 |
|
| 3 |
liveuser |
15514 |
#根據每個索引鍵欄位與其所屬的資料表來建立 「索引鍵所屬資料表名稱.索引鍵欄位名稱 儲存變數型別與長度」 格式的陣列
|
|
|
15515 |
for($i=0;$i<count($result["indexKey"]["tableName"]);$i++){
|
| 226 |
liveuser |
15516 |
|
| 3 |
liveuser |
15517 |
#設置 索引鍵所屬資料表名稱.索引鍵欄位名稱 格式的陣列
|
|
|
15518 |
$result["indexKey"]["tableDotColumnName"][]=$result["indexKey"]["tableName"][$i].".".$result["indexKey"]["columnName"][$i];
|
| 226 |
liveuser |
15519 |
|
| 3 |
liveuser |
15520 |
#設置 索引鍵所屬資料表名稱.索引鍵欄位名稱 欄位儲存型態與長度限制 格式的陣列
|
|
|
15521 |
$result["indexKey"]["tableDotColumnVarType"][]=$result["indexKey"]["tableName"][$i].".".$result["indexKey"]["columnName"][$i]." ".$result["indexKey"]["typeAndLength"][$i];
|
| 226 |
liveuser |
15522 |
|
| 3 |
liveuser |
15523 |
}#for end
|
| 226 |
liveuser |
15524 |
|
| 3 |
liveuser |
15525 |
#組裝主鍵與索引鍵的資訊
|
|
|
15526 |
#$result["content"][$i]["tableName"],欄位所屬的資料表名稱.
|
|
|
15527 |
#$result["content"][$i]["columnKey"],是"primary key"還是"index key".
|
|
|
15528 |
#$result["content"][$i]["columnName"],欄位名稱.
|
|
|
15529 |
#$result["content"][$i]["typeAndLength"],欄位儲存形態與長度限制.
|
|
|
15530 |
#$result["content"][$i]["tableDotColumnName"],欄位的「鍵所屬資料表名稱.鍵欄位名稱」.
|
|
|
15531 |
#$result["content"][$i]["tableDotColumnVarType"],「資料索引鍵所屬資料表名稱.索引鍵欄位名稱 儲存變數型別與長度」.
|
|
|
15532 |
#$result["indexKey"]["tableName"],index key欄位所屬的資料表陣列
|
|
|
15533 |
#$result["indexKey"]["columnName"],index key的欄位名稱陣列
|
|
|
15534 |
#$result["indexKey"]["typeAndLength"],index key的欄位儲存型態與長度限制陣列
|
|
|
15535 |
#$result["indexKey"]["tableDotColumnName"],index key的 「資料索引鍵所屬資料表名稱.索引鍵欄位名稱」 陣列
|
|
|
15536 |
#$result["indexKey"]["tableDotColumnVarType"],index key的 「資料索引鍵所屬資料表名稱.索引鍵欄位名稱 儲存變數型別與長度」 陣列
|
|
|
15537 |
#$result["primaryKey"][$tableCount]["dtName"],主鍵所屬的資料表名稱,若沒有主鍵則為null.
|
|
|
15538 |
#$result["primaryKey"][$tableCount]["columnName"],資料表的主鍵欄位名稱,若沒有主鍵則為null.
|
|
|
15539 |
#$result["primaryKey"][$tableCount]["columnVarType"],資料表的主鍵欄位的儲存形態,若沒有主鍵則為null..
|
|
|
15540 |
#$result["primaryKey"][$tableCount]["columnVarLengthLimit"],資料表的主鍵欄位的儲存長度限制,若沒有主鍵則為null.
|
|
|
15541 |
#$result["primaryKey"][$tableCount]["columnVarTypeAndLengthLimit"],儲存當前資料表的主鍵欄位的儲存形態與長度限制,若沒有主鍵則為null.
|
| 226 |
liveuser |
15542 |
|
| 3 |
liveuser |
15543 |
#能夠被外鍵參照的欄位計數
|
|
|
15544 |
$referenceColumnCount=0;
|
| 226 |
liveuser |
15545 |
|
| 3 |
liveuser |
15546 |
#有幾個主鍵就執行幾次
|
|
|
15547 |
for($i=0;$i<count($result["primaryKey"]);$i++){
|
| 226 |
liveuser |
15548 |
|
| 3 |
liveuser |
15549 |
#暫存當前資料表的名稱
|
|
|
15550 |
$dtName=$result["primaryKey"][$i]["dtName"];
|
| 226 |
liveuser |
15551 |
|
| 3 |
liveuser |
15552 |
#如果主鍵欄位名稱不為 null,亦即有主鍵
|
|
|
15553 |
if($result["primaryKey"][$i]["columnName"]!=null){
|
| 226 |
liveuser |
15554 |
|
| 3 |
liveuser |
15555 |
#儲存欄位所屬的資料表名稱.
|
|
|
15556 |
$result["content"][$referenceColumnCount]["tableName"]=$dtName;
|
| 226 |
liveuser |
15557 |
|
| 3 |
liveuser |
15558 |
#儲存是"primary key"還是"index key".
|
|
|
15559 |
$result["content"][$referenceColumnCount]["columnKey"]="primary key";
|
| 226 |
liveuser |
15560 |
|
| 3 |
liveuser |
15561 |
#儲存欄位名稱
|
|
|
15562 |
$result["content"][$referenceColumnCount]["columnName"]=$result["primaryKey"][$i]["columnName"];
|
| 226 |
liveuser |
15563 |
|
| 3 |
liveuser |
15564 |
#儲存欄位儲存形態與長度限制.
|
|
|
15565 |
$result["content"][$referenceColumnCount]["typeAndLength"]=$result["primaryKey"][$i]["columnVarLengthLimit"];
|
| 226 |
liveuser |
15566 |
|
| 3 |
liveuser |
15567 |
#儲存欄位的「鍵所屬資料表名稱.鍵欄位名稱」.
|
|
|
15568 |
$result["content"][$referenceColumnCount]["tableDotColumnName"]=$dtName.".".$result["primaryKey"][$i]["columnName"];
|
| 226 |
liveuser |
15569 |
|
| 3 |
liveuser |
15570 |
#儲存欄位的「資料索引鍵所屬資料表名稱.索引鍵欄位名稱 儲存變數型別與長度」.
|
|
|
15571 |
$result["content"][$referenceColumnCount]["tableDotColumnVarType"]=$dtName.".".$result["primaryKey"][$i]["columnName"]." ".$result["primaryKey"][$i]["columnVarTypeAndLengthLimit"];
|
| 226 |
liveuser |
15572 |
|
| 3 |
liveuser |
15573 |
#能夠被外鍵參照的欄位計數加1
|
| 226 |
liveuser |
15574 |
$referenceColumnCount++;
|
|
|
15575 |
|
| 3 |
liveuser |
15576 |
}#if end
|
| 226 |
liveuser |
15577 |
|
| 3 |
liveuser |
15578 |
#用當前資料表的名稱取得索引鍵的資訊
|
| 226 |
liveuser |
15579 |
|
| 3 |
liveuser |
15580 |
#所有資料表有幾個索引鍵就執行幾次
|
|
|
15581 |
for($j=0;$j<count($result["indexKey"]["tableName"]);$j++){
|
| 226 |
liveuser |
15582 |
|
| 3 |
liveuser |
15583 |
#如果是當前資料表的索引鍵
|
|
|
15584 |
if($result["indexKey"]["tableName"][$j]==$dtName){
|
| 226 |
liveuser |
15585 |
|
| 3 |
liveuser |
15586 |
#儲存欄位所屬的資料表名稱.
|
|
|
15587 |
$result["content"][$referenceColumnCount]["tableName"]=$dtName;
|
| 226 |
liveuser |
15588 |
|
| 3 |
liveuser |
15589 |
#儲存是"primary key"還是"index key".
|
|
|
15590 |
$result["content"][$referenceColumnCount]["columnKey"]="index key";
|
| 226 |
liveuser |
15591 |
|
| 3 |
liveuser |
15592 |
#儲存欄位名稱
|
|
|
15593 |
$result["content"][$referenceColumnCount]["columnName"]=$result["indexKey"]["columnName"][$j];
|
| 226 |
liveuser |
15594 |
|
| 3 |
liveuser |
15595 |
#儲存欄位儲存形態與長度限制.
|
|
|
15596 |
$result["content"][$referenceColumnCount]["typeAndLength"]=$result["indexKey"]["typeAndLength"][$j];
|
| 226 |
liveuser |
15597 |
|
| 3 |
liveuser |
15598 |
#儲存欄位的「鍵所屬資料表名稱.鍵欄位名稱」.
|
|
|
15599 |
$result["content"][$referenceColumnCount]["tableDotColumnName"]=$result["indexKey"]["tableDotColumnName"][$j];
|
| 226 |
liveuser |
15600 |
|
| 3 |
liveuser |
15601 |
#儲存欄位的「資料索引鍵所屬資料表名稱.索引鍵欄位名稱 儲存變數型別與長度」.
|
|
|
15602 |
$result["content"][$referenceColumnCount]["tableDotColumnVarType"]=$result["indexKey"]["tableDotColumnVarType"][$j];
|
| 226 |
liveuser |
15603 |
|
| 3 |
liveuser |
15604 |
#能夠被外鍵參照的欄位計數加1
|
| 226 |
liveuser |
15605 |
$referenceColumnCount++;
|
|
|
15606 |
|
| 3 |
liveuser |
15607 |
}#if end
|
| 226 |
liveuser |
15608 |
|
| 3 |
liveuser |
15609 |
}#for end
|
| 226 |
liveuser |
15610 |
|
| 3 |
liveuser |
15611 |
}#for end
|
| 226 |
liveuser |
15612 |
|
| 3 |
liveuser |
15613 |
#執行到這邊代表執行成功
|
|
|
15614 |
$result["status"]="true";
|
| 226 |
liveuser |
15615 |
|
| 3 |
liveuser |
15616 |
#回傳結果
|
|
|
15617 |
return $result;
|
|
|
15618 |
|
| 226 |
liveuser |
15619 |
}#function getAllIndexKeyInAllDataBase end
|
|
|
15620 |
|
| 3 |
liveuser |
15621 |
/*
|
|
|
15622 |
#函式說明:
|
|
|
15623 |
#將資料表輸出成csv檔案
|
|
|
15624 |
#回傳結果:
|
|
|
15625 |
#$result["status"],執行是否正常,"true"代表執行正常,"false"代表執行失敗.
|
|
|
15626 |
#$result["error"],錯誤訊息
|
|
|
15627 |
#$result["function"],當前執行的涵式
|
|
|
15628 |
#$result["csvFile"],輸出的csv檔案位置與名稱.
|
|
|
15629 |
#必填參數:
|
|
|
15630 |
#$conf["dbAddress"],字串,欲連線的mariadb/mysql伺服器IP/domainName位置.
|
|
|
15631 |
$conf["dbAddress"]=$dbAddress;
|
|
|
15632 |
#$conf["dbAccount"],字串,連線到mariadb/mysql所用的帳戶.
|
|
|
15633 |
$conf["dbAccount"]=$dbAccount;
|
|
|
15634 |
#$conf["dbName"],字串,目標資料表位於哪個資庫底下.
|
|
|
15635 |
$conf["dbName"]=$dbName;
|
|
|
15636 |
#$conf["dtName"],字串,目標資料表的名稱.
|
|
|
15637 |
$conf["dtName"]="";
|
|
|
15638 |
#可省略參數:
|
|
|
15639 |
#$conf["dbPassword"],字串,連線到mariadb/mysql伺服器時所使用的密碼,若未設置則代表不使用密碼來連線.
|
|
|
15640 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
15641 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
|
|
|
15642 |
#$conf["dbPort"]=$dbPort;
|
| 226 |
liveuser |
15643 |
#$conf["column"],陣列,要的欄位名稱,預設為「array(*)」代表所有欄位都要,
|
| 3 |
liveuser |
15644 |
#$conf["column"]=array("*");
|
|
|
15645 |
#$conf["WhereColumnName"],陣列,篩選用的特定欄位
|
|
|
15646 |
#$conf["WhereColumnName"]=array("");
|
|
|
15647 |
#$conf["WhereColumnValue"],陣列,篩選用特定欄位的數值要等於多少才是我們要的.
|
|
|
15648 |
#$conf["WhereColumnValue"]=array("");
|
|
|
15649 |
#$conf["groupBy"],陣列,爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆).
|
|
|
15650 |
#$conf["groupBy"]=array("");
|
|
|
15651 |
#$conf["orderItem"],字串,爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
|
|
15652 |
#$conf["orderItem"]="";#
|
|
|
15653 |
#$conf["ascORdesc"],字串,爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
|
|
15654 |
#$conf["ascORdesc"]="asc";
|
|
|
15655 |
#$conf["outPutPathAndName"],字串,輸出的csv檔案要存放在哪裡.
|
|
|
15656 |
#$conf["outPutPathAndName"]="";
|
|
|
15657 |
#$conf["noDownload"],字串,如果爲"true"則代表不要讓使用者下載,但會回傳檔案的相對位置
|
|
|
15658 |
#$conf["noDownload"]="true";
|
|
|
15659 |
#參考資料:
|
|
|
15660 |
#無.
|
|
|
15661 |
#備註:
|
|
|
15662 |
#無.
|
|
|
15663 |
*/
|
|
|
15664 |
public static function exportTableToCsv($conf){
|
| 226 |
liveuser |
15665 |
|
| 3 |
liveuser |
15666 |
#初始化要回傳的內容
|
|
|
15667 |
$result=array();
|
|
|
15668 |
|
|
|
15669 |
#取得當前執行的函數名稱
|
|
|
15670 |
$result["function"]=__FUNCTION__;
|
|
|
15671 |
|
|
|
15672 |
#如果 $conf 不為陣列
|
|
|
15673 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
15674 |
|
| 3 |
liveuser |
15675 |
#設置執行失敗
|
|
|
15676 |
$result["status"]="false";
|
| 226 |
liveuser |
15677 |
|
| 3 |
liveuser |
15678 |
#設置執行錯誤訊息
|
|
|
15679 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
15680 |
|
|
|
15681 |
#如果傳入的參數為 null
|
|
|
15682 |
if($conf==null){
|
| 226 |
liveuser |
15683 |
|
| 3 |
liveuser |
15684 |
#設置執行錯誤訊息
|
|
|
15685 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
15686 |
|
| 3 |
liveuser |
15687 |
}#if end
|
|
|
15688 |
|
|
|
15689 |
#回傳結果
|
|
|
15690 |
return $result;
|
| 226 |
liveuser |
15691 |
|
| 3 |
liveuser |
15692 |
}#if end
|
| 226 |
liveuser |
15693 |
|
| 3 |
liveuser |
15694 |
#檢查參數
|
|
|
15695 |
#函式說明:
|
|
|
15696 |
#檢查陣列裡面的特定元素是否存在以及其變數型態是否正確,如果沒有設定則回傳提示訊息。
|
|
|
15697 |
#回傳結果:
|
|
|
15698 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15699 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
15700 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
15701 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
15702 |
#必填參數:
|
|
|
15703 |
$conf["db"]["isexistMuti"]["varInput"]=$conf;#要檢查的陣列變數
|
|
|
15704 |
$conf["db"]["isexistMuti"]["variableCheck"]=array("dbAddress","dbAccount","dbName","dtName");#要檢查的變數名稱陣列,形態爲陣列變數,例如: $conf["variableCheck"] = array("id","account","password");
|
|
|
15705 |
#可省略參數:
|
| 226 |
liveuser |
15706 |
$conf["db"]["isexistMuti"]["variableType"]=array("string","string","string","string");#要檢查的陣列變數內的元素應該爲何種變數形態,形態爲陣列 例如: $conf[variableType] = array("string","int","double");
|
| 3 |
liveuser |
15707 |
$conf["db"]["isexistMuti"]["canBeEmptyString"]="false";#變數內容如果是空字串就不能算是有設置的話,請設為"false",預設為也算是有設置。
|
|
|
15708 |
$checkResult=variableCheck::isexistMulti($conf["db"]["isexistMuti"]);
|
|
|
15709 |
unset($conf["db"]["isexistMuti"]);
|
| 226 |
liveuser |
15710 |
|
| 3 |
liveuser |
15711 |
#如果 $checkResult["status"] 等於 "false"
|
|
|
15712 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
15713 |
|
| 3 |
liveuser |
15714 |
#設置錯誤識別
|
|
|
15715 |
$result["status"]="false";
|
| 226 |
liveuser |
15716 |
|
| 3 |
liveuser |
15717 |
#設置錯誤訊息
|
|
|
15718 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
15719 |
|
| 3 |
liveuser |
15720 |
#回傳結果
|
|
|
15721 |
return $result;
|
| 226 |
liveuser |
15722 |
|
| 3 |
liveuser |
15723 |
}#if end
|
| 226 |
liveuser |
15724 |
|
| 3 |
liveuser |
15725 |
#如果 $checkResult["passed"] 等於 "false"
|
|
|
15726 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
15727 |
|
| 3 |
liveuser |
15728 |
#設置錯誤識別
|
|
|
15729 |
$result["status"]="false";
|
| 226 |
liveuser |
15730 |
|
| 3 |
liveuser |
15731 |
#設置錯誤訊息
|
|
|
15732 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
15733 |
|
| 3 |
liveuser |
15734 |
#回傳結果
|
|
|
15735 |
return $result;
|
| 226 |
liveuser |
15736 |
|
| 3 |
liveuser |
15737 |
}#if end
|
| 226 |
liveuser |
15738 |
|
| 3 |
liveuser |
15739 |
#如果 $conf["column"] 沒有設置
|
|
|
15740 |
if(!isset($conf["column"])){
|
| 226 |
liveuser |
15741 |
|
| 3 |
liveuser |
15742 |
#則代表要全部的欄位
|
|
|
15743 |
$conf["column"]=array("*");
|
| 226 |
liveuser |
15744 |
|
| 3 |
liveuser |
15745 |
}#if end
|
| 226 |
liveuser |
15746 |
|
| 3 |
liveuser |
15747 |
#抓取資料表資料
|
|
|
15748 |
#函式說明:
|
|
|
15749 |
#一次取得資料庫、表的資料
|
|
|
15750 |
#回傳結果:
|
|
|
15751 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
15752 |
#$result["error"],錯誤訊息陣列。
|
|
|
15753 |
#$result["dataColumnName"],抓取的資料欄位名稱陣列.
|
|
|
15754 |
#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
|
|
|
15755 |
#$result["dataContent"],爲資料的內容。
|
|
|
15756 |
#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
15757 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
15758 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
15759 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
15760 |
#$result["sql"],執行的sql字串.
|
|
|
15761 |
#必填參數:
|
|
|
15762 |
$conf["db"]["fastGetDbData"]["dbAddress"]=$conf["dbAddress"];#爲dbServer的位置。
|
|
|
15763 |
$conf["db"]["fastGetDbData"]["dbAccount"]=$conf["dbAccount"];#爲登入dbServer的帳號。
|
|
|
15764 |
$conf["db"]["fastGetDbData"]["dbName"]=$conf["dbName"];#爲要存取的資料庫名稱
|
|
|
15765 |
$conf["db"]["fastGetDbData"]["tableName"]=$conf["dtName"];#爲要存取的資料表名稱
|
|
|
15766 |
$conf["db"]["fastGetDbData"]["columnYouWant"]=$conf["column"];#你想要的欄位!
|
|
|
15767 |
#可省略參數:
|
| 226 |
liveuser |
15768 |
|
|
|
15769 |
#如果 $conf["dbPassword"] 有設置
|
| 3 |
liveuser |
15770 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
15771 |
|
| 3 |
liveuser |
15772 |
#則設定進行連線密碼
|
|
|
15773 |
$conf["db"]["fastGetDbData"]["dbPassword"]=$conf["dbPassword"];#爲要存取dbServer的密碼
|
| 226 |
liveuser |
15774 |
|
| 3 |
liveuser |
15775 |
}#if end
|
| 226 |
liveuser |
15776 |
|
|
|
15777 |
#如果 $conf["dbPort"] 有設置
|
| 3 |
liveuser |
15778 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
15779 |
|
| 3 |
liveuser |
15780 |
#則設定進行連線的 port
|
|
|
15781 |
$conf["db"]["fastGetDbData"]["dbPort"]=$conf["dbPort"];#爲要存取dbServer的port
|
| 226 |
liveuser |
15782 |
|
| 3 |
liveuser |
15783 |
}#if end
|
| 226 |
liveuser |
15784 |
|
| 3 |
liveuser |
15785 |
#如果 $conf["WhereColumnName"] 有設置
|
|
|
15786 |
if(isset($conf["WhereColumnName"])){
|
| 226 |
liveuser |
15787 |
|
| 3 |
liveuser |
15788 |
$conf["db"]["fastGetDbData"]["WhereColumnName"]=$conf["WhereColumnName"];#用於判斷語句的欄位項目陣列。
|
| 226 |
liveuser |
15789 |
|
| 3 |
liveuser |
15790 |
}#if end
|
| 226 |
liveuser |
15791 |
|
| 3 |
liveuser |
15792 |
#如果 $conf["WhereColumnValue"] 有設置
|
|
|
15793 |
if(isset($conf["WhereColumnValue"])){
|
| 226 |
liveuser |
15794 |
|
| 3 |
liveuser |
15795 |
$conf["db"]["fastGetDbData"]["WhereColumnValue"]=$conf["WhereColumnValue"];#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
| 226 |
liveuser |
15796 |
|
| 3 |
liveuser |
15797 |
}#if end
|
| 226 |
liveuser |
15798 |
|
| 3 |
liveuser |
15799 |
#$conf["db"]["fastGetDbData"]["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
15800 |
#$conf["db"]["fastGetDbData"]["WhereColumnOperator"]=array("");#用於判斷語句的比較符號陣列,可以用的符號有「"="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
15801 |
#$conf["db"]["fastGetDbData"]["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
| 226 |
liveuser |
15802 |
|
| 3 |
liveuser |
15803 |
#如果 $conf["orderItem"] 有設定
|
|
|
15804 |
if(isset($conf["orderItem"])){
|
| 226 |
liveuser |
15805 |
|
| 3 |
liveuser |
15806 |
$conf["db"]["fastGetDbData"]["orderItem"]=$conf["orderItem"];#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
| 226 |
liveuser |
15807 |
|
| 3 |
liveuser |
15808 |
}#if end
|
| 226 |
liveuser |
15809 |
|
| 3 |
liveuser |
15810 |
#如果 $conf["ascORdesc"] 有設定
|
|
|
15811 |
if(isset($conf["ascORdesc"])){
|
| 226 |
liveuser |
15812 |
|
|
|
15813 |
|
| 3 |
liveuser |
15814 |
$conf["db"]["fastGetDbData"]["ascORdesc"]=$conf["ascORdesc"];#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
| 226 |
liveuser |
15815 |
|
| 3 |
liveuser |
15816 |
}#if end
|
| 226 |
liveuser |
15817 |
|
| 3 |
liveuser |
15818 |
#$conf["db"]["fastGetDbData"]["numberStart"]="0";#為從第幾筆開始讀取,預設為0,代筆第一筆。
|
|
|
15819 |
#$conf["db"]["fastGetDbData"]["numLimit"]="30";#為要取幾筆資料,可以省略,省略則表示不限制數目。
|
| 226 |
liveuser |
15820 |
|
| 3 |
liveuser |
15821 |
#如果 $conf["groupBy"] 有設定
|
|
|
15822 |
if(isset($conf["groupBy"])){
|
| 226 |
liveuser |
15823 |
|
| 3 |
liveuser |
15824 |
$conf["db"]["fastGetDbData"]["groupBy"]=$conf["groupBy"];#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆).
|
| 226 |
liveuser |
15825 |
|
| 3 |
liveuser |
15826 |
}#if end
|
| 226 |
liveuser |
15827 |
|
| 3 |
liveuser |
15828 |
$db["fastGetDbData"]=db::fastGetDbData($conf["db"]["fastGetDbData"]);
|
|
|
15829 |
unset($conf["db"]["fastGetDbData"]);
|
| 226 |
liveuser |
15830 |
|
| 3 |
liveuser |
15831 |
#var_dump($db["fastGetDbData"]);
|
| 226 |
liveuser |
15832 |
|
| 3 |
liveuser |
15833 |
#如果 $db["fastGetDbData"]["status"] 等於 "false"
|
|
|
15834 |
if($db["fastGetDbData"]["status"]=="false"){
|
| 226 |
liveuser |
15835 |
|
| 3 |
liveuser |
15836 |
#設置錯誤識別
|
|
|
15837 |
$result["status"]="false";
|
| 226 |
liveuser |
15838 |
|
| 3 |
liveuser |
15839 |
#設置錯誤訊息
|
|
|
15840 |
$result["error"]=$db["fastGetDbData"];
|
| 226 |
liveuser |
15841 |
|
| 3 |
liveuser |
15842 |
#回傳結果
|
|
|
15843 |
return $result;
|
| 226 |
liveuser |
15844 |
|
| 3 |
liveuser |
15845 |
}#if end
|
| 226 |
liveuser |
15846 |
|
| 3 |
liveuser |
15847 |
#初始化要寫入的內容
|
|
|
15848 |
$writedData[0]=$db["fastGetDbData"]["dataColumnName"];
|
| 226 |
liveuser |
15849 |
|
| 3 |
liveuser |
15850 |
#var_dump($writedData);
|
| 226 |
liveuser |
15851 |
|
| 3 |
liveuser |
15852 |
#取得要寫入的欄位數值
|
| 226 |
liveuser |
15853 |
|
| 3 |
liveuser |
15854 |
#針對每筆資料
|
|
|
15855 |
for($i=0;$i<$db["fastGetDbData"]["dataCount"];$i++){
|
| 226 |
liveuser |
15856 |
|
| 3 |
liveuser |
15857 |
#依據每個欄位
|
|
|
15858 |
for($j=0;$j<count($db["fastGetDbData"]["dataColumnName"]);$j++){
|
| 226 |
liveuser |
15859 |
|
| 3 |
liveuser |
15860 |
#儲存到列裡面
|
|
|
15861 |
$writedData[$i+1][]=$db["fastGetDbData"]["dataContent"][$db["fastGetDbData"]["dataColumnName"][$j]][$i];
|
| 226 |
liveuser |
15862 |
|
| 3 |
liveuser |
15863 |
}#foreach end
|
| 226 |
liveuser |
15864 |
|
| 3 |
liveuser |
15865 |
}#for end
|
| 226 |
liveuser |
15866 |
|
| 3 |
liveuser |
15867 |
#var_dump($writedData);
|
| 226 |
liveuser |
15868 |
|
| 3 |
liveuser |
15869 |
#輸出成csv檔
|
|
|
15870 |
#函式說明:
|
|
|
15871 |
#快速建立一個csv檔案,並且要求使用者下載。
|
|
|
15872 |
#回傳結果::
|
|
|
15873 |
#如果有設置$conf["noDownload"]爲"true"的話,則會回傳檔案的位置
|
|
|
15874 |
#必填參數:
|
|
|
15875 |
$conf["db"]["create"]["dataArray"]=$writedData;#要寫入的文字,$conf["dataArray"][$i],代表第 $i 行的內容。
|
|
|
15876 |
#可省略參數:
|
| 226 |
liveuser |
15877 |
|
| 3 |
liveuser |
15878 |
#如果有設置 $conf["outPutPathAndName"]
|
|
|
15879 |
if(isset($conf["outPutPathAndName"])){
|
| 226 |
liveuser |
15880 |
|
| 3 |
liveuser |
15881 |
$conf["db"]["create"]["csvFilePathAndName"]=$conf["outPutPathAndName"];#csv檔案的名稱,預設爲系統時間
|
| 226 |
liveuser |
15882 |
|
| 3 |
liveuser |
15883 |
}#if end
|
| 226 |
liveuser |
15884 |
|
| 3 |
liveuser |
15885 |
#如果 $conf["noDownload"] 有設置
|
|
|
15886 |
if(isset($conf["noDownload"])){
|
| 226 |
liveuser |
15887 |
|
| 3 |
liveuser |
15888 |
#且$conf["noDownload"]等於"true"
|
|
|
15889 |
if($conf["noDownload"]=="true"){
|
| 226 |
liveuser |
15890 |
|
| 3 |
liveuser |
15891 |
$conf["db"]["create"]["noDownload"]="true";#如果爲"true"則代表不要讓使用者下載,但會回傳檔案的相對位置
|
| 226 |
liveuser |
15892 |
|
|
|
15893 |
}#if end
|
|
|
15894 |
|
| 3 |
liveuser |
15895 |
}#if end
|
| 226 |
liveuser |
15896 |
|
| 3 |
liveuser |
15897 |
#參考資料來源:
|
|
|
15898 |
#http://php.net/manual/en/function.str-split.php
|
|
|
15899 |
return csv::create($conf["db"]["create"]);
|
|
|
15900 |
unset($conf["db"]["create"]);
|
| 226 |
liveuser |
15901 |
|
| 3 |
liveuser |
15902 |
}#funciton exportTableToCsv end
|
| 226 |
liveuser |
15903 |
|
| 3 |
liveuser |
15904 |
/*
|
|
|
15905 |
#函式說明:
|
|
|
15906 |
#透過一筆筆將資料表刪除後,重設識別欄位的自動增量欄位起始值為1
|
|
|
15907 |
#回傳結果:
|
|
|
15908 |
#$result["status"],執行是否正常,"true"代表執行正常,"false"代表執行失敗.
|
|
|
15909 |
#$result["error"],錯誤訊息.
|
|
|
15910 |
#$result["function"],當前執行的函數名稱.
|
|
|
15911 |
#$result["sql"],執行的sql語法陣列.
|
|
|
15912 |
#必填參數:
|
|
|
15913 |
#$conf["dbAddress"],字串,連線到資料庫的位置.
|
|
|
15914 |
$conf["dbAddress"]=$dbAddress;
|
|
|
15915 |
#$conf["dbAccount"],字串,連線到資料庫的帳號.
|
|
|
15916 |
$conf["dbAccount"]=$dbAccount;
|
|
|
15917 |
#$conf["dbName"],字串,要連線到哪個資料庫.
|
|
|
15918 |
$conf["dbName"]=$dbName;
|
|
|
15919 |
#$conf["dtName"],字串,要重設重設識別欄位的自動增量為0的資料表名稱.
|
|
|
15920 |
$conf["dtName"]="";
|
|
|
15921 |
#可省略參數:
|
|
|
15922 |
#$conf["dbPassword"],字串,連線到資料庫的密碼.
|
|
|
15923 |
#$conf["dbPassword"]=$dbPassword;
|
|
|
15924 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的port 3306.
|
|
|
15925 |
#$conf["dbPort"]=$dbPort;
|
|
|
15926 |
#參考資料:
|
|
|
15927 |
#http://dev.mysql.com/doc/refman/5.0/en/alter-table.html
|
|
|
15928 |
#備註:
|
|
|
15929 |
#參考語法,ALTER TABLE dbName.dtName AUTO_INCREMENT = 1;
|
|
|
15930 |
*/
|
|
|
15931 |
public static function eraseDataInTableThenResetAutoIncrement(&$conf){
|
| 226 |
liveuser |
15932 |
|
| 3 |
liveuser |
15933 |
#初始化要回傳的內容
|
|
|
15934 |
$result=array();
|
|
|
15935 |
|
|
|
15936 |
#取得當前執行的函數名稱
|
|
|
15937 |
$result["function"]=__FUNCTION__;
|
|
|
15938 |
|
|
|
15939 |
#如果 $conf 不為陣列
|
|
|
15940 |
if(gettype($conf)!="array"){
|
| 226 |
liveuser |
15941 |
|
| 3 |
liveuser |
15942 |
#設置執行失敗
|
|
|
15943 |
$result["status"]="false";
|
| 226 |
liveuser |
15944 |
|
| 3 |
liveuser |
15945 |
#設置執行錯誤訊息
|
|
|
15946 |
$result["error"][]="\$conf變數須為陣列形態";
|
|
|
15947 |
|
|
|
15948 |
#如果傳入的參數為 null
|
|
|
15949 |
if($conf==null){
|
| 226 |
liveuser |
15950 |
|
| 3 |
liveuser |
15951 |
#設置執行錯誤訊息
|
|
|
15952 |
$result["error"][]="\$conf變數不得為null,請檢查函數「".$result["function"]."」的參數設置有無正確!";
|
| 226 |
liveuser |
15953 |
|
| 3 |
liveuser |
15954 |
}#if end
|
|
|
15955 |
|
|
|
15956 |
#回傳結果
|
|
|
15957 |
return $result;
|
| 226 |
liveuser |
15958 |
|
| 3 |
liveuser |
15959 |
}#if end
|
| 226 |
liveuser |
15960 |
|
| 3 |
liveuser |
15961 |
#檢查參數
|
|
|
15962 |
#函式說明:
|
|
|
15963 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
15964 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
15965 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
15966 |
#$result["function"],當前執行的函式名稱.
|
|
|
15967 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
15968 |
#$result[$shouldBtCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
15969 |
#$result[$shouldBtCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
15970 |
#$result[$shouldBtCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
15971 |
#必填參數:
|
|
|
15972 |
#$conf["variableCheck.checkArguments"]["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
15973 |
$conf["variableCheck.checkArguments"]["varInput"]=&$conf;
|
|
|
15974 |
#$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
15975 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableName"]=array("dbAddress","dbAccount","dbName","dtName");
|
| 226 |
liveuser |
15976 |
#$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列 例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
15977 |
$conf["variableCheck.checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string");
|
|
|
15978 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
15979 |
$conf["variableCheck.checkArguments"]["referenceVarKey"]="variableCheck.checkArguments";
|
|
|
15980 |
#可省略參數:
|
|
|
15981 |
#$conf["canBeEmptyString"],必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"false"。
|
|
|
15982 |
#$conf["canBeEmptyString"]="false";
|
|
|
15983 |
#$conf["variableCheck.checkArguments"]["skipableVariableName"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
|
|
15984 |
$conf["variableCheck.checkArguments"]["skipableVariableName"]=array("dbPassword","dbPort");
|
| 226 |
liveuser |
15985 |
#$conf["variableCheck.checkArguments"]["skipableVariableType"],爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 3 |
liveuser |
15986 |
$conf["variableCheck.checkArguments"]["skipableVariableType"]=array("string","string");
|
|
|
15987 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,"null"代表不指定,若預設值是必填參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
|
|
15988 |
#$conf["skipableVarDefaultValue"]=array("");
|
|
|
15989 |
$checkResult=variableCheck::checkArguments($conf["variableCheck.checkArguments"]);
|
|
|
15990 |
unset($conf["variableCheck.checkArguments"]);
|
| 226 |
liveuser |
15991 |
|
| 3 |
liveuser |
15992 |
#如果 檢查參數 失敗
|
|
|
15993 |
if($checkResult["status"]=="false"){
|
| 226 |
liveuser |
15994 |
|
| 3 |
liveuser |
15995 |
#設置執行不正常
|
|
|
15996 |
$result["status"]="false";
|
| 226 |
liveuser |
15997 |
|
| 3 |
liveuser |
15998 |
#設置執行錯誤
|
|
|
15999 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
16000 |
|
| 3 |
liveuser |
16001 |
#回傳節果
|
|
|
16002 |
return $result;
|
| 226 |
liveuser |
16003 |
|
| 3 |
liveuser |
16004 |
}#if end
|
| 226 |
liveuser |
16005 |
|
| 3 |
liveuser |
16006 |
#如果 檢查參數 不通過
|
|
|
16007 |
if($checkResult["passed"]=="false"){
|
| 226 |
liveuser |
16008 |
|
| 3 |
liveuser |
16009 |
#設置執行不正常
|
|
|
16010 |
$result["status"]="false";
|
| 226 |
liveuser |
16011 |
|
| 3 |
liveuser |
16012 |
#設置執行錯誤
|
|
|
16013 |
$result["error"]=$checkResult;
|
| 226 |
liveuser |
16014 |
|
| 3 |
liveuser |
16015 |
#回傳節果
|
|
|
16016 |
return $result;
|
| 226 |
liveuser |
16017 |
|
| 3 |
liveuser |
16018 |
}#if end
|
| 226 |
liveuser |
16019 |
|
| 3 |
liveuser |
16020 |
#執行一筆筆移除資料的sql語法
|
|
|
16021 |
#函式說明:
|
|
|
16022 |
#執行mysql指令
|
|
|
16023 |
#回傳結果::
|
|
|
16024 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
16025 |
#$result["error"],錯誤訊息的陣列
|
|
|
16026 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
16027 |
#$result["queryString"],mysql查詢的語言
|
|
|
16028 |
#查詢號的解果,需要解析。
|
|
|
16029 |
#必填參數:
|
|
|
16030 |
$conf["db.execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
16031 |
$conf["db.execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
16032 |
$conf["db.execMysqlQuery"]["dbSql"]="DELETE FROM `".$conf["dbName"]."`.`".$conf["dtName"]."` ";#要執行sql語法
|
| 226 |
liveuser |
16033 |
#可省略參數:
|
|
|
16034 |
|
| 3 |
liveuser |
16035 |
#如果有設置 $conf["dbPassword"]
|
|
|
16036 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
16037 |
|
| 3 |
liveuser |
16038 |
$conf["db.execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
16039 |
|
| 3 |
liveuser |
16040 |
}#if end
|
| 226 |
liveuser |
16041 |
|
| 3 |
liveuser |
16042 |
#如果有設置 $conf["dbPort"]
|
|
|
16043 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
16044 |
|
| 3 |
liveuser |
16045 |
$conf["db.execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的3306 port.
|
| 226 |
liveuser |
16046 |
|
| 3 |
liveuser |
16047 |
}#if end
|
| 226 |
liveuser |
16048 |
|
| 3 |
liveuser |
16049 |
$queryResult=db::execMysqlQuery($conf["db.execMysqlQuery"]);
|
|
|
16050 |
unset($conf["db.execMysqlQuery"]);
|
| 226 |
liveuser |
16051 |
|
| 3 |
liveuser |
16052 |
#如果執行 sql 語法失敗
|
|
|
16053 |
if($queryResult["status"]=="false"){
|
| 226 |
liveuser |
16054 |
|
| 3 |
liveuser |
16055 |
#設置執行不正常
|
|
|
16056 |
$result["status"]="false";
|
| 226 |
liveuser |
16057 |
|
| 3 |
liveuser |
16058 |
#設置執行錯誤
|
|
|
16059 |
$result["error"]=$queryResult;
|
| 226 |
liveuser |
16060 |
|
| 3 |
liveuser |
16061 |
#回傳節果
|
|
|
16062 |
return $result;
|
| 226 |
liveuser |
16063 |
|
| 3 |
liveuser |
16064 |
}#if end
|
| 226 |
liveuser |
16065 |
|
| 3 |
liveuser |
16066 |
#取得所執行的sql語法
|
| 226 |
liveuser |
16067 |
$result["sql"][]=$queryResult["queryString"];
|
|
|
16068 |
|
| 3 |
liveuser |
16069 |
#執行重設增量的sql語法
|
|
|
16070 |
#函式說明:
|
|
|
16071 |
#執行mysql指令
|
|
|
16072 |
#回傳結果::
|
|
|
16073 |
#$result["status"],"true"為執行成功;"false"為執行失敗。
|
|
|
16074 |
#$result["error"],錯誤訊息的陣列
|
|
|
16075 |
#$result["queryResource"],mysql查詢後的resource資源,用於給mysql解析的資源變數。
|
|
|
16076 |
#$result["queryString"],mysql查詢的語言
|
|
|
16077 |
#查詢號的解果,需要解析。
|
|
|
16078 |
#必填參數:
|
|
|
16079 |
$conf["db.execMysqlQuery"]["dbAddress"]=$conf["dbAddress"];#爲mysql-Server的位置
|
|
|
16080 |
$conf["db.execMysqlQuery"]["dbAccount"]=$conf["dbAccount"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
16081 |
$conf["db.execMysqlQuery"]["dbSql"]="ALTER TABLE ".$conf["dbName"].".".$conf["dtName"]." AUTO_INCREMENT = 1";#要執行sql語法
|
|
|
16082 |
#如果有設置 $conf["dbPassword"]
|
|
|
16083 |
if(isset($conf["dbPassword"])){
|
| 226 |
liveuser |
16084 |
|
| 3 |
liveuser |
16085 |
$conf["db.execMysqlQuery"]["dbPassword"]=$conf["dbPassword"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 226 |
liveuser |
16086 |
|
| 3 |
liveuser |
16087 |
}#if end
|
| 226 |
liveuser |
16088 |
|
| 3 |
liveuser |
16089 |
#如果有設置 $conf["dbPort"]
|
|
|
16090 |
if(isset($conf["dbPort"])){
|
| 226 |
liveuser |
16091 |
|
| 3 |
liveuser |
16092 |
$conf["db.execMysqlQuery"]["dbPort"]=$conf["dbPort"];#爲連線到mysql-Server時要使用的port,可省略,若省略則代表預設的3306 port.
|
| 226 |
liveuser |
16093 |
|
| 3 |
liveuser |
16094 |
}#if end
|
| 226 |
liveuser |
16095 |
|
| 3 |
liveuser |
16096 |
$queryResult=db::execMysqlQuery($conf["db.execMysqlQuery"]);
|
|
|
16097 |
unset($conf["db.execMysqlQuery"]);
|
| 226 |
liveuser |
16098 |
|
| 3 |
liveuser |
16099 |
#如果執行 sql 語法失敗
|
|
|
16100 |
if($queryResult["status"]=="false"){
|
| 226 |
liveuser |
16101 |
|
| 3 |
liveuser |
16102 |
#設置執行不正常
|
|
|
16103 |
$result["status"]="false";
|
| 226 |
liveuser |
16104 |
|
| 3 |
liveuser |
16105 |
#設置執行錯誤
|
|
|
16106 |
$result["error"]=$queryResult;
|
| 226 |
liveuser |
16107 |
|
| 3 |
liveuser |
16108 |
#回傳節果
|
|
|
16109 |
return $result;
|
| 226 |
liveuser |
16110 |
|
| 3 |
liveuser |
16111 |
}#if end
|
| 226 |
liveuser |
16112 |
|
| 3 |
liveuser |
16113 |
#取得所執行的sql語法
|
|
|
16114 |
$result["sql"][]=$queryResult["queryString"];
|
| 226 |
liveuser |
16115 |
|
| 3 |
liveuser |
16116 |
#設置執行正常
|
|
|
16117 |
$result["status"]="true";
|
| 226 |
liveuser |
16118 |
|
| 3 |
liveuser |
16119 |
#回傳結果
|
|
|
16120 |
return $result;
|
| 226 |
liveuser |
16121 |
|
| 3 |
liveuser |
16122 |
}#function eraseDataInTableThenResetAutoIncrement end
|
|
|
16123 |
|
|
|
16124 |
}#db class end
|
| 226 |
liveuser |
16125 |
|
| 3 |
liveuser |
16126 |
?>
|