php - How to send and receive a xml to another computer -


i have 2 computers, comp 1 branch 1 , comp 2 main branch. in comp 1 have generated xml of database query using php.

`<?php header ("content-type:text/xml"); //database configuration $config['mysql_host'] = "localhost"; $config['mysql_user'] = "root"; $config['mysql_pass'] = "donnaluz"; $config['db_name']    = "global89_branch1"; $config['table_name'] = "branchsales";  //connect host mysql_connect($config['mysql_host'],$config['mysql_user'],$config['mysql_pass']); //select database @mysql_select_db($config['db_name']) or die( "unable select database"); $xml          = "<?xml version=\"1.0\" encoding=\"utf-8\"?>"; $root_element = $config['table_name']; $xml         = "<$root_element>"; /*$title = $doc->createelement("branchsales"); $title = $root->appendchild($title); $text = $doc->createtextnode("sales"); $text = $title->appendchild($text); */ //select items in table $sql = "select        branch.branchname,branchadmin.username,branchcomp.*,branchsales.*,days.day             branchsales,branch,branchadmin,branchcomp,days                                     branchsales.comp_id = branchcomp.comp_id                     , branchsales.admin_id = branchadmin.admin_id                     , branchsales.branch_id = branch.branch_id                     , branchsales.day_id = days.day_id";  $result = mysql_query($sql); if (!$result) { die('invalid query: ' . mysql_error()); }  if(mysql_num_rows($result)>0) { while($result_array = mysql_fetch_assoc($result)) {      $xml .= "<".$config['table_name'].">";    //loop through each key,value pair in row   foreach($result_array $key => $value)   {      //$key holds table column name      $xml .= "<$key>";       //embed sql data in cdata element avoid xml entity issues      $xml .= "<![cdata[$value]]>";        //and close element      $xml .= "</$key>";   }    $xml.="</".$config['table_name'].">";   }  //close root element $xml .= "</$root_element>";  //send xml header browser header ("content-type:text/xml");  echo $xml;  ?> 

` looks

<branchsales> <branchname>branch1</branchname> <username>garfield</username> <comp_id>1</comp_id> <admin_id>1</admin_id> <pcnum>1</pcnum> <starttime>09:00:00</starttime> <endtime>10:00:00</endtime> <totaltime>1:00:00</totaltime> <compcharge>10.00</compcharge> <id>1</id> <branch_id>1</branch_id> <day_id>5</day_id> <timeopened>8:00:00</timeopened> <timeclosed>23:00:00<timeclosed> 

blah blah.. on..

the thing is, want generated xml sent out comp 2, looking in table


|id|day |watcher |branch | current date | time opened | time closed | pc no. | on...

1 friday garfield branch1 29-03-13 8:00:00 23:00:00 1

this send code, not working

<? php $file = 'http://localhost/thesis/xmldailyrep.php'; $xml_builder = 'simplexml_load_file($file)';    $ch = curl_init("http://172.16.0.55/dailyrep1.php"); curl_setopt($ch, curlopt_httpheader, array('content-type:text/xml')); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields, $xml_builder); curl_setopt($ch, curlopt_followlocation, 0); curl_setopt($ch, curlopt_referer, "http://localhost/thesis/xmldailyrep.php"); curl_setopt($ch, curlopt_returntransfer, 1); $ch_result = curl_exec($ch); curl_close($ch); echo $ch_result;   ?>  

my receive code in comp 2 this

<?php /* * xml server. */ // use php://input raw $_post results. $xml_post = file_get_contents('xmldailyrep.php'); // if receive data, save it. if ($xml_post) { $xml_file = 'received_xml_' . date('y_m_d-h-i-s') . '.xml'; $fh       = fopen($xml_file, 'w') or die(); fwrite($fh, $xml_post); fclose($fh); // return, don't want cause loop processing code below. return; }  ?> 

please help

as far know, title. use frameworks work. apache camel, mule esb. if going large scale implementation.

if can tell whole story, easier you.

-guru @gnanagurus


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -