| 1 |
liveuser |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
/*
|
|
|
4 |
QBPWCF, Quick Build PHP website Component base on Fedora Linux.
|
| 349 |
liveuser |
5 |
Copyright (C) 2015~2023 Min-Jhin,Chen
|
| 1 |
liveuser |
6 |
|
|
|
7 |
This file is part of QBPWCF.
|
|
|
8 |
|
|
|
9 |
QBPWCF is free software: you can redistribute it and/or modify
|
|
|
10 |
it under the terms of the GNU General Public License as published by
|
|
|
11 |
the Free Software Foundation, either version 3 of the License, or
|
|
|
12 |
(at your option) any later version.
|
|
|
13 |
|
|
|
14 |
QBPWCF is distributed in the hope that it will be useful,
|
|
|
15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
17 |
GNU General Public License for more details.
|
|
|
18 |
|
|
|
19 |
You should have received a copy of the GNU General Public License
|
|
|
20 |
along with QBPWCF. If not, see <http://www.gnu.org/licenses/>.
|
|
|
21 |
|
|
|
22 |
*/
|
|
|
23 |
|
|
|
24 |
/*
|
|
|
25 |
|
| 17 |
liveuser |
26 |
抓取資料庫資料
|
| 1 |
liveuser |
27 |
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
#使用命名空間qbpwcf
|
|
|
31 |
namespace qbpwcf;
|
|
|
32 |
|
| 519 |
liveuser |
33 |
#以該檔案的實際位置的 lib path 為 include path 首位
|
|
|
34 |
exec("cd ".pathinfo(__FILE__)["dirname"]."/../;pwd;",$output,$status);
|
|
|
35 |
set_include_path($output[0].PATH_SEPARATOR.get_include_path());
|
|
|
36 |
|
| 1 |
liveuser |
37 |
#匯入外部套件
|
| 519 |
liveuser |
38 |
include("allInOneForJson.php");
|
| 1 |
liveuser |
39 |
|
| 349 |
liveuser |
40 |
#設定log的檔案名稱
|
|
|
41 |
$logFile=basename(__FILE__).".log.readonly";
|
| 17 |
liveuser |
42 |
|
| 351 |
liveuser |
43 |
/*
|
|
|
44 |
|
| 17 |
liveuser |
45 |
# test case - 1 - start
|
|
|
46 |
|
|
|
47 |
$params=array();
|
|
|
48 |
$params["dbSecret"]="";
|
|
|
49 |
$params["dbAddr"]="localhost";
|
|
|
50 |
$params["dbPort"]="3306";
|
|
|
51 |
$params["dbName"]="test";
|
|
|
52 |
$params["dbUser"]="test";
|
|
|
53 |
$params["dbPass"]="test";
|
|
|
54 |
$params["dtName"]="member";
|
|
|
55 |
$params["cols"]=array("*");
|
|
|
56 |
#$params["WhereColumnName"];
|
|
|
57 |
#$params["WhereColumnValue"];
|
|
|
58 |
#$params["WhereColumnOperator"];
|
|
|
59 |
#$params["orderItem"];
|
|
|
60 |
#$params["ascORdesc"];
|
|
|
61 |
#$params["numLimit"];
|
| 51 |
liveuser |
62 |
#$params["numberStart"];
|
| 17 |
liveuser |
63 |
|
|
|
64 |
#設置參數
|
|
|
65 |
$_POST["params"]=base64_encode(urlencode(json_encode($params)));
|
|
|
66 |
|
|
|
67 |
# test case - 1 - end
|
|
|
68 |
|
| 351 |
liveuser |
69 |
*/
|
| 17 |
liveuser |
70 |
|
| 1 |
liveuser |
71 |
#涵式說明:
|
|
|
72 |
#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.
|
|
|
73 |
#回傳的結果:
|
|
|
74 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
75 |
#$result["error"],錯誤訊息陣列.
|
|
|
76 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
77 |
#$result["warning"],警告訊息陣列.
|
|
|
78 |
#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
|
|
|
79 |
#$result["lostVarName"],沒有皆收到的變數名稱陣列
|
|
|
80 |
#$result["inputDataContent"],所接收的參數陣列.
|
|
|
81 |
#$result["inputDataContent"]["變數名稱"],所接收變數的內容.
|
|
|
82 |
#$result["inputDataCount"],從表單總共接收到幾個元素.
|
|
|
83 |
#$result["HTTP_REFERER"],前一頁的網址,null代表不存在.
|
|
|
84 |
#必填的參數:
|
|
|
85 |
#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?
|
|
|
86 |
$conf["method"]="POST";
|
|
|
87 |
#可省略的參數:
|
|
|
88 |
#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.
|
|
|
89 |
#$conf["allowGet"]="true";
|
|
|
90 |
#$conf["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.
|
|
|
91 |
#$conf["limitPrePage"]=array("");
|
|
|
92 |
#$conf["transferLocation"],字串,遇到get傳值,或前一個頁面不符合要求時要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"
|
|
|
93 |
#$conf["transferLocation"]="";
|
|
|
94 |
#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.
|
|
|
95 |
#$conf["ignore"]=array();
|
|
|
96 |
#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.
|
|
|
97 |
#$conf["correctCharacter"]="false";
|
|
|
98 |
#$conf["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.
|
|
|
99 |
$conf["checkedVarName"]=array("params");
|
|
|
100 |
#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.
|
|
|
101 |
#$conf["canBeEmptyString"]="false";
|
|
|
102 |
#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.
|
|
|
103 |
#$conf["sessionNameArray"]=array();
|
|
|
104 |
#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.
|
|
|
105 |
#$conf["unsetSessionArray"]=array();
|
|
|
106 |
#$conf["recaptcha_url"],字串,有內容代表要檢查有無透過recaptcha於特定頁面網址認證過.
|
|
|
107 |
#$conf["recaptcha_url"]="";
|
|
|
108 |
#參考資料來源:
|
|
|
109 |
#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php
|
|
|
110 |
#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php
|
|
|
111 |
#備註:
|
|
|
112 |
#表單變數的名稱若含有「.」,則會變成「-」。
|
|
|
113 |
$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf);
|
|
|
114 |
unset($conf);
|
|
|
115 |
|
| 349 |
liveuser |
116 |
#函式說明:
|
|
|
117 |
#撰寫log
|
|
|
118 |
#回傳結果:
|
|
|
119 |
#$result["status"],狀態,"true"或"false".
|
|
|
120 |
#$result["error"],錯誤訊息陣列.
|
|
|
121 |
#$result["function"],當前函式的名稱.
|
|
|
122 |
#$result["argu"],使用的參數.
|
|
|
123 |
#必填參數:
|
|
|
124 |
#$conf["path"],log檔案的路徑與名稱.
|
|
|
125 |
$conf["path"]=$logFile;
|
|
|
126 |
#$conf["content"],字串,要寫的內容.
|
|
|
127 |
$conf["content"]=json_encode($responseMultiInputDataSecurityEnhance).PHP_EOL;
|
|
|
128 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
129 |
$conf["fileArgu"]=__FILE__;
|
|
|
130 |
#可省略參數:
|
|
|
131 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
132 |
#$conf["rewrite"]="false";
|
|
|
133 |
#參考資料:
|
|
|
134 |
#無.
|
|
|
135 |
#備註:
|
|
|
136 |
#無.
|
|
|
137 |
$record=logs::record($conf);
|
|
|
138 |
unset($conf);
|
|
|
139 |
|
|
|
140 |
#如果寫log 失敗
|
|
|
141 |
if($record["status"]==="false"){
|
|
|
142 |
|
|
|
143 |
#印出訊息
|
|
|
144 |
echo json_encode($record);
|
|
|
145 |
|
|
|
146 |
#結束執行
|
|
|
147 |
exit;
|
|
|
148 |
|
|
|
149 |
}#if end
|
|
|
150 |
|
| 1 |
liveuser |
151 |
#如果執行失敗
|
|
|
152 |
if($responseMultiInputDataSecurityEnhance["status"]==="false"){
|
|
|
153 |
|
|
|
154 |
#印出訊息
|
| 17 |
liveuser |
155 |
echo json_encode($responseMultiInputDataSecurityEnhance);
|
| 1 |
liveuser |
156 |
|
|
|
157 |
#結束執行
|
|
|
158 |
exit;
|
|
|
159 |
|
|
|
160 |
}#if end
|
|
|
161 |
|
|
|
162 |
#如果邊數檢查不通過
|
|
|
163 |
if($responseMultiInputDataSecurityEnhance["passed"]==="false"){
|
|
|
164 |
|
|
|
165 |
#印出訊息
|
| 17 |
liveuser |
166 |
echo json_encode($responseMultiInputDataSecurityEnhance);
|
| 1 |
liveuser |
167 |
|
|
|
168 |
#結束執行
|
|
|
169 |
exit;
|
|
|
170 |
|
|
|
171 |
}#if end
|
|
|
172 |
|
|
|
173 |
#取得參數
|
|
|
174 |
$params=$responseMultiInputDataSecurityEnhance["inputDataContent"]["params"];
|
|
|
175 |
|
|
|
176 |
#解析變數
|
|
|
177 |
$params=json_decode(urldecode(base64_decode($params)));
|
|
|
178 |
|
|
|
179 |
#轉換為陣列
|
|
|
180 |
$params=(array)$params;
|
|
|
181 |
|
| 349 |
liveuser |
182 |
#函式說明:
|
|
|
183 |
#撰寫log
|
|
|
184 |
#回傳結果:
|
|
|
185 |
#$result["status"],狀態,"true"或"false".
|
|
|
186 |
#$result["error"],錯誤訊息陣列.
|
|
|
187 |
#$result["function"],當前函式的名稱.
|
|
|
188 |
#$result["argu"],使用的參數.
|
|
|
189 |
#必填參數:
|
|
|
190 |
#$conf["path"],log檔案的路徑與名稱.
|
|
|
191 |
$conf["path"]=$logFile;
|
|
|
192 |
#$conf["content"],字串,要寫的內容.
|
|
|
193 |
$conf["content"]=json_encode($params).PHP_EOL;
|
|
|
194 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
195 |
$conf["fileArgu"]=__FILE__;
|
|
|
196 |
#可省略參數:
|
|
|
197 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
198 |
#$conf["rewrite"]="false";
|
|
|
199 |
#參考資料:
|
|
|
200 |
#無.
|
|
|
201 |
#備註:
|
|
|
202 |
#無.
|
|
|
203 |
$record=logs::record($conf);
|
|
|
204 |
unset($conf);
|
|
|
205 |
|
|
|
206 |
#如果寫log 失敗
|
|
|
207 |
if($record["status"]==="false"){
|
|
|
208 |
|
|
|
209 |
#印出訊息
|
|
|
210 |
echo json_encode($record);
|
|
|
211 |
|
|
|
212 |
#結束執行
|
|
|
213 |
exit;
|
|
|
214 |
|
|
|
215 |
}#if end
|
|
|
216 |
|
| 17 |
liveuser |
217 |
#如果少了使用資料庫系統的dbSecret
|
|
|
218 |
if(!isset($params["dbSecret"])){
|
|
|
219 |
|
|
|
220 |
#結束執行
|
|
|
221 |
exit;
|
|
|
222 |
|
|
|
223 |
}#if end
|
|
|
224 |
|
|
|
225 |
#驗證密碼是否正確
|
|
|
226 |
else{
|
|
|
227 |
|
|
|
228 |
#若dbSecret錯誤
|
|
|
229 |
if($params["dbSecret"]!==dbSecret){
|
|
|
230 |
|
|
|
231 |
#結束執行
|
|
|
232 |
exit;
|
|
|
233 |
|
|
|
234 |
}#if end
|
|
|
235 |
|
|
|
236 |
#移除傳遞的 dbSecret
|
|
|
237 |
unset($params["dbSecret"]);
|
|
|
238 |
|
|
|
239 |
}#else end
|
|
|
240 |
|
| 1 |
liveuser |
241 |
#檢查變數
|
|
|
242 |
#函式說明:
|
|
|
243 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
244 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
245 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
246 |
#$result["function"],當前執行的函式名稱.
|
|
|
247 |
#$result["argu"],設置給予的參數.
|
|
|
248 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
249 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
250 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
251 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
252 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
253 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
254 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
255 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
256 |
#必填寫的參數:
|
|
|
257 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
258 |
$conf["variableCheck::checkArguments"]["varInput"]=&$params;
|
|
|
259 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
260 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
261 |
#可以省略的參數:
|
|
|
262 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
263 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddr","dbName","dbUser","dbPass","dtName","cols");
|
|
|
264 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
265 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string","array");
|
|
|
266 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
267 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
268 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
269 |
#$conf["canNotBeEmpty"]=array();
|
|
|
270 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
271 |
#$conf["canBeEmpty"]=array();
|
|
|
272 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
| 51 |
liveuser |
273 |
$conf["variableCheck::checkArguments"]["skipableVariableCanNotBeEmpty"]=array("dbPort","orderItem","ascORdesc","numLimit","WhereColumnName","WhereColumnValue","WhereColumnOperator","numberStart");
|
| 1 |
liveuser |
274 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 51 |
liveuser |
275 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPort","orderItem","ascORdesc","numLimit","WhereColumnName","WhereColumnValue","WhereColumnOperator","numberStart");
|
| 1 |
liveuser |
276 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 51 |
liveuser |
277 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string","string","string","string","array","array","array","string");
|
| 1 |
liveuser |
278 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 51 |
liveuser |
279 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("3306",null,null,null,null,null,null,"0");
|
| 1 |
liveuser |
280 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
281 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
282 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
283 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
284 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
285 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cols","vals");
|
|
|
286 |
#參考資料來源:
|
|
|
287 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
288 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
289 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
290 |
|
| 349 |
liveuser |
291 |
#函式說明:
|
|
|
292 |
#撰寫log
|
|
|
293 |
#回傳結果:
|
|
|
294 |
#$result["status"],狀態,"true"或"false".
|
|
|
295 |
#$result["error"],錯誤訊息陣列.
|
|
|
296 |
#$result["function"],當前函式的名稱.
|
|
|
297 |
#$result["argu"],使用的參數.
|
|
|
298 |
#必填參數:
|
|
|
299 |
#$conf["path"],log檔案的路徑與名稱.
|
|
|
300 |
$conf["path"]=$logFile;
|
|
|
301 |
#$conf["content"],字串,要寫的內容.
|
|
|
302 |
$conf["content"]=json_encode($checkArguments).PHP_EOL;
|
|
|
303 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
304 |
$conf["fileArgu"]=__FILE__;
|
|
|
305 |
#可省略參數:
|
|
|
306 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
307 |
#$conf["rewrite"]="false";
|
|
|
308 |
#參考資料:
|
|
|
309 |
#無.
|
|
|
310 |
#備註:
|
|
|
311 |
#無.
|
|
|
312 |
$record=logs::record($conf);
|
|
|
313 |
unset($conf);
|
|
|
314 |
|
|
|
315 |
#如果寫log 失敗
|
|
|
316 |
if($record["status"]==="false"){
|
|
|
317 |
|
|
|
318 |
#印出訊息
|
|
|
319 |
echo json_encode($record);
|
|
|
320 |
|
|
|
321 |
#結束執行
|
|
|
322 |
exit;
|
|
|
323 |
|
|
|
324 |
}#if end
|
|
|
325 |
|
| 1 |
liveuser |
326 |
#如果執行失敗
|
|
|
327 |
if($checkArguments["status"]==="false"){
|
|
|
328 |
|
|
|
329 |
#印出訊息
|
|
|
330 |
echo json_encode($checkArguments);
|
|
|
331 |
|
|
|
332 |
#結束執行
|
|
|
333 |
exit;
|
|
|
334 |
|
|
|
335 |
}#if end
|
|
|
336 |
|
|
|
337 |
#如果邊數檢查不通過
|
|
|
338 |
if($checkArguments["passed"]==="false"){
|
|
|
339 |
|
|
|
340 |
#印出訊息
|
|
|
341 |
echo json_encode($checkArguments);
|
|
|
342 |
|
|
|
343 |
#結束執行
|
|
|
344 |
exit;
|
|
|
345 |
|
|
|
346 |
}#if end
|
|
|
347 |
|
| 17 |
liveuser |
348 |
/*
|
|
|
349 |
#可能存在的參數
|
|
|
350 |
$params["dbAddr"];
|
|
|
351 |
$params["dbPort"];
|
|
|
352 |
$params["dbName"];
|
|
|
353 |
$params["dbUser"];
|
|
|
354 |
$params["dbPass"];
|
|
|
355 |
$params["dtName"];
|
|
|
356 |
$params["cols"];
|
|
|
357 |
$params["WhereColumnName"];
|
|
|
358 |
$params["WhereColumnValue"];
|
|
|
359 |
$params["WhereColumnOperator"];
|
|
|
360 |
$params["orderItem"];
|
|
|
361 |
$params["ascORdesc"];
|
|
|
362 |
$params["numLimit"];
|
|
|
363 |
*/
|
| 1 |
liveuser |
364 |
|
|
|
365 |
#涵式說明:
|
|
|
366 |
#一次取得資料庫、表的資料
|
|
|
367 |
#回傳的結果
|
|
|
368 |
#$result["status"],執行結果"true"為成功;"false"為執行失敗。
|
|
|
369 |
#$result["error"],錯誤訊息陣列。
|
|
|
370 |
#$result["function"],當前執行的漢書名稱.
|
|
|
371 |
#$result["argu"],使用的參數.
|
|
|
372 |
#$result["dataColumnName"],抓取的資料欄位名稱陣列.
|
|
|
373 |
#$result["dataColumnName"][$i]代表第$i+1個欄位名稱
|
|
|
374 |
#$result["dataContent"],爲資料的內容。
|
|
|
375 |
#$result["dataContent"][$conf["WhereColumnName"][$i]][$dataSetNum]
|
|
|
376 |
#$dataSetNum 爲第$dataSetNum+1筆資料
|
|
|
377 |
#$conf["WhereColumnName"][$i] 爲第 $i+1 個欄位的名稱
|
|
|
378 |
#$result["dataCount"],爲取得的資料筆數。
|
|
|
379 |
#$result["sql"],執行的sql字串.
|
|
|
380 |
#必填的參數:
|
|
|
381 |
$conf["dbAddress"]=$params["dbAddr"];#爲dbServer的位置。
|
|
|
382 |
$conf["dbAccount"]=$params["dbUser"];#爲登入dbServer的帳號。
|
|
|
383 |
$conf["dbName"]=$params["dbName"];#爲要存取的資料庫名稱
|
|
|
384 |
$conf["tableName"]=$params["dtName"];#爲要存取的資料表名稱
|
|
|
385 |
$conf["columnYouWant"]=$params["cols"];#你想要的欄位!,若設為「array("*")」則代表全部欄位.
|
|
|
386 |
#可省略的參數:
|
|
|
387 |
$conf["dbPassword"]=$params["dbPass"];#爲要存取dbServer的密碼
|
|
|
388 |
|
|
|
389 |
#如果存在 $params["WhereColumnName"]
|
|
|
390 |
if(isset($params["WhereColumnName"])){
|
|
|
391 |
|
|
|
392 |
$conf["WhereColumnName"]=$params["WhereColumnName"];#用於判斷語句的欄位項目陣列。
|
|
|
393 |
|
|
|
394 |
}#if end
|
|
|
395 |
|
|
|
396 |
#如果存在 $params["WhereColumnName"]
|
|
|
397 |
if(isset($params["WhereColumnValue"])){
|
|
|
398 |
|
|
|
399 |
$conf["WhereColumnValue"]=$params["WhereColumnValue"];#用於判斷語句的欄位數值陣列,若與LIKE搭配,則可以在關鍵自字串的左右名加上「%」符號,這樣就可以搜尋具有該字串的內容。
|
|
|
400 |
|
|
|
401 |
}#if end
|
|
|
402 |
|
|
|
403 |
#$conf["WhereColumnCombine"]=array("");#用於判斷語句當中需要()起來的判斷式,須爲陣列值,"s"代表「(」,"e"代表「)」 ,若無則須設爲""。
|
|
|
404 |
|
|
|
405 |
#如果存在 $params["WhereColumnOperator"]
|
|
|
406 |
if(isset($params["WhereColumnOperator"])){
|
|
|
407 |
|
|
|
408 |
$conf["WhereColumnOperator"]=$params["WhereColumnOperator"];#用於判斷語句的比較符號陣列,可以用的符號有「"="、"!="、">"、"<"、"LIKE"、"NOT LIKE"」,預設都爲「=」。
|
|
|
409 |
|
|
|
410 |
}#if end
|
|
|
411 |
|
|
|
412 |
#$conf["WhereColumnAndOr"]=array("");#用於判斷語句條件之間成立的條件是AND還是OR,須爲陣列值。其數量應爲要判斷的欄位數量減一。
|
|
|
413 |
#$conf["whereIn"],二維字串陣列,為每個in語句的內容,特定欄位數值等於陣列元素之一。array(array("colName",array("a","b","c")));代表欄位colName的值為a,b,c三者之一.
|
|
|
414 |
#$conf["whereIn"]=array(array("colName",array("a","b","c")));
|
|
|
415 |
#$conf["whereNotIn"],二維字串陣列,為每個not in語句的內容,array(array("colName",array("a","b","c")));代表欄位colName的值不為a,b,c三者之一.
|
|
|
416 |
#$conf["whereNotIn"]=array(array("colName",array("a","b","c")));
|
|
|
417 |
|
|
|
418 |
#如果有設置 $params["orderItem"]
|
|
|
419 |
if(isset($params["orderItem"])){
|
|
|
420 |
|
|
|
421 |
$conf["orderItem"]=$params["orderItem"];#爲排序的項目依據,若要用隨機抽樣,可以用"rand()",可省略。
|
|
|
422 |
|
|
|
423 |
}#if end
|
|
|
424 |
|
|
|
425 |
#如果有設置 $params["ascORdesc"]
|
|
|
426 |
if(isset($params["ascORdesc"])){
|
|
|
427 |
|
|
|
428 |
$conf["ascORdesc"]=$params["ascORdesc"];#爲要低增還是遞減排序,asc爲遞增;desc爲遞減。
|
|
|
429 |
|
|
|
430 |
}#if end
|
|
|
431 |
|
|
|
432 |
#如果有設置 $params["numLimit"]
|
|
|
433 |
if(isset($params["numLimit"])){
|
|
|
434 |
|
|
|
435 |
$conf["numLimit"]=$params["numLimit"];#為要取幾筆資料,可以省略,省略則表示不限制數目。
|
|
|
436 |
|
|
|
437 |
}#if end
|
|
|
438 |
|
| 51 |
liveuser |
439 |
#如果有設置 $params["numberStart"]
|
|
|
440 |
if(isset($params["numberStart"])){
|
|
|
441 |
|
|
|
442 |
$conf["numberStart"]=$params["numberStart"];#為從第幾筆開始讀取,預設為0,代筆第一筆。
|
|
|
443 |
|
|
|
444 |
}#if end
|
|
|
445 |
|
| 1 |
liveuser |
446 |
#$conf["groupBy"]=array("");#爲要以哪幾個欄爲作爲分羣的依據(欄位相同的數值僅會取出一筆)。
|
| 17 |
liveuser |
447 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表使用預設的3306 port.
|
|
|
448 |
$conf["dbPort"]=$params["dbPort"];
|
| 1 |
liveuser |
449 |
$fastGetDbData=db::fastGetDbData($conf);
|
|
|
450 |
unset($conf);
|
|
|
451 |
|
| 349 |
liveuser |
452 |
#函式說明:
|
|
|
453 |
#撰寫log
|
|
|
454 |
#回傳結果:
|
|
|
455 |
#$result["status"],狀態,"true"或"false".
|
|
|
456 |
#$result["error"],錯誤訊息陣列.
|
|
|
457 |
#$result["function"],當前函式的名稱.
|
|
|
458 |
#$result["argu"],使用的參數.
|
|
|
459 |
#必填參數:
|
|
|
460 |
#$conf["path"],log檔案的路徑與名稱.
|
|
|
461 |
$conf["path"]=$logFile;
|
|
|
462 |
#$conf["content"],字串,要寫的內容.
|
|
|
463 |
$conf["content"]=json_encode($fastGetDbData).PHP_EOL;
|
|
|
464 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
465 |
$conf["fileArgu"]=__FILE__;
|
|
|
466 |
#可省略參數:
|
|
|
467 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
468 |
#$conf["rewrite"]="false";
|
|
|
469 |
#參考資料:
|
|
|
470 |
#無.
|
|
|
471 |
#備註:
|
|
|
472 |
#無.
|
|
|
473 |
$record=logs::record($conf);
|
|
|
474 |
unset($conf);
|
|
|
475 |
|
|
|
476 |
#如果寫log 失敗
|
|
|
477 |
if($record["status"]==="false"){
|
|
|
478 |
|
|
|
479 |
#印出訊息
|
|
|
480 |
echo json_encode($record);
|
|
|
481 |
|
|
|
482 |
#結束執行
|
|
|
483 |
exit;
|
|
|
484 |
|
|
|
485 |
}#if end
|
|
|
486 |
|
| 1 |
liveuser |
487 |
#印出訊息
|
|
|
488 |
echo json_encode($fastGetDbData);
|
|
|
489 |
|
|
|
490 |
?>
|