180 likes | 294 Views
Introduction to File Processing with PHP - Part 2 Indexed Files. 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.
E N D
Introduction to File Processing with PHP - Part 2 Indexed Files
Review of Course Outcomes 1. Implement file reading and writing programs using PHP. 2. Identify file access schemes, including: sequentialfile 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.
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
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
The PHP filesystem functions • http://us2.php.net/manual/en/ref.filesystem.php
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.php
To Open a File for Processing resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )
Read a string from a file string fgets ( resource $handle [, int $length ] )
Write a string to a file intfwrite ( resource $handle , string $string [, int $length ] )
Close a file to processing boolfclose ( resource $handle )
Test if a file is at the end boolfeof ( resource $handle )
Move the file pointer intfseek ( resource $handle , int $offset [, int $whence = SEEK_SET ] )
Read a string string fread ( resource $handle , int $length )
Read an entire file array file ( string $filename [, int $flags = 0 [, resource $context ]] )
Read an entire file string file_get_contents ( string $filename [, bool $use_include_path = false [, resource $context [, int $offset = -1 [, int $maxlen ]]]] )
Write to a file intfile_put_contents ( string $filename , mixed $data [, int $flags = 0 [, resource $context ]] )