<?php
$cn = mysqli_connect("localhost","root","","agpapp");
//include('config.php');
header('content-type:text/xml');
//
$table_id = 'application';
$dbresult = mysqli_query($cn, "SELECT id, fullname, mobileno FROM _application where id<11");
$doc = new DomDocument('1.0');
$root = $doc->createElement('home_automation');
$root = $doc->appendChild($root);
$num = mysqli_num_rows($dbresult);
$root->setAttribute('total',$num);
if($num)
{
$i=1;
while($row = mysqli_fetch_assoc($dbresult))
{
$occ = $doc->createElement($table_id);
$occ = $root->appendChild($occ);
foreach ($row as $fieldname => $fieldvalue)
{
$child = $doc->createElement($fieldname);
$child = $occ->appendChild($child);
if($fieldname == 'img')
$value = $doc->createTextNode("http://e-megha.electronicbits.in/img/icon/".$fieldvalue);
else $value = $doc->createTextNode($fieldvalue);
$value = $child->appendChild($value);
}
$i++;
}
}
else
{
}
$xml_string = $doc->saveXML();
echo $xml_string;
// validate @ http://www.w3schools.com/xml/xml_validator.asp
?>
<?php
// https://developer.decibel.net/sample-code-rest-php
<?php
$service_url = 'http://localhost/ws/xml.php';
$curl = curl_init($service_url);
$curl_post_data = array(
"user_id" => 42,
"emailaddress" => 'manniru@gmail.com',
);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curl_post_data);
$curl_response = curl_exec($curl);
curl_close($curl);
$xml = new SimpleXMLElement($curl_response);
print($xml);
?>
<?php
header("Content-Type:application/json");
$cn = mysqli_connect("localhost","root","","agpapp");
// sqlite to array
function comb() {
$comb = array();
$db = new SQLite3('db.sqlite');
$results = $db->query('SELECT * FROM _combinations');
while ($row = $results->fetchArray()) {
$comb[$row[0]] = $row[1];
}
$db->close();
return $comb;
}
$return_arr = array();
$fetch = mysqli_query($cn, "SELECT * FROM _application WHERE id<11");
while ($row = mysqli_fetch_array($fetch, MYSQL_ASSOC)) {
$row_array['id'] = $row['id'];
$row_array['fullname'] = $row['fullname'];
$row_array['mobileno'] = $row['mobileno'];
array_push($return_arr,$row_array);
}
echo json_encode($return_arr);
// validate @ http://jsonlint.com/
?>