class.CSVHandler.php 0.91

© 2005 by andreas mueller hugo-at-v17-dot-de

What it does:

Retrieve and edit data from csv-files
this can be useful as a friendly replacement for small hosting without Database Support or just for q'n'd applications covering only one data table where there's no need to have full database support.

What it requires:

You only need class.CSVHandler.php and a datafile in a "delimited" format with headers for column names.
Any character can be used as delimiter. These files can be created or changed with a text editor, but programs like excel and the like can handle them as well.
This is what these files look like:

record;id;address;Town;Phone
103;Bopfingen City;Hauptstr. 26;73441 Bopfingen;07362 / 6393
106;Aalen (Ostalbcenter);Wilhelm-Merz-Straße 41;73430 Aalen;07361 / 36734

The first line contains the field names that identify Data.

Usage:

function CSVHandler($Filename, $Separator, $KeyFieldName) The constructor:
Use any single character as Separator, the KeyFieldName designates the Field that will be used as internal reference. In EditMode, the Key Field cannot be altered.
array $result=Select($needle,[$column]) To retrieve only data that contain $needle. If $column is specified, only those records that contain $needle in $column are returned in $result.
array $result=GetValues($field) Will return all values in the specified column in $result
function ListAll() Prints a simple table containing all data (Example in list.php)
function Edit(); Prints a complete Editing Table for all Data (Example in edit.php)
function Update($key,$data) for updating the record $key. $Data is a nemed array, only fields in $data will be updated, and only if that fieldname exists in the DataFile.
function Add($key,$data) adds a record $key with the contents of $data likewise.
function Delete($key) removes record $key form the datafile.