Abstract
After reading this chapter you should be able to:
-
understand issues relating to data cleaning
-
use PHP to take data stored in a text file, clean it and convert it to a database table
-
export data from a database table to a text file for archive purposes
-
restore a database table from a backup held as a text file.
Access this chapter
Tax calculation will be finalised at checkout
Purchases are for personal use only
Notes
- 1.
Note that the first item after the opening bracket following VALUES is an empty string. This is a placeholder for the value of the auto_increment field ind. When the INSERT operation takes place the value inserted will not be an empty string but the next integer in sequence.
- 2.
One further point to note, which is not an error but a potential cause of confusion, is that there were six embedded spaces in the date Aug 24 but only one appears in the displayed table. All six spaces are present in the database table mytable2 itself, but displaying them in a webpage makes them subject to the general HTML principle that any number of spaces and newline characters are displayed as a single space.
- 3.
This is an extended version of the explode function discussed previously. It has a third argument, in this case the number 2. The reason for this will be explained in Sect. 16.5 at the end of this chapter.
- 4.
The handling of $day shows PHP's flexibility when using numerical and string data together. Variable $day has a string value, say '8' and yet it can be compared with the number 10 as if it were the number 8. As 8 is smaller than 10 we prefix a zero to $day, making the string '08'. (If instead we were to compare a $day value of '8' with the string '10', $day would be considered larger, which is definitely not what we want.)
Author information
Authors and Affiliations
Rights and permissions
Copyright information
© 2015 Springer International Publishing Switzerland
About this chapter
Cite this chapter
Bramer, M. (2015). PHP in Action: Converting Data between Text Files and Database Tables. In: Web Programming with PHP and MySQL. Springer, Cham. https://doi.org/10.1007/978-3-319-22659-0_16
Download citation
DOI: https://doi.org/10.1007/978-3-319-22659-0_16
Publisher Name: Springer, Cham
Print ISBN: 978-3-319-22658-3
Online ISBN: 978-3-319-22659-0
eBook Packages: Computer ScienceComputer Science (R0)