Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to File Processing with PHP - Part 2 Indexed Files.

Similar presentations


Presentation on theme: "Introduction to File Processing with PHP - Part 2 Indexed Files."— Presentation transcript:

1 Introduction to File Processing with PHP - Part 2 Indexed Files

2 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.

3 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

4 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

5 The PHP filesystem functions http://us2.php.net/manual/en/ref.filesystem. php http://us2.php.net/manual/en/ref.filesystem. php

6 A C-like subset fopen – http://us2.php.net/manual/en/function.fopen.php http://us2.php.net/manual/en/function.fopen.php fgets – http://us2.php.net/manual/en/function.fgets.php http://us2.php.net/manual/en/function.fgets.php fwrite – http://us2.php.net/manual/en/function.fwrite.php http://us2.php.net/manual/en/function.fwrite.php fclose – http://us2.php.net/manual/en/function.fclose.php http://us2.php.net/manual/en/function.fclose.php

7 To Open a File for Processing resource fopen ( string $filename, string $mode [, bool $use_include_path = false [, resource $context ]] )

8 Mode Codes modeDescription 'r'Open for reading only; place the file pointer at the beginning of the file. 'r+'Open for reading and writing; place the file pointer at the beginning of the file. 'w' Open for writing only; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. 'w+' Open for reading and writing; place the file pointer at the beginning of the file and truncate the file to zero length. If the file does not exist, attempt to create it. 'a' Open for writing only; place the file pointer at the end of the file. If the file does not exist, attempt to create it. 'a+' Open for reading and writing; place the file pointer at the end of the file. If the file does not exist, attempt to create it. 'x' Create and open for writing only; place the file pointer at the beginning of the file. If the file already exists, the fopen() call will fail by returning FALSE and generating an error of level E_WARNING. If the file does not exist, attempt to create it. This is equivalent to specifying O_EXCL|O_CREAT flags for the underlying open(2)system call. 'x+'Create and open for reading and writing; otherwise it has the same behavior as 'x'.

9 Read a string from a file string fgets ( resource $handle [, int $length ] )

10 Write a string to a file int fwrite ( resource $handle, string $string [, int $length ] )

11 Close a file to processing bool fclose ( resource $handle )

12 Test if a file is at the end bool feof ( resource $handle )

13 Move the file pointer int fseek ( resource $handle, int $offset [, int $w hence = SEEK_SET ] )

14 Read a string string fread ( resource $handle, int $length )

15 Read an entire file array file ( string $filename [, int $flags = 0 [, resource $context ]] )

16 Read an entire file string file_get_contents ( string $filename [, boo l $use_include_path = false [, resource $context [, int $offset = - 1 [, int $maxlen ]]]] )

17 Write to a file int file_put_contents ( string $filename, mixed $data [, int $flags = 0 [, resource $context ]] )mixed


Download ppt "Introduction to File Processing with PHP - Part 2 Indexed Files."

Similar presentations


Ads by Google