pc_publish.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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("sqlite:$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. }
  52. else{
  53. $count=count($arrInserString);
  54. $log.= "updata $count recorders. \r\n";
  55. }
  56. $PDO=null;
  57. $log.= "pdo close. \r\n";
  58. }
  59. }
  60. $myLogFile = fopen("updata_wbw.log", "w");
  61. fwrite($myLogFile, $log);
  62. fclose($myLogFile);
  63. echo("Successful");
  64. ?>