tran_text.php 1.5 KB

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