#native_company# #native_desc#
#native_cta#

WDDX Functions in PHP Page 6

By Jess M. Castagnetto
on July 30, 2000

The Data Generator (The WDDX Server)

This script shows how to construct a packet incrementally, and makes use of
database functions, as well as a histogram class (“class.hist”).
For the sake of this
example, we will search for zinc-histidine distances, and then construct an
array containing the resulting data set. In you own application, you may be
obtaining, for example, daily maximum temperatures, or closing stock prices,
or any quantitative value you would like to analyze.
wddx_generator.php3

<?php

require("class.hist");

// perform a search on the MDB looking for Zn-His distances

$link mysql_pconnect();

mysql_select_db("metallodb");

$query "select metal_lig_dist from ligand where metal='zn' and lig_symbol='his'";

$result mysql_query($query$link);

while (
$row mysql_fetch_row($result)) {

    
$data[] = $row[0];

}

?>



After we gathered the information, we use the “Histogram” class (contained in
“class.hist”), to allocate the data into 15 bins. Then, we retrieve these bins
and the data statistics (both being associative arrays) into the variables
$bins and $stats.

<?php

// generate a histogram with 15 bins

$hist = new Histogram($data15);

// get back the bins and statistics

$bins $hist->getBins();

$stats $hist->getStats();

?>



Finally we create the WDDX packet. For this example we have chosen to create
the packet incrementally. We could also have used a the function
wddx_serialize_vars to create and output the packet in one step.

<?php

//create a WDDX packet and serialize the histogram information.

$packet_id wddx_packet_start("Results of histogram calculation of Zn-His distances");

wddx_add_vars($packet_id"bins""stats");

$packet_out wddx_packet_end($packet_id);

echo 
$packet_out;

?>



That is all, we have done a SQL query, processed the data, and generated a
packet in less than 20 lines!

1
|
2
|
3
|
4
|
5
|
6
|
7
|
8