11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 38 • IMPORTING AND EXPORTING DATAwww.it-ebooks.info);total_cost DECIMAL(8,2) NOT NULLThis table is used to track basic sales information. Although it lacks many of the columns you mightfind in a real-world implementation, the additional detail is omitted in an attempt to keep the focus onthe concepts introduced in this chapter.Using Data DelimitationEven if you’re a budding programmer, you’re probably already quite familiar with software’s exactingdemands when it comes to data. All i’s must be dotted and all t’s must be crossed, with a singlemisplaced character enough to produce unexpected results. Therefore, you can imagine the issues thatmight arise when attempting to convert data from one format to another. Thankfully, a particularlyconvenient formatting strategy has become commonplace: delimitation.Information structures like database tables and spreadsheets share a similar conceptualorganization. These structures are typically conceptualized as consisting of rows and columns, each ofwhich is further broken down into cells. Therefore, you can convert between formats as long as youinstitute a set of rules for determining how the columns, rows, and cells are recognized. One of the mostimportant rules involves the establishment of a character or a character sequence which will be used as adelimiter, separating each cell within a row, and each row from the following row. For example, thesales table might be delimited in a format that separates each field by a comma and each row by anewline character:12309,45633,2010-12-19 01:13:42,22.04,5.67,27.71\n12310,942,2010-12-19 01:15:12,11.50,3.40,14.90\n12311,7879,2010-12-19 01:15:22,95.99,15.00,110.99\n12312,55521,2010-12-19 01:30:45,10.75,3.00,13.75\nOf course, the newline character would be invisible when viewing the file from within a text editor; Iam just displaying it here for reason of illustration. Many data import and export utilities, including<strong>MySQL</strong>’s, revolve around the concept of data delimitation.Importing DataIn this section, you’ll learn about the two built-in tools <strong>MySQL</strong> offers for importing delimited data setsinto a table: LOAD DATA INFILE and mysqlimport.■ Tip You might consider using the mysqlimport client in lieu of LOAD DATA INFILE when you need to createbatch imports executed from a cron job. This client was introduced in Chapter 27.720

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!