Writing a PHP GetHandler for the Combo
First we set up our PHP page by including the Nitobi XML API (nitobi.xml.php) which is included.
The following code snippets will connect to a database and output 4 columns of xml data. You can output as many columns as you like and you need only use the ones you want in the ComboBox. See the bottom of this page for the corresponding Combo Tag.
<?php
require("nitobi.xml.php");
Next we set up our database and perform our query.
$accessDB = dirname(__FILE__) . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "data.mdb";
$strConn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=$accessDB;USER ID=;PASSWORD=;";
$objConn = new COM("ADODB.Connection");
$recordSet = new COM("ADODB.RecordSet");
$objConn->ConnectionString = $strConn;
$objConn->Open();
$newQuery = "SELECT * FROM tblCustomers";
$recordSet = $objConn->Execute($newQuery);
Now we create the EBAGetHandler.
$getHandler = new EBAGetHandler();
Now we loop through our recordset .
while (!$recordSet->EOF)
{
$record = New EBARecord($recordSet->Fields[0]->Value);
$record->add("CustomerName", $recordSet->Fields[1]->Value);
$record->add("CustomerAddress", $recordSet->Fields[2]->Value);
$record->add("CustomerEmail", $recordSet->Fields[3]->Value);
$record->add("CustomerPhone", $recordSet->Fields[4]->Value);
$getHandler->add($record);
$recordSet->MoveNext();
}
Finally, we output the XML stream to the client.
$getHandler->CompleteGet();
$recordSet->Close();
$objConn->Close();
?>
Here is the entire code sample:
require("nitobi.xml.php"); $accessDB = dirname(__FILE__) . DIRECTORY_SEPARATOR . "data" . DIRECTORY_SEPARATOR . "data.mdb"; $strConn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=$accessDB;USER ID=;PASSWORD=;"; $objConn = new COM("ADODB.Connection"); $recordSet = new COM("ADODB.RecordSet"); $objConn->ConnectionString = $strConn; $objConn->Open(); $newQuery = "SELECT * FROM tblCustomers"; $recordSet = $objConn->Execute($newQuery); $getHandler = new EBAGetHandler(); while (!$recordSet->EOF) { $record = New EBARecord($recordSet->Fields[0]->Value); $record->add("CustomerName", $recordSet->Fields[1]->Value); $record->add("CustomerAddress", $recordSet->Fields[2]->Value); $record->add("CustomerEmail", $recordSet->Fields[3]->Value); $record->add("CustomerPhone", $recordSet->Fields[4]->Value); $getHandler->add($record); $recordSet->MoveNext(); } $getHandler->CompleteGet(); $recordSet->Close(); $objConn->Close();
page_revision: 1, last_edited: 1224712280|%e %b %Y, %H:%M %Z (%O ago)