PHP
  Home arrow PHP arrow Page 8 - Data Exchange with XML, WDDX and PHP
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Mobile Linux 
App Generation ROI 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Data Exchange with XML, WDDX and PHP
By: Vikram Vaswani, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2001-09-13

    Table of Contents:
  • Data Exchange with XML, WDDX and PHP
  • The Wonderful World Of WDDX
  • Polly Wants A Cracker
  • Humbert Redfinch-Northbottom The Third, I Presume?
  • Old Friends And New
  • Hip To Be Square
  • The Truth Is Out There
  • Money Talks
  • Closing Time

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Data Exchange with XML, WDDX and PHP - Money Talks


    (Page 8 of 9 )

    Let's try another example, this one using WDDX to transmit five-day currency rate data to a requesting client. The client then uses this data to calculate an average rate for the past five days.

    Let's assume that the data is stored in the following database table:

    mysql> select * from currency; +--------+-------+-------+-------+-------+-------+ | symbol | mark1 | mark2 | mark3 | mark4 | mark5 | +--------+-------+-------+-------+-------+-------+ | GBP | 0.72 | 0.69 | 0.73 | 0.75 | 0.69 | | INR | 0.023 | 0.045 | 0.012 | 0.019 | 0.025 | | DZD | 0.01 | 0.009 | 0.015 | 0.011 | 0.01 | | CAD | 0.66 | 0.65 | 0.68 | 0.7 | 0.64 | | DEM | 0.43 | 0.44 | 0.43 | 0.42 | 0.42 | +--------+-------+-------+-------+-------+-------+ 5 rows in set (0.00 sec)
    The server script needs to get all five values and encode them as a WDDX packet.

    <? // server.php - output WDDX packet containing currency data// database parameters$hostname = "medusa";$user = "wddx_agent";$pass = "jser745mf";$database = "trends";// open connection to database$connection = mysql_connect($hostname, $user, $pass) or die ("Unable toconnect!");// get rates for last five days$query = "SELECT mark1, mark2, mark3, mark4, mark5 FROM currency WHEREsymbol = '$symbol'";$result = mysql_db_query($database, $query, $connection) or die ("Error inquery: $query. " . mysql_error());// add data to packetif (mysql_num_rows($result) > 0) { $mark = mysql_fetch_row($result); }mysql_close($connection);// print packetecho wddx_serialize_value($mark);?>
    Again, the array of five values is encoded as a WDDX packet, and sent to the requesting client, which decodes it and prints the data, together with an average of all five values.

    <? // client.php - connect to server, retrieve and decode WDDX packet// url of Web page$url = "http://medusa/server.php?symbol=$symbol";// read WDDX packet into string$package = join ('', file($url));// deserialize$rates = wddx_deserialize($package);?><html><head><basefont face="Verdana"></head><body><h3>Five-day currency trends for currency symbol <? echo $symbol; ?></h3><table border="1" cellspacing="3" cellpadding="3"><tr><td>Data pointer 1</td><td>Data pointer 2</td><td>Data pointer 3</td><td>Data pointer 4</td><td>Data pointer 5</td><td>Average</td></tr><tr><?$sum = 0;// print rate datafor($x=0; $x<5; $x++){ $sum = $sum + $rates[$x]; echo "<td>$rates[$x]</td>";}// calculate average$avg = $sum/5;echo "<td>$avg</td>";?></tr></table></body></html>
    Simple, huh?

    More PHP Articles
    More By Vikram Vaswani, (c) Melonfire


     

       

    PHP ARTICLES

    - Working With Different Namespaces in PHP 5
    - User Management Explained: Overview
    - Using Namespaces in PHP 5
    - Database Security: Guarding Against SQL Inje...
    - Building a Modular Exception Class in PHP 5
    - Database and Password Security for Web Appli...
    - Handling MySQL Data Set Failures in PHP 5
    - Building Site Registration for Web Applicati...
    - Intercepting Customized Exceptions in PHP 5
    - Securing Your Web Application Against Attacks
    - Sub Classing Exceptions in PHP 5
    - Authentication for Web Application Security
    - Building a Content Management System with Co...
    - Filters and Login Systems for Web Applicatio...
    - Working with the Email Class in Code Igniter





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT