Review of Course Outcomes 1 Implement file reading and writing programs using PHP 2 Identify file access schemes including sequential file access direct file access ID: 461642
Download Presentation The PPT/PDF document "Introduction to File Processing with PHP" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
Introduction to File Processing with PHP
Slide2
Review of Course
Outcomes
1
. Implement file reading and writing programs using PHP.
2. Identify
file access schemes,
including:
sequential
file access
direct file access
indexed
sequential file access.
3. Describe file-sorting and file-searching techniques.
4. Describe data compression and encryption techniques.
5. Design a rational database using E-R modeling techniques.
6. Build a relational database.
7. Write database queries using SQL.
8. Implement a web-based relational database using MySQL. Slide3
File Structures
File Structures are
persistent
data structures
Files composed of records
Records composed of fields
Files can be viewed as tables
File
->
Table
Record
->
Row
Field
->
ColumnSlide4
File Organization
The
data
is stored as a collection of
files
. Each file is a sequence of
records.
A record is a sequence of
fields
.
One approach:
assume record size is fixed
each file has records of one particular type only
this
case is easiest to implement;
we will
consider
it furtherSlide5
Organization of Records in Files
Heap
– a record can be placed anywhere in the file where there is space
Sequential
– store records in sequential order,
perhaps based
on the value of the search key of each record
Indexing –
Keep two files, the Data File and an Index File and the data file. Index records hold file pointers of Data records
Hashing
– a hash function computed on some attribute of each record; the result specifies in which block of the file the record should be placedSlide6
Fixed-Length Records
Simple approach:
Store record
i
starting from byte
n
(
i
–
1), where
n
is the size of each record.Record access is simple but records may cross blocksModification: do not allow records to cross block boundariesWays to delete record i: move records i + 1, . . ., n to i, . . . , n – 1move record n to ido not move records, but mark deleted recordSlide7
Variable-Length Records
Variable-length records arise in database systems in several ways:
Storage of multiple record types in a file.
Record types that allow variable lengths for one or more fields such as strings
Record types that allow repeating fields (used in some older data models).
We won’t talk about VL recordsSlide8
Sequential File Organization
For sequential processing of entire file
Records ordered by a search-keySlide9
Sequential File Organization
Deletion – use pointer chains
Insertion –locate the position where the record is to be inserted
if there is free space insert there
if no free space, insert the record in an overflow block
In either case, pointer chain must be updated
Need to reorganize the file from time to time to restore sequential orderSlide10
The CRUD paradigm
Open the current version of a file
Process it using the CRUD operations
Create records
Retrieve records
Update records
Delete records
Output and close the new version of the fileSlide11
Implementing CRUD paradigm in PHP
Use PHP file functions
There a many of them
We will start with a simple subset that are similar to file functions used in C and in other C-based languagesSlide12
The PHP filesystem
functions
http://us2.php.net/manual/en/ref.filesystem.phpSlide13
A C-like subset
fopen
http://us2.php.net/manual/en/function.fopen.php
fgets
http://us2.php.net/manual/en/function.fgets.php
fwrite
http://us2.php.net/manual/en/function.fwrite.php
fclose
http://us2.php.net/manual/en/function.fclose.phpSlide14
Some PHP File Tutorials
http://www.tizag.com/phpT/files.php
http://php.about.com/od/advancedphp/ss/php_read_file_5.htm
http://www.codingunit.com/php-tutorial-file-handling