2
0

pc_publish.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. include "./_pdo.php";
  3. include "config.php";
  4. $input = file_get_contents("php://input"); //
  5. //begin updata wbw database
  6. $log = "";
  7. $arrInserString = array();
  8. $xmlObj = simplexml_load_string($input);
  9. $dataBlock = $xmlObj->xpath('//block');
  10. foreach ($dataBlock as $block) {
  11. if ($block->info->type == "wbw") {
  12. $bookId = $block->info->book;
  13. $parNum = $block->info->paragraph;
  14. $author = $block->info->author;
  15. $language = $block->info->language;
  16. $edition = $block->info->edition;
  17. $db_file = $dir_palicannon_wbw . $bookId . "_wbw.db3";
  18. PDO_Connect("$db_file");
  19. $log .= "pdo open . $db_file \r\n";
  20. $query = "DELETE FROM \"main\" WHERE \"book\" = " . $PDO->quote($bookId) . " AND \"paragraph\" = " . $PDO->quote($parNum);
  21. $stmt = @PDO_Execute($query);
  22. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  23. $error = PDO_ErrorInfo();
  24. //print_r($error[2]);
  25. $log .= "error:" . $error[2] . " \r\n";
  26. break;
  27. }
  28. $log .= "pdo delete ok . $db_file \r\n";
  29. $arrInserString = array();
  30. $words = $block->data->xpath('word');
  31. foreach ($block->data->children() as $ws) {
  32. $log .= "word:$ws->pali \r\n";
  33. //foreach($words as $ws){
  34. //new recorder
  35. $params = array($ws->id, $ws->pali, $ws->real, $ws->type, $ws->gramma, $ws->mean, $ws->note, $ws->org, $ws->om, $ws->bmc, $ws->bmt, $ws->un, $ws->style, $ws->edition);
  36. $arrInserString[count($arrInserString)] = $params;
  37. }
  38. /* 开始一个事务,关闭自动提交 */
  39. $PDO->beginTransaction();
  40. $query = "INSERT INTO main ('id','wid','book','paragraph','word','real','type','gramma','mean','note','part','partmean','bmc','bmt','un','style','language','author','editor','revision','edition','subver','vri','sya','si','ka','pi','pa','kam') VALUES (null,?,'" . $bookId . "','$parNum',?,?,?,?,?,?,?,?,?,?,?,?,'" . $language . "','" . $author . "','','',?,'0','1','0','0','0','0','0','0')";
  41. $log .= "query $query \r\n";
  42. $stmt = $PDO->prepare($query);
  43. foreach ($arrInserString as $oneParam) {
  44. $stmt->execute($oneParam);
  45. }
  46. /* 提交更改 */
  47. $PDO->commit();
  48. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  49. $error = PDO_ErrorInfo();
  50. $log .= "error - $error[2] \r\n";
  51. } else {
  52. $count = count($arrInserString);
  53. $log .= "updata $count recorders. \r\n";
  54. }
  55. $PDO = null;
  56. $log .= "pdo close. \r\n";
  57. }
  58. }
  59. $myLogFile = fopen("updata_wbw.log", "w");
  60. fwrite($myLogFile, $log);
  61. fclose($myLogFile);
  62. echo ("Successful");