tran_text.php 1.3 KB

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