From the course: PHP: Exporting Data to Files

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Outputting the database result as a .odt file

Outputting the database result as a .odt file - PHP Tutorial

From the course: PHP: Exporting Data to Files

Start my 1-month free trial

Outputting the database result as a .odt file

Now that we've created the template, and converted its main content file into an XSLT style sheet, we can use the OpenDoc class to generate and download an Open Document Text file. So make sure that you've got the OpenDoc class definition in your testing site. The class expects an XML string, so we'll also use the XML class to convert the database result. That means you need both Xml and Base.php in your testing site. You also need the Psr4Autoloader. This is flowers_odt.php. We'll use this file to create the download. The code at the top of the page includes the auto loader and then registers the foundation PHP namespace. Lines eight and nine import the XML and OpenDoc classes with the use operator, and line 11 includes the database result. I'm using the PDO version. If you're using MySQL, change PDO to mySQLI. All the code needs to go inside the triblock beginning on line 14. In the previous chapter we used the XML class to save a file to disc, and create a download file. This time,…

Contents