Advertisement
Guest User

Untitled

a guest
Jun 15th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.25 KB | None | 0 0
  1. Файл конфигурации:
  2. <?xml version="1.0" encoding="WINDOWS-1251"?>
  3. <config>
  4. <host>localhost</host>
  5. <login>postgres</login>
  6. <password>11asdf00</password>
  7. <bd>aud</bd>
  8. <port>5433</port>
  9. <tablebd>naud</tablebd>
  10. <field namebd="id" value=""/>
  11. <field namebd="name" value=""/>
  12. <field namebd="capacity" value=""/>
  13. <field namebd="department" value=""/>
  14. <field namebd="flag" value="0"/>
  15. <field namebd="building">
  16. <value value="1" name="ГУК"/>
  17. <value value="2" name="УЛК"/>
  18. <value value="3" name="Э"/>
  19. </field>
  20. </config>
  21.  
  22. =======================================================================================================================================
  23. =======================================================================================================================================
  24. =======================================================================================================================================
  25.  
  26. ПХП код:
  27. $config=simplexml_load_file("config.xml");
  28. $host_bd=$config->host;
  29. $login_bd=$config->login;
  30. $password_bd=$config->password;
  31. $port_bd=$config->port;
  32. $table_bd=$config->tablebd;
  33. $db_name=$config->bd;
  34. $field_id=$config->xpath("//field[@namebd='id']");
  35. $field_name=$config->xpath("//field[@namebd='name']");
  36. $field_capacity=$config->xpath("//field[@namebd='capacity']");
  37. $field_department=$config->xpath("//field[@namebd='department']");
  38. $field_building=$config->xpath("//field[@namebd='building']");
  39. $field_flag=$config->xpath("//field[@namebd='flag']");
  40.  
  41. $dbconn = pg_connect("host=$host_bd port=$port_bd dbname=$db_name user=$login_bd password=$password_bd ")
  42. or die('Could not connect: ' . pg_last_error());
  43.  
  44. $module_node = $page->appendChild(new DOMElement('module')); //здесь стоит создать тег этого модуля
  45.  
  46. $mode = isset($_module_vars[1]) ? $_module_vars[1] : 'default';
  47.  
  48. if($mode==search)
  49. {
  50. //$page->setAttribute('mode','search');
  51. $request='';
  52. print "<pre>";
  53. //print_r($config->field);
  54. foreach($config->field as $fieldname => $v)
  55. print_r($v);
  56. print_r($config);
  57. die();
  58. foreach($config->field as $fieldname => $v)
  59. {
  60. if(isset($_GET[$fieldname]))
  61. {
  62. //print "Q";
  63. if(!$request) $request.=' AND ';
  64. $request='"'.$fieldname.'"="'.$_GET[$fieldname].'"';
  65. }
  66. }
  67. //print "SELECT * FROM $table_bd WHERE ".$request;
  68. //die();
  69. $res=pg_query($dbconn,"SELECT * FROM $table_bd WHERE ".$request);
  70. $auditors=pg_fetch_all($res);
  71.  
  72.  
  73. $audit_node=new DOMElement('audit');
  74. $module_node->appendChild($audit_node);
  75.  
  76. foreach($auditors as $aud)
  77. {
  78. $aud_node=new DOMElement('aud');
  79. $audit_node->appendChild($aud_node);
  80. $aud_node->setAttribute('id', $aud['id']);
  81. $aud_node->setAttribute('capacity', $aud['capacity']);
  82. $aud_node->setAttribute('name', $aud['name']);
  83. $aud_node->setAttribute('floor', $aud['floor']);
  84. $aud_node->setAttribute('bulding', $aud['bulding']);
  85. $aud_node->setAttribute('department', $aud['department']);
  86. $audit_node->setAttribute('flag', $aud['flag']);
  87. }
  88. }
  89.  
  90. =======================================================================================================================================
  91. =======================================================================================================================================
  92. =======================================================================================================================================
  93.  
  94. Результат выполнения куска кода print_r($config):
  95. SimpleXMLElement Object
  96. (
  97. [@attributes] => Array
  98. (
  99. [namebd] => id
  100. [value] =>
  101. )
  102.  
  103. )
  104. SimpleXMLElement Object
  105. (
  106. [@attributes] => Array
  107. (
  108. [namebd] => name
  109. [value] =>
  110. )
  111.  
  112. )
  113. SimpleXMLElement Object
  114. (
  115. [@attributes] => Array
  116. (
  117. [namebd] => capacity
  118. [value] =>
  119. )
  120.  
  121. )
  122. SimpleXMLElement Object
  123. (
  124. [@attributes] => Array
  125. (
  126. [namebd] => department
  127. [value] =>
  128. )
  129.  
  130. )
  131. SimpleXMLElement Object
  132. (
  133. [@attributes] => Array
  134. (
  135. [namebd] => flag
  136. [value] => 0
  137. )
  138.  
  139. )
  140. SimpleXMLElement Object
  141. (
  142. [@attributes] => Array
  143. (
  144. [namebd] => building
  145. )
  146.  
  147. [value] => Array
  148. (
  149. [0] => SimpleXMLElement Object
  150. (
  151. [@attributes] => Array
  152. (
  153. [value] => 1
  154. [name] => ГУК
  155. )
  156.  
  157. )
  158.  
  159. [1] => SimpleXMLElement Object
  160. (
  161. [@attributes] => Array
  162. (
  163. [value] => 2
  164. [name] => УЛК
  165. )
  166.  
  167. )
  168.  
  169. [2] => SimpleXMLElement Object
  170. (
  171. [@attributes] => Array
  172. (
  173. [value] => 3
  174. [name] => Р­
  175. )
  176.  
  177. )
  178.  
  179. )
  180.  
  181. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement