020 555 1111
  • Old fashion, modular, procedural PHP plus some scaffolding techniques to allow it to mimic MVC simplicity.
  • A quick reference to help you find in PHP maze what needs to be done and how to do it.
  • Learn a PHP Object Oriented Programming by building a live discussion forum application.
  • MVC - Model View Controller - real life, easy reference and application.
This product has options, take a look at them and select ones you like the most.
Options are displayed under image section.
Top » XML

Create XML using PDO db fetch and XMLWriter
[XMLWriter example]

A nice idea to create large XML

//db connection - does not require try/catch, as it is handled by global exception handler
$dbh = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''));
$dbh->exec("SET CHARACTER SET utf8");
$sql = 'SELECT cn, iso_2, iso_3 FROM ct WHERE id < 5';
$sth = $dbh->prepare($sql);
$sth->bindColumn('cn', $cn, PDO::PARAM_STR);
$sth->bindColumn('iso_2', $iso_2, PDO::PARAM_STR);
$sth->bindColumn('iso_3', $iso_3, PDO::PARAM_STR);
$result = $sth->fetch();

$xmlWriter = new XMLWriter();
$xmlWriter->startDocument('1.0', 'UTF-8');

while ($result = $sth->fetch()) {
    $xmlWriter->writeElement('name', $cn);
    $xmlWriter->writeElement('iso2', $iso_2);
    $xmlWriter->writeElement('iso3', $iso_3);
// Final flush to make sure we haven't missed anything
file_put_contents('example.xml', $xmlWriter->flush(true));



        <name>American Samoa</name>