14
Introduction to File Processing with PHP

Introduction to File Processing with PHP

  • Upload
    edward

  • View
    70

  • Download
    0

Embed Size (px)

DESCRIPTION

Introduction to File Processing with PHP. 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. - PowerPoint PPT Presentation

Citation preview

Page 1: Introduction to File Processing with PHP

Introduction to File Processing with PHP

Page 2: Introduction to File Processing with PHP

Review of Course Outcomes

1. Implement file reading and writing programs using PHP.2. Identify file access schemes, including:

sequential file access direct file accessindexed 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.

Page 3: Introduction to File Processing with PHP

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 -> Column

Page 4: Introduction to File Processing with PHP

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 further

Page 5: Introduction to File Processing with PHP

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 placed

Page 6: Introduction to File Processing with PHP

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 blocks• Modification: do not allow records to cross block boundaries

• Ways to delete record i: • move records i + 1, . . ., n

to i, . . . , n – 1• move record n to i• do not move records, but

mark deleted record

Page 7: Introduction to File Processing with PHP

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 records

Page 8: Introduction to File Processing with PHP

Sequential File Organization• For sequential processing of entire file • Records ordered by a search-key

Page 9: Introduction to File Processing with PHP

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 order

Page 10: Introduction to File Processing with PHP

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 file

Page 11: Introduction to File Processing with PHP

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 languages

Page 12: Introduction to File Processing with PHP

The PHP filesystem functions

• http://us2.php.net/manual/en/ref.filesystem.php

Page 13: Introduction to File Processing with PHP

A C-like subset

• fopen – http://us2.php.net/manual/en/function.fopen.ph

p• fgets– http://us2.php.net/manual/en/function.fgets.php

• fwrite– http://us2.php.net/manual/en/function.fwrite.ph

p• fclose– http://us2.php.net/manual/en/function.fclose.ph

p

Page 14: Introduction to File Processing with PHP

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