Using simpleXML instead of MySQL for applications that don’t use SQL


There is a large number of online applications which get data from the web and dynamically place it on a web page. One method to do this is PHP and MySQL but it is not the only method. Web developers should be able to offer more than one solution to a problem. For Dynamic web sites there are many methods and solutions all with pros and cons.

The advantages for MySQL is that one can search a large table of data. But for say client records themselves where the record is identified in the URL, there is no need to search and in fact searching would cost performance.  If these records contain a mix of data such as videos it is best that these records have a directory on the server instead of a record in a MySQL database. A simple CMS system for example does not benefit by calling a mySQL database to open the files on a server then search those files until it matches the record identified by the URL. Using the URL to directly identify the location of the record on the server reduces the work done by the server.

There are A few things PHP simplexml should have such as the ability to delete a node and to move a node from one XML file to another, just for starters. However, you can import SimpleXML files into dom and do all of the more complicated XML data manipulations … Here is an example code snipplet from a backend contact management program being developed. The number of records should not be more than one person can go through and respond to in a day. No sorting is required the records are maintained in FIFO, and the hope is that the leads become clients.

if ($makehot) {
foreach ($hotLeadsXML->request as $request) {
if( $request[‘id’] == $makehot) {

// get child + children to move.
$node = $request->asXML();
$nodeXML = simplexml_load_string($node);
$nodeDom = dom_import_simplexml($nodeXML);

// place the leads XML file with children.
$leadsDom = dom_import_simplexml($leadsXML);
$leadsDom->appendChild($leadsDom->ownerDocument->importNode($nodeDom, true));

// remove from the hot XML file
$dom=dom_import_simplexml($request);
$dom->parentNode->removeChild($dom);
}
}
$leadsXML->asXML(‘leads.xml’);
$hotLeadsXML->asXML(“hot.xml”);
}

So most XML based data sets programmed using simpleXML actually become a mix which still maintains the benefits of using XML data on a site.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: