How To Output The Database Result To A Text File In Php Export


show more Outputting the database result to a text file provides you with in-depth training on Developer. Taught by David Powers as part of the Exporting Data to Files with PHP show less
please wait ...

Outputting the database result to a text file

Generating a plain text file from a database result requires only a dozen or so lines of code. You don't even need to create a copy of the file for the user to download. The PHP script streams it directly to the browser with the appropriate HTTP headers. In my editing program, I've opened cars_text.php. It's identical to the page we set up in chapter one, apart from the label on the submit button. The command on line two includes the database query.

I'm using the mySQLi version. Change it to the PDO version if you're using the SQLi database or any other database. The code we'll write in this page will be the same, whichever version you're using. If we scroll down to the bottom of the page, we can see that the name of the submit button is download, so we need to add a conditional statement to check for download in the post array when the submit button is clicked. So, let's go back above the doctype and add a new line after line two, then a conditional statement, if is set...

Outputting the database result to a text file
Video duration: 6m 32s 3h 42m Intermediate

Viewers:

Outputting the database result to a text file provides you with in-depth training on Developer. Taught by David Powers as part of the Exporting Data to Files with PHP

Subject:
Developer
Software:
PHP
Author:
please wait ...