tran_text.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. include "./config.php";
  3. include "./_pdo.php";
  4. if (isset($_POST["album"])) {
  5. $album = $_POST["album"];
  6. } else {
  7. echo "no album";
  8. exit;
  9. }
  10. if (isset($_POST["data"])) {
  11. $data = $_POST["data"];
  12. } else {
  13. echo "no data";
  14. exit;
  15. }
  16. $log = "";
  17. $db_file = _FILE_DB_RESRES_INDEX_;
  18. PDO_Connect("$db_file");
  19. $query = "select * from 'album' where id='$album'";
  20. $Fetch = PDO_FetchAll($query);
  21. $iFetch = count($Fetch);
  22. if ($iFetch > 0) {
  23. if ($Fetch[0]["type"] == "translate") {
  24. $tocHtml = "";
  25. //打开翻译数据文件
  26. $db_file = $dir_appdata . $Fetch[0]["file"];
  27. PDO_Connect("$db_file");
  28. // 开始一个事务,关闭自动提交
  29. $PDO->beginTransaction();
  30. $query = "UPDATE 'data' SET 'text' = ? WHERE paragraph = ?";
  31. $stmt = $PDO->prepare($query);
  32. $dighest_par_array = str_getcsv($data, "#");
  33. foreach ($dighest_par_array as $value) {
  34. $one_recorder = str_getcsv($value, "@");
  35. if (count($one_recorder) >= 4) {
  36. $newData = array($one_recorder[3], $one_recorder[2]);
  37. $log .= "par:" . $one_recorder[2];
  38. $stmt->execute($newData);
  39. }
  40. }
  41. // 提交更改
  42. $PDO->commit();
  43. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  44. $error = PDO_ErrorInfo();
  45. echo "error - $error[2] <br>";
  46. } else {
  47. echo count($dighest_par_array) . "个段落被修改";
  48. }
  49. }
  50. }