Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Файл конфигурации:
- <?xml version="1.0" encoding="WINDOWS-1251"?>
- <config>
- <host>localhost</host>
- <login>postgres</login>
- <password>11asdf00</password>
- <bd>aud</bd>
- <port>5433</port>
- <tablebd>naud</tablebd>
- <field namebd="id" value=""/>
- <field namebd="name" value=""/>
- <field namebd="capacity" value=""/>
- <field namebd="department" value=""/>
- <field namebd="flag" value="0"/>
- <field namebd="building">
- <value value="1" name="ГУК"/>
- <value value="2" name="УЛК"/>
- <value value="3" name="Э"/>
- </field>
- </config>
- =======================================================================================================================================
- =======================================================================================================================================
- =======================================================================================================================================
- ПХП код:
- $config=simplexml_load_file("config.xml");
- $host_bd=$config->host;
- $login_bd=$config->login;
- $password_bd=$config->password;
- $port_bd=$config->port;
- $table_bd=$config->tablebd;
- $db_name=$config->bd;
- $field_id=$config->xpath("//field[@namebd='id']");
- $field_name=$config->xpath("//field[@namebd='name']");
- $field_capacity=$config->xpath("//field[@namebd='capacity']");
- $field_department=$config->xpath("//field[@namebd='department']");
- $field_building=$config->xpath("//field[@namebd='building']");
- $field_flag=$config->xpath("//field[@namebd='flag']");
- $dbconn = pg_connect("host=$host_bd port=$port_bd dbname=$db_name user=$login_bd password=$password_bd ")
- or die('Could not connect: ' . pg_last_error());
- $module_node = $page->appendChild(new DOMElement('module')); //здесь стоит создать тег этого модуля
- $mode = isset($_module_vars[1]) ? $_module_vars[1] : 'default';
- if($mode==search)
- {
- //$page->setAttribute('mode','search');
- $request='';
- print "<pre>";
- //print_r($config->field);
- foreach($config->field as $fieldname => $v)
- print_r($v);
- print_r($config);
- die();
- foreach($config->field as $fieldname => $v)
- {
- if(isset($_GET[$fieldname]))
- {
- //print "Q";
- if(!$request) $request.=' AND ';
- $request='"'.$fieldname.'"="'.$_GET[$fieldname].'"';
- }
- }
- //print "SELECT * FROM $table_bd WHERE ".$request;
- //die();
- $res=pg_query($dbconn,"SELECT * FROM $table_bd WHERE ".$request);
- $auditors=pg_fetch_all($res);
- $audit_node=new DOMElement('audit');
- $module_node->appendChild($audit_node);
- foreach($auditors as $aud)
- {
- $aud_node=new DOMElement('aud');
- $audit_node->appendChild($aud_node);
- $aud_node->setAttribute('id', $aud['id']);
- $aud_node->setAttribute('capacity', $aud['capacity']);
- $aud_node->setAttribute('name', $aud['name']);
- $aud_node->setAttribute('floor', $aud['floor']);
- $aud_node->setAttribute('bulding', $aud['bulding']);
- $aud_node->setAttribute('department', $aud['department']);
- $audit_node->setAttribute('flag', $aud['flag']);
- }
- }
- =======================================================================================================================================
- =======================================================================================================================================
- =======================================================================================================================================
- Результат выполнения куска кода print_r($config):
- SimpleXMLElement Object
- (
- [@attributes] => Array
- (
- [namebd] => id
- [value] =>
- )
- )
- SimpleXMLElement Object
- (
- [@attributes] => Array
- (
- [namebd] => name
- [value] =>
- )
- )
- SimpleXMLElement Object
- (
- [@attributes] => Array
- (
- [namebd] => capacity
- [value] =>
- )
- )
- SimpleXMLElement Object
- (
- [@attributes] => Array
- (
- [namebd] => department
- [value] =>
- )
- )
- SimpleXMLElement Object
- (
- [@attributes] => Array
- (
- [namebd] => flag
- [value] => 0
- )
- )
- SimpleXMLElement Object
- (
- [@attributes] => Array
- (
- [namebd] => building
- )
- [value] => Array
- (
- [0] => SimpleXMLElement Object
- (
- [@attributes] => Array
- (
- [value] => 1
- [name] => ГУК
- )
- )
- [1] => SimpleXMLElement Object
- (
- [@attributes] => Array
- (
- [value] => 2
- [name] => УЛК
- )
- )
- [2] => SimpleXMLElement Object
- (
- [@attributes] => Array
- (
- [value] => 3
- [name] => Р
- )
- )
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement