Hello All
I am uploading a code by which you can generate XML response from your database.
As you know the data can move on network in a particular format.
The two popular format are XML and JSON.
Then generated response can be parsed in any Application like Web App, Mobile App- Android or iPhone.
Most of the Market Captured Apps are working with such kind of concepts.
Let's start
Step-1: Install Your database server on your system -n I am using XAMPP as a tool to create
Database as well as server side script language(PHP)
Step-2: Create a database on your localhost by using phpmyadmin panel
Step-3: Create a table with some fields like i have Database named as mydb and table name is
myinfo as below mentioned
Step-4: Create a php file in htdocs folder of Xampp directory
I had created a new folder in htdocs named anddb - > xmlres.php file as
<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('mydb');
$sql = "SELECT * FROM myinfo ORDER BY id";
$res = mysql_query($sql);
$xml = new SimpleXMLElement('<info/>');
while ($row = mysql_fetch_assoc($res))
{
$track = $xml->addChild('personal');
$track->addChild('uid', $row['id']);
$track->addChild('first_name', $row['fname']);
$track->addChild('address', $row['address']);
}
Header('Content-type: text/xml');
print($xml->asXML());
?>
Step-5: Run your php file on the localhost the response will be like
I am uploading a code by which you can generate XML response from your database.
As you know the data can move on network in a particular format.
The two popular format are XML and JSON.
Then generated response can be parsed in any Application like Web App, Mobile App- Android or iPhone.
Most of the Market Captured Apps are working with such kind of concepts.
Let's start
Step-1: Install Your database server on your system -n I am using XAMPP as a tool to create
Database as well as server side script language(PHP)
Step-2: Create a database on your localhost by using phpmyadmin panel
Step-3: Create a table with some fields like i have Database named as mydb and table name is
myinfo as below mentioned
Step-4: Create a php file in htdocs folder of Xampp directory
I had created a new folder in htdocs named anddb - > xmlres.php file as
<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('mydb');
$sql = "SELECT * FROM myinfo ORDER BY id";
$res = mysql_query($sql);
$xml = new SimpleXMLElement('<info/>');
while ($row = mysql_fetch_assoc($res))
{
$track = $xml->addChild('personal');
$track->addChild('uid', $row['id']);
$track->addChild('first_name', $row['fname']);
$track->addChild('address', $row['address']);
}
Header('Content-type: text/xml');
print($xml->asXML());
?>
Step-5: Run your php file on the localhost the response will be like
**** How to fetch / parse this response in Android - check in my next upload ***
No comments:
Post a Comment