flatfile
[ class tree: flatfile ] [ index: flatfile ] [ all elements ]

Class: Flatfile

Source Location: /flatfile.php

Class Overview


Provides simple but powerful flatfile database storage and retrieval


Variables

Methods



Class Details

[line 68]
Provides simple but powerful flatfile database storage and retrieval

Includes equivalents to SELECT * FROM table WHERE..., DELETE WHERE ... UPDATE and more. All files are stored in the $datadir directory, and table names are just filenames in that directory. Subdirectories can be used just by specifying a table name that includes the directory name.




[ Top ]


Class Variables

$datadir =

[line 78]

The directory to store files in.


Type:   string


[ Top ]



Class Methods


constructor Flatfile [line 80]

Flatfile Flatfile( )



[ Top ]

method addSchema [line 367]

void addSchema( string $fileregex, string $rowSchema)

Adds a schema definition to the DB for a specified regular expression

Schemas are optional, and are only used for automatically determining the comparison types that should be used when sorting and selecting.




Parameters:

string   $fileregex   A regular expression used to match filenames
string   $rowSchema   An array specifying the column types for data files that match the regex, using constants defined in flatfile_utils.php

[ Top ]

method deleteAll [line 307]

void deleteAll( string $tablename)

Delete all rows in a table



Parameters:

string   $tablename   The table to alter

[ Top ]

method deleteWhere [line 288]

void deleteWhere( string $tablename, $whereClause, object $whereClause.)

Deletes all rows in a table that match specified criteria



Parameters:

string   $tablename   The table to alter
object   $whereClause.   WhereClause object that will select rows to be deleted. All rows are deleted if $whereClause === NULL
   $whereClause  

[ Top ]

method getSchema [line 373]

void getSchema( $filename)

Retrieves the schema for a given filename



Parameters:

   $filename  

[ Top ]

method insert [line 232]

void insert( string $tablename, array $newRow)

Inserts a row in a table



Parameters:

string   $tablename   The table to insert data into
array   $newRow   The new row to add to the table

[ Top ]

method insertWithAutoId [line 209]

int insertWithAutoId( string $tablename, int $idField, array $newRow)

Inserts a row with an automatically generated ID

The autogenerated ID will be the highest ID in the column so far plus one. The supplied row should include all fields required for the table, and the ID field it contains will just be ignored




Tags:

return:  The newly assigned ID


Parameters:

string   $tablename   The table to insert data into
int   $idField   The index of the field which is the ID field
array   $newRow   The new row to add to the table

[ Top ]

method selectAll [line 90]

array selectAll( string $tablename)

Get all rows from a table



Tags:

return:  The table as an array of rows, where each row is an array of columns


Parameters:

string   $tablename   The table to get rows from

[ Top ]

method selectUnique [line 153]

array selectUnique( string $tablename, string $idField, string $id)

Select a row using a unique ID



Tags:

return:  The row of the table as an array


Parameters:

string   $tablename   The table to get data from
string   $idField   The index of the field containing the ID
string   $id   The ID to search for

[ Top ]

method selectWhere [line 116]

array selectWhere( string $tablename, object $whereClause, [mixed $limit = -1], [mixed $orderBy = NULL])

Selects rows from a table that match the specified criteria

This simulates the following SQL query:

   SELECT LIMIT $limit * FROM  $tablename
   WHERE $whereclause
   ORDER BY $orderBy [ASC | DESC] [, $orderBy2 ...]




Tags:

return:  The matching data, as an array of rows, where each row is an array of columns


Parameters:

string   $tablename   The table (file) to get the data from
object   $whereClause   Either a WhereClause object to do selection of rows, or NULL to select all
mixed   $limit   Specifies limits for the rows returned:
  • use -1 or omitted to return all rows
  • use an integer n to return the first n rows
  • use a two item array ($startrow, $endrow) to return rows $startrow to $endrow - 1 (zero indexed)
  • use a two item array ($startrow, -1) to return rows $startrow to the end (zero indexed)
mixed   $orderBy   Either an OrderBy object or an array of them, defining the sorting that should be applied (if an array, then the first object in the array is the first key to sort on etc). Use NULL for no sorting.

[ Top ]

method updateRowById [line 247]

void updateRowById( string $tablename, int $idField, array $updatedRow)

Updates an existing row using a unique ID



Parameters:

string   $tablename   The table to update
int   $idField   The index of the field which is the ID field
array   $updatedRow   The updated row to add to the table

[ Top ]

method updateSetWhere [line 264]

void updateSetWhere( string $tablename, array $newFields, WhereClause $whereClause)

Updates fields in a table for rows that match the provided criteria

$newFields can be a complete row or it can be a sparsely populated hashtable of values (where the keys are integers which are the column indexes to update)




Parameters:

string   $tablename   The table to update
array   $newFields   A hashtable (with integer keys) of fields to update
WhereClause   $whereClause   The criteria or NULL to update all rows

[ Top ]


Documentation generated on Sun, 25 Oct 2009 22:30:46 +0000 by phpDocumentor 1.4.3