Exporting Data to Files with PHP
Illustration by Don Barnett
Watching:

Connecting to different databases with PHP Data Objects (PDO)


From:

Exporting Data to Files with PHP

with David Powers

Video: Connecting to different databases with PHP Data Objects (PDO)

PDO, which stands for PHP Data Objects, is a database abstraction layer designed to overcome to problem of needing to use different functions, to communicate with each database system. The idea behind PDO is that you can switch a replication, to a different make of database without having to change your code. PDO supports a large number of databases. The main ones are listed here. So, in theory, you could switch from MySQL to Microsoft SQL Server or Firebird.
Expand all | Collapse all
  1. 5m 57s
    1. Welcome
      59s
    2. What you should know before watching this course
      2m 42s
    3. Using the exercise files
      2m 16s
  2. 28m 3s
    1. Loading the test data into a database
      4m 8s
    2. Querying the database with MySQL Improved
      6m 4s
    3. Connecting to different databases with PHP Data Objects (PDO)
      2m 26s
    4. Querying the database with PDO
      7m 47s
    5. Displaying the data in a webpage
      5m 1s
    6. Autoloading classes
      2m 37s
  3. 38m 47s
    1. Outputting the database result to a text file
      6m 32s
    2. Outputting the result as a CSV file
      6m 53s
    3. Introducing the Base class for file downloads
      4m 37s
    4. Using the Text class for greater control over output
      7m 20s
    5. Controlling CSV options with the Csv class
      6m 49s
    6. Saving the data to a local file
      6m 36s
  4. 51m 42s
    1. Introducing PHPExcel
      3m 31s
    2. Setting properties and defaults in PHPExcel
      6m 58s
    3. Setting the spreadsheet's print options
      5m 59s
    4. Populating an Excel spreadsheet with data
      7m 46s
    5. Formatting columns in PHPExcel
      5m 47s
    6. Downloading the data as a .xlsx file
      5m 18s
    7. Creating a spreadsheet in the OpenDocument format
      3m 4s
    8. Creating columns and headers in Fusonic SpreadsheetExport
      6m 27s
    9. Adding the data and downloading as a .ods file
      6m 52s
  5. 22m 10s
    1. Installing PHPRtfLite
      3m 27s
    2. Defining the page margins and the footer
      6m 55s
    3. Setting heading and paragraph styles
      5m 18s
    4. Adding the data and outputting a .rtf file
      6m 30s
  6. 16m 35s
    1. Understanding the basic process
      3m 52s
    2. Merging XML documents with XSLT
      4m 13s
    3. Preparing a directory to generate the output
      1m 48s
    4. Generating XML from a database result
      6m 42s
  7. 27m 17s
    1. Creating a .odt file to use as a template
      4m 29s
    2. Inspecting the structure of an OpenDocument text file
      2m 43s
    3. Extracting the main content file from a .odt document
      5m 2s
    4. Converting the main content file to XSLT
      8m 3s
    5. Outputting the database result as a .odt file
      7m 0s
  8. 29m 0s
    1. Creating a .docx file to use as a template
      3m 37s
    2. Extracting the main content file from a Word document
      5m 28s
    3. Formatting the main content file
      3m 38s
    4. Converting the main content file to XSLT
      6m 18s
    5. Outputting the database result as a .docx file
      6m 4s
    6. Offering a choice of download formats
      3m 55s
  9. 3m 25s
    1. Goodbye
      3m 25s

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now
please wait ...
Watch the Online Video Course Exporting Data to Files with PHP
3h 42m Intermediate Apr 11, 2014

Viewers: in countries Watching now:

Providing a file from a database in exactly the same format that's requested by the user is an extremely valuable technique. In this course, David Powers shows you how to export data from a database with PHP in a variety of formats, including rich text, CSV, Excel, Word, OpenOffice spreadsheets and documents, and even XML. He introduces tools like PHPExcel and PHPRtfLite that make the job of formatting the data (fonts, headers, columns, and all) easier to manage, and also shows how to embed nontext data like images in your exports.

Topics include:
  • Connecting to the database with PDO or MySQL Improved
  • Outputting data into a simple text or CSV file
  • Generating a spreadsheet
  • Creating columns and headers
  • Using a class to generate XML
  • Creating a page template
Subject:
Developer
Software:
PHP
Author:
David Powers

Connecting to different databases with PHP Data Objects (PDO)

PDO, which stands for PHP Data Objects, is a database abstraction layer designed to overcome to problem of needing to use different functions, to communicate with each database system. The idea behind PDO is that you can switch a replication, to a different make of database without having to change your code. PDO supports a large number of databases. The main ones are listed here. So, in theory, you could switch from MySQL to Microsoft SQL Server or Firebird.

In practice, it's not quite so straightforward. One of the main drawbacks, is that each database system tends to use its own dialect of structured query language. Full portability is practical only if your queries use core SQL syntax. Each database system relies on a dedicated PDO driver. Many servers have the drivers from MySQL and SQLite, but exact availability depends on your hosting company or server administrator.

You can check what your server supports by running php info. Some drivers are still experimental. You can check the current status in the PHP online documentation at this address. To communicate to the database using PDO you need to supply a database source name or DSN. This is simply a string that begins with a prefix, which identifies the PDO driver you want to use. In other words, the type of database you're connecting to. The prefix is followed by a colon and a series of name values pairs, separated by semicolons.

Let's take a look at a few examples. MySQL uses host for the server and dbname for the database. If you're connecting to MySQL on a non-standard port, you need to specify that as a separate name value pair. The DSN for SQLite3 is the prefix SQLite followed by a fully qualified path to the database file. The syntax for Microsoft Sequel server is very similar to MySQL, but is uses server instead of host and database instead of DB name.

You can check all the options for each PDO driver in the PHP documentation at the address shown here.

There are currently no FAQs about Exporting Data to Files with PHP.

 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Exporting Data to Files with PHP.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.