| 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 |
|
|
|
26 |
依照來源的內容來將資料塞入到資料庫
|
|
|
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";
|
|
|
42 |
|
| 17 |
liveuser |
43 |
/*
|
|
|
44 |
|
|
|
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("account","password","comment");
|
|
|
56 |
$params["vals"]=array("test acct","test pass","test comment");
|
|
|
57 |
|
|
|
58 |
#設置參數
|
|
|
59 |
$_POST["params"]=base64_encode(urlencode(json_encode($params)));
|
|
|
60 |
|
|
|
61 |
# test case - 1 - end
|
|
|
62 |
|
|
|
63 |
*/
|
|
|
64 |
|
| 1 |
liveuser |
65 |
#涵式說明:
|
|
|
66 |
#可以處理多個透過GET、POST而來的資訊,儲存成變數,同時限定傳送的方法、來源,來增加安全性,檢查有沒有皆收到必須要接收到的變數,沒有接收到的變數可以指定從session變數中取得.
|
|
|
67 |
#回傳的結果:
|
|
|
68 |
#$result["status"],執行正常與否,"true"代表正常,"false"代表不正常.
|
|
|
69 |
#$result["error"],錯誤訊息陣列.
|
|
|
70 |
#$resutl["function"],當前執行的涵式名稱.
|
|
|
71 |
#$result["warning"],警告訊息陣列.
|
|
|
72 |
#$result["passed"],是否有皆收到全部該接收到的變數,若有設定$conf["checkedVarName"]的話,執行正常後會回傳該結果。
|
|
|
73 |
#$result["lostVarName"],沒有皆收到的變數名稱陣列
|
|
|
74 |
#$result["inputDataContent"],所接收的參數陣列.
|
|
|
75 |
#$result["inputDataContent"]["變數名稱"],所接收變數的內容.
|
|
|
76 |
#$result["inputDataCount"],從表單總共接收到幾個元素.
|
|
|
77 |
#$result["HTTP_REFERER"],前一頁的網址,null代表不存在.
|
|
|
78 |
#必填的參數:
|
|
|
79 |
#$conf["method"],字串,傳送過來的資料是用"post/POST"還是"get/GET"?
|
|
|
80 |
$conf["method"]="POST";
|
|
|
81 |
#可省略的參數:
|
|
|
82 |
#$conf["allowGet"],字串,是否要允許 get 傳值,"true",代表允許;"false" ,代表不允許,預設爲不允許.
|
|
|
83 |
#$conf["allowGet"]="true";
|
|
|
84 |
#$conf["limitPrePage"],字串陣列,是否要限定前一頁的網址為哪些,才能接收內容,不符合則轉址.
|
|
|
85 |
#$conf["limitPrePage"]=array("");
|
|
|
86 |
#$conf["transferLocation"],字串,遇到get傳值,或前一個頁面不符合要求時要轉址到的頁面,預設爲資安素養網"https://isafe.moe.edu.tw/"
|
|
|
87 |
#$conf["transferLocation"]="";
|
|
|
88 |
#$conf["ignore"]=字串陣列,如果要接收的變數名稱與該陣列其一元素一樣,則不放進要回傳的變數裏面.
|
|
|
89 |
#$conf["ignore"]=array();
|
|
|
90 |
#$conf["correctCharacter"]=,字串,如果爲"false",則不處理可能導致網頁出問題的字串,預設爲要進行處理.
|
|
|
91 |
#$conf["correctCharacter"]="false";
|
|
|
92 |
#$conf["checkedVarName"],字串陣列,為檢查是否有接收到哪些變數.
|
|
|
93 |
$conf["checkedVarName"]=array("params");
|
|
|
94 |
#$conf["canBeEmptyString"],字串,用$conf["checkedVarName"]指定接收的變數名稱陣列,若接收到的內容為空字串是否算有接收到內容,預設為"false","true"代表接收到的內容可以為空字串,"false"代表接收到的內容不可以為空字串.
|
|
|
95 |
#$conf["canBeEmptyString"]="false";
|
|
|
96 |
#$conf["sessionNameArray"],陣列,若存在則代表若沒有從表單取得變數,則從session變數中取得內容,每個元素代表每個表單變數對應的session名稱,若不是要改用session方式取得變數內容的變數,請輸入null,數量請跟$conf["checkedVarName"]參數一致.
|
|
|
97 |
#$conf["sessionNameArray"]=array();
|
|
|
98 |
#$conf["unsetSessionArray"],陣列,與$conf["sessionNameArray"]對應的元素,是否要接收到變數後就卸除,"true"代表要卸除,"false"代表不要卸除.
|
|
|
99 |
#$conf["unsetSessionArray"]=array();
|
|
|
100 |
#$conf["recaptcha_url"],字串,有內容代表要檢查有無透過recaptcha於特定頁面網址認證過.
|
|
|
101 |
#$conf["recaptcha_url"]="";
|
|
|
102 |
#參考資料來源:
|
|
|
103 |
#foreach 的用法 -> http://php.net/manual/en/control-structures.foreach.php
|
|
|
104 |
#伺服器端的變數 -> http://php.net/manual/en/reserved.variables.server.php
|
|
|
105 |
#備註:
|
|
|
106 |
#表單變數的名稱若含有「.」,則會變成「-」。
|
|
|
107 |
$responseMultiInputDataSecurityEnhance=form::responseMultiInputDataSecurityEnhance($conf);
|
|
|
108 |
unset($conf);
|
|
|
109 |
|
| 349 |
liveuser |
110 |
#函式說明:
|
|
|
111 |
#撰寫log
|
|
|
112 |
#回傳結果:
|
|
|
113 |
#$result["status"],狀態,"true"或"false".
|
|
|
114 |
#$result["error"],錯誤訊息陣列.
|
|
|
115 |
#$result["function"],當前函式的名稱.
|
|
|
116 |
#$result["argu"],使用的參數.
|
|
|
117 |
#必填參數:
|
|
|
118 |
#$conf["path"],log檔案的路徑與名稱.
|
|
|
119 |
$conf["path"]=$logFile;
|
|
|
120 |
#$conf["content"],字串,要寫的內容.
|
|
|
121 |
$conf["content"]=json_encode($responseMultiInputDataSecurityEnhance).PHP_EOL;
|
|
|
122 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
123 |
$conf["fileArgu"]=__FILE__;
|
|
|
124 |
#可省略參數:
|
|
|
125 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
126 |
#$conf["rewrite"]="false";
|
|
|
127 |
#參考資料:
|
|
|
128 |
#無.
|
|
|
129 |
#備註:
|
|
|
130 |
#無.
|
|
|
131 |
$record=logs::record($conf);
|
|
|
132 |
unset($conf);
|
|
|
133 |
|
|
|
134 |
#如果寫log 失敗
|
|
|
135 |
if($record["status"]==="false"){
|
|
|
136 |
|
|
|
137 |
#印出訊息
|
|
|
138 |
echo json_encode($record);
|
|
|
139 |
|
|
|
140 |
#結束執行
|
|
|
141 |
exit;
|
|
|
142 |
|
|
|
143 |
}#if end
|
|
|
144 |
|
| 1 |
liveuser |
145 |
#如果執行失敗
|
|
|
146 |
if($responseMultiInputDataSecurityEnhance["status"]==="false"){
|
|
|
147 |
|
|
|
148 |
#印出訊息
|
| 17 |
liveuser |
149 |
echo json_encode($responseMultiInputDataSecurityEnhance);
|
| 1 |
liveuser |
150 |
|
|
|
151 |
#結束執行
|
|
|
152 |
exit;
|
|
|
153 |
|
|
|
154 |
}#if end
|
|
|
155 |
|
|
|
156 |
#如果邊數檢查不通過
|
|
|
157 |
if($responseMultiInputDataSecurityEnhance["passed"]==="false"){
|
|
|
158 |
|
|
|
159 |
#印出訊息
|
| 17 |
liveuser |
160 |
echo json_encode($responseMultiInputDataSecurityEnhance);
|
| 1 |
liveuser |
161 |
|
|
|
162 |
#結束執行
|
|
|
163 |
exit;
|
|
|
164 |
|
|
|
165 |
}#if end
|
|
|
166 |
|
|
|
167 |
#取得參數
|
|
|
168 |
$params=$responseMultiInputDataSecurityEnhance["inputDataContent"]["params"];
|
|
|
169 |
|
|
|
170 |
#解析變數
|
|
|
171 |
$params=json_decode(urldecode(base64_decode($params)));
|
|
|
172 |
|
|
|
173 |
#轉換為陣列
|
|
|
174 |
$params=(array)$params;
|
|
|
175 |
|
| 349 |
liveuser |
176 |
#函式說明:
|
|
|
177 |
#撰寫log
|
|
|
178 |
#回傳結果:
|
|
|
179 |
#$result["status"],狀態,"true"或"false".
|
|
|
180 |
#$result["error"],錯誤訊息陣列.
|
|
|
181 |
#$result["function"],當前函式的名稱.
|
|
|
182 |
#$result["argu"],使用的參數.
|
|
|
183 |
#必填參數:
|
|
|
184 |
#$conf["path"],log檔案的路徑與名稱.
|
|
|
185 |
$conf["path"]=$logFile;
|
|
|
186 |
#$conf["content"],字串,要寫的內容.
|
|
|
187 |
$conf["content"]=json_encode($params).PHP_EOL;
|
|
|
188 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
189 |
$conf["fileArgu"]=__FILE__;
|
|
|
190 |
#可省略參數:
|
|
|
191 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
192 |
#$conf["rewrite"]="false";
|
|
|
193 |
#參考資料:
|
|
|
194 |
#無.
|
|
|
195 |
#備註:
|
|
|
196 |
#無.
|
|
|
197 |
$record=logs::record($conf);
|
|
|
198 |
unset($conf);
|
|
|
199 |
|
|
|
200 |
#如果寫log 失敗
|
|
|
201 |
if($record["status"]==="false"){
|
|
|
202 |
|
|
|
203 |
#印出訊息
|
|
|
204 |
echo json_encode($record);
|
|
|
205 |
|
|
|
206 |
#結束執行
|
|
|
207 |
exit;
|
|
|
208 |
|
|
|
209 |
}#if end
|
|
|
210 |
|
| 17 |
liveuser |
211 |
#如果少了使用資料庫系統的dbSecret
|
|
|
212 |
if(!isset($params["dbSecret"])){
|
|
|
213 |
|
|
|
214 |
#結束執行
|
|
|
215 |
exit;
|
|
|
216 |
|
|
|
217 |
}#if end
|
|
|
218 |
|
|
|
219 |
#驗證密碼是否正確
|
|
|
220 |
else{
|
|
|
221 |
|
|
|
222 |
#若dbSecret錯誤
|
|
|
223 |
if($params["dbSecret"]!==dbSecret){
|
|
|
224 |
|
|
|
225 |
#結束執行
|
|
|
226 |
exit;
|
|
|
227 |
|
|
|
228 |
}#if end
|
|
|
229 |
|
|
|
230 |
#移除傳遞的 dbSecret
|
|
|
231 |
unset($params["dbSecret"]);
|
|
|
232 |
|
|
|
233 |
}#else end
|
|
|
234 |
|
| 1 |
liveuser |
235 |
#檢查變數
|
|
|
236 |
#函式說明:
|
|
|
237 |
#檢查必填與可省略的參數,可省略參數可指定預設要給與什麼數值內容。
|
|
|
238 |
#$result["status"],執行是否正常,"true"代表正常,"false"代表不正常.
|
|
|
239 |
#$reuslt["error"],執行不正常結束的錯訊息陣列.
|
|
|
240 |
#$result["function"],當前執行的函式名稱.
|
|
|
241 |
#$result["argu"],設置給予的參數.
|
|
|
242 |
#$result["passed"],識別要檢查的全體變數是否存在以及型態是否正確的變數,"true"代表檢查全部通過;"false"代表檢查不通過
|
|
|
243 |
#$result[$shouldBeCheckedVarName]["varExist"],所檢查的變數是否存在,"false"代表不存在;"true"代表存在
|
|
|
244 |
#$result[$shouldBeCheckedVarName]["varType"],所檢查的變數型態是否正確,"false"代表錯誤;"true"代表正確
|
|
|
245 |
#$result[$shouldBeCheckedVarName]["error"],每個參數設定的錯誤訊息
|
|
|
246 |
#$result["shouldNotBeEmpty"],不應該為空字串或控陣列的變數.
|
|
|
247 |
#$result["argu"],字串陣列,目前輸入的參數名稱陣列.
|
|
|
248 |
#$result["legalVarName"],字串陣列,合法可用的參數名稱陣列.
|
|
|
249 |
#$result["notNeedVar"],字串陣列,多餘的參數名稱.
|
|
|
250 |
#必填寫的參數:
|
|
|
251 |
#$conf["varInput"],陣列變數,要檢查的陣列變數,請在要檢查的參數前面加上&,這樣變動的結果才能被套用。
|
|
|
252 |
$conf["variableCheck::checkArguments"]["varInput"]=&$params;
|
|
|
253 |
#$conf["referenceVarKey"],字串,$conf參數後面的key值,用於移除不要的參考陣列.
|
|
|
254 |
$conf["variableCheck::checkArguments"]["referenceVarKey"]="variableCheck::checkArguments";
|
|
|
255 |
#可以省略的參數:
|
|
|
256 |
#$conf["mustBeFilledVariableName"],爲必填參數的變數名稱陣列,形態爲陣列變數,元素數量需要跟"mustBeFilledVariableType"參數的元素數量一致,例如: $conf["mustBeFilledVariableName"] = array("id","account","password");
|
|
|
257 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableName"]=array("dbAddr","dbName","dbUser","dbPass","dtName","cols","vals");
|
|
|
258 |
#$conf["mustBeFilledVariableType"],爲必填參數的變數陣列應該爲何種變數形態,形態爲陣列,元素數量需要跟"mustBeFilledVariableName"參數的元素數量一致,例如: $conf["mustBeFilledVariableType"] = array("string",integer,"double","resource","object"); , null代表不指定變數形態.
|
|
|
259 |
$conf["variableCheck::checkArguments"]["mustBeFilledVariableType"]=array("string","string","string","string","string","array","array");
|
|
|
260 |
#$conf["canBeEmptyString"],字串,必填變數內容如果是空字串就不能算是有設置的話,請設為"false",預設爲"true",可以為空字串.
|
|
|
261 |
$conf["variableCheck::checkArguments"]["canBeEmptyString"]="false";
|
|
|
262 |
#$conf["canNotBeEmpty"],字串陣列,哪些必填參數的內容不得為空字串或空陣列,僅當$conf["canBeEmptyString"]為"true"時會生效.
|
|
|
263 |
#$conf["canNotBeEmpty"]=array();
|
|
|
264 |
#$conf["canBeEmpty"],字串陣列,哪些必填參數的內容可為空字串或空陣列,僅當$conf["canBeEmptyString"]為"false"時會生效.
|
|
|
265 |
#$conf["canBeEmpty"]=array();
|
|
|
266 |
#$conf["skipableVariableCanNotBeEmpty"],字串陣列,哪些可省略參數不可以為空字串或空陣列.
|
|
|
267 |
#$conf["skipableVariableCanNotBeEmpty"]=array();
|
|
|
268 |
#$conf["skipableVariableName"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableName"] = array("id","account","password");
|
| 17 |
liveuser |
269 |
$conf["variableCheck::checkArguments"]["skipableVariableName"]=array("dbPort");
|
| 1 |
liveuser |
270 |
#$conf["skipableVariableType"],陣列字串,爲可省略參數的變數名稱陣列,形態爲陣列變數,例如: $conf["skipableVariableType"] = array("string",integer,"double");
|
| 17 |
liveuser |
271 |
$conf["variableCheck::checkArguments"]["skipableVariableType"]=array("string");
|
| 1 |
liveuser |
272 |
#$conf["skipableVarDefaultValue"],字串陣列,每個不存在的可省略變數要初始化為什麼,null與代表不指定,若預設值是參數之一,請將$conf["mustBeFilledVar"]改成"\$conf["\mustBeFilledVar\"]".
|
| 17 |
liveuser |
273 |
$conf["variableCheck::checkArguments"]["skipableVarDefaultValue"]=array("3306");
|
| 1 |
liveuser |
274 |
#$conf["disallowAllSkipableVarIsEmpty"],字串,是否允許每個可省略參數都為空字串,預設為"true"允許,反之為"false".
|
|
|
275 |
#$conf["disallowAllSkipableVarIsEmpty"]="";
|
|
|
276 |
#$conf["disallowAllSkipableVarIsEmptyArray"],字串,是否允許每個可省略參數都為空陣列,預設為"true"允許,反之為"false".
|
|
|
277 |
#$conf["disallowAllSkipableVarIsEmptyArray"]="";
|
|
|
278 |
#$conf["arrayCountEqualCheck"],字串陣列,為檢查哪些陣列參數的元素數量要一樣,$conf["arrayCountEqualCheck"][$i]=array()為第$i組key為哪些的變數其元素數量要相等.
|
|
|
279 |
$conf["variableCheck::checkArguments"]["arrayCountEqualCheck"][]=array("cols","vals");
|
|
|
280 |
#參考資料來源:
|
|
|
281 |
#array_keys=>http://php.net/manual/en/function.array-keys.php
|
|
|
282 |
$checkArguments=variableCheck::checkArguments($conf["variableCheck::checkArguments"]);
|
|
|
283 |
unset($conf["variableCheck::checkArguments"]);
|
|
|
284 |
|
| 349 |
liveuser |
285 |
#函式說明:
|
|
|
286 |
#撰寫log
|
|
|
287 |
#回傳結果:
|
|
|
288 |
#$result["status"],狀態,"true"或"false".
|
|
|
289 |
#$result["error"],錯誤訊息陣列.
|
|
|
290 |
#$result["function"],當前函式的名稱.
|
|
|
291 |
#$result["argu"],使用的參數.
|
|
|
292 |
#必填參數:
|
|
|
293 |
#$conf["path"],log檔案的路徑與名稱.
|
|
|
294 |
$conf["path"]=$logFile;
|
|
|
295 |
#$conf["content"],字串,要寫的內容.
|
|
|
296 |
$conf["content"]=json_encode($checkArguments).PHP_EOL;
|
|
|
297 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
298 |
$conf["fileArgu"]=__FILE__;
|
|
|
299 |
#可省略參數:
|
|
|
300 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
301 |
#$conf["rewrite"]="false";
|
|
|
302 |
#參考資料:
|
|
|
303 |
#無.
|
|
|
304 |
#備註:
|
|
|
305 |
#無.
|
|
|
306 |
$record=logs::record($conf);
|
|
|
307 |
unset($conf);
|
|
|
308 |
|
|
|
309 |
#如果寫log 失敗
|
|
|
310 |
if($record["status"]==="false"){
|
|
|
311 |
|
|
|
312 |
#印出訊息
|
|
|
313 |
echo json_encode($record);
|
|
|
314 |
|
|
|
315 |
#結束執行
|
|
|
316 |
exit;
|
|
|
317 |
|
|
|
318 |
}#if end
|
|
|
319 |
|
| 1 |
liveuser |
320 |
#如果執行失敗
|
|
|
321 |
if($checkArguments["status"]==="false"){
|
|
|
322 |
|
|
|
323 |
#印出訊息
|
| 17 |
liveuser |
324 |
echo json_encode($checkArguments);
|
| 1 |
liveuser |
325 |
|
|
|
326 |
#結束執行
|
|
|
327 |
exit;
|
|
|
328 |
|
|
|
329 |
}#if end
|
|
|
330 |
|
|
|
331 |
#如果邊數檢查不通過
|
|
|
332 |
if($checkArguments["passed"]==="false"){
|
|
|
333 |
|
|
|
334 |
#印出訊息
|
| 17 |
liveuser |
335 |
echo json_encode($checkArguments);
|
| 1 |
liveuser |
336 |
|
|
|
337 |
#結束執行
|
|
|
338 |
exit;
|
|
|
339 |
|
|
|
340 |
}#if end
|
|
|
341 |
|
|
|
342 |
#取得資料庫連線參數
|
|
|
343 |
$params["dbAddr"];
|
| 17 |
liveuser |
344 |
$params["dbPort"];#預設為3306
|
| 1 |
liveuser |
345 |
$params["dbName"];
|
|
|
346 |
$params["dbUser"];
|
|
|
347 |
$params["dbPass"];
|
|
|
348 |
$params["dtName"];
|
|
|
349 |
$params["cols"];
|
|
|
350 |
$params["vals"];
|
|
|
351 |
|
|
|
352 |
#var_dump($params);
|
|
|
353 |
#exit;
|
|
|
354 |
|
|
|
355 |
#涵式說明:
|
|
|
356 |
#插入資料到指定的資料表裡面,插入資料完畢可以選擇是否要進行轉址。
|
|
|
357 |
#回傳的數值:
|
|
|
358 |
#$result["status"],爲查詢是否成功,若爲"true"則成功,若爲"false"則表示失敗了.
|
|
|
359 |
#$result["error"],錯誤訊息.
|
|
|
360 |
#$result["sql"],執行的sql語法.
|
|
|
361 |
#$result["function"],當前執行的涵式
|
|
|
362 |
#必填的參數:
|
|
|
363 |
$conf["dbAddress"]=$params["dbAddr"];#爲mysql-Server的位置
|
|
|
364 |
$conf["dbAccount"]=$params["dbUser"];#爲用於連入mysql-Server時要使用的帳號
|
|
|
365 |
$conf["selectedDataBaseName"]=$params["dbName"];#要選取的資料庫名稱
|
|
|
366 |
$conf["tableName"]=$params["dtName"];#爲要插入資料的資料表名稱
|
|
|
367 |
$conf["columnName"]=$params["cols"];#爲資料表的項目名稱,
|
|
|
368 |
#例如:$conf["columnName"]=array("columnName1","columnName2","columnName3",...);
|
|
|
369 |
$conf["insertValue"]=$params["vals"];#爲要插入度數值,
|
|
|
370 |
#例如:$conf["insertValue"]=array("insertValue1","insertValue2","insertValue3",...);
|
|
|
371 |
#可以省略的變數:
|
|
|
372 |
$conf["dbPassword"]=$params["dbPass"];#爲連線到mysql-Server時要使用的密碼,可省略,若省略則代表不使用密碼
|
| 17 |
liveuser |
373 |
#$conf["dbPort"],字串,爲連線到mysql-Server時要使用的port,可省略,若省略則代表用預設的 3306 port.
|
|
|
374 |
$conf["dbPort"]=$params["dbPort"];
|
| 1 |
liveuser |
375 |
#參考資料來源:
|
|
|
376 |
#http://www.javaworld.com.tw/jute/post/view?bid=21&id=173738&sty=1
|
|
|
377 |
$insertData=db::insertData($conf);
|
|
|
378 |
unset($conf);
|
|
|
379 |
|
| 349 |
liveuser |
380 |
#函式說明:
|
|
|
381 |
#撰寫log
|
|
|
382 |
#回傳結果:
|
|
|
383 |
#$result["status"],狀態,"true"或"false".
|
|
|
384 |
#$result["error"],錯誤訊息陣列.
|
|
|
385 |
#$result["function"],當前函式的名稱.
|
|
|
386 |
#$result["argu"],使用的參數.
|
|
|
387 |
#必填參數:
|
|
|
388 |
#$conf["path"],log檔案的路徑與名稱.
|
|
|
389 |
$conf["path"]=$logFile;
|
|
|
390 |
#$conf["content"],字串,要寫的內容.
|
|
|
391 |
$conf["content"]=json_encode($insertData).PHP_EOL;
|
|
|
392 |
#$conf["fileArgu"],字串,php變數__FILE__的內容,亦即該檔案在檔案系統的絕對路徑
|
|
|
393 |
$conf["fileArgu"]=__FILE__;
|
|
|
394 |
#可省略參數:
|
|
|
395 |
#$conf["rewrite"],預設為"false",接續寫入;反之"true"代表重新寫入.
|
|
|
396 |
#$conf["rewrite"]="false";
|
|
|
397 |
#參考資料:
|
|
|
398 |
#無.
|
|
|
399 |
#備註:
|
|
|
400 |
#無.
|
|
|
401 |
$record=logs::record($conf);
|
|
|
402 |
unset($conf);
|
|
|
403 |
|
|
|
404 |
#如果寫log 失敗
|
|
|
405 |
if($record["status"]==="false"){
|
|
|
406 |
|
|
|
407 |
#印出訊息
|
|
|
408 |
echo json_encode($record);
|
|
|
409 |
|
|
|
410 |
#結束執行
|
|
|
411 |
exit;
|
|
|
412 |
|
|
|
413 |
}#if end
|
|
|
414 |
|
| 17 |
liveuser |
415 |
#印出結果
|
|
|
416 |
echo json_encode($insertData);
|
| 1 |
liveuser |
417 |
|
|
|
418 |
?>
|