setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->exec('SET CHARACTER SET utf8mb4'); $pdo->beginTransaction(); $sth = $pdo->prepare("INSERT INTO account (accounttype , accountid) VALUES (?, ?)"); $sth->bindValue(1, 'mf_vol_no'); $sth->execute(); $pdo->commit(); showSuccessMessage(); } catch (PDOException $e) { $pdo->rollBack(); echo "Transaction failed: " . $e->getMessage(); } } function showSuccessMessage() { $response = array('status' => 'success', 'message' => 'Data received and stored successfully'); header('Content-Type: application/json'); echo json_encode($response); } function showErrorMessage() { $response = array('status' => 'error', 'message' => 'Data received and stored error'); header('Content-Type: application/json'); echo json_encode($response); } function show400Error() { http_response_code(400); echo 'Invalid request data'; } function show405Error() { http_response_code(405); echo 'Method Not Allowed'; } function writePostIni($request_data) { // 讀取現有 ini 檔案的資料 $ini_file = 'addContract.ini'; $existing_data = parse_ini_file($ini_file, true); // 將接收到的資料加入現有資料 $timestamp = time(); $existing_data[$timestamp] = $request_data; // 將資料寫入 ini 檔 $ini_content = ''; foreach ($existing_data as $key => $value) { $ini_content .= "[$key]\n"; foreach ($value as $k => $v) { $ini_content .= "$k = \"$v\"\n"; } $ini_content .= "\n"; } file_put_contents($ini_file, $ini_content); } function writePostIniJson($request_data) { $txt_file = 'addContract.txt'; $txt = ""; $file = fopen($txt_file, 'a'); foreach($request_data as $k => $v){ $txt .= "$k = \"$v\"\n"; } fwrite($file, $txt . PHP_EOL); fclose($file); }