Class FlatfileTools

Description

A class to manipulate flat-file databases

A useful class to manipulate flat-file databases. Supports multipule line endings for compactiblity with flat-file databases you made yourself with Windoze Notepad.

Located in /flatfiletools.lib.php (line 47)


	
			
Variable Summary
Array(string) $config
int $error
Method Summary
void add_line (Array(string) $data)
void add_line_raw (string $data)
void apply ()
void commit ()
Array(string) get_cols (int $col)
string get_field (int $row, int $col)
Array(string) get_line (int $line)
string get_line_raw (int $line)
Array(string) match_list_col (Array(string) $defn, int $row)
bool populate ()
void set_datafile (string $loc)
bool set_field (int $row, int $col, string $data)
void set_line (int $ln, Array(string) $data)
bool write ()
void _destroy_db (int $rand1, int $rand2, [ $data_to_replace_with = ""])
Variables
Array(string) $config (line 93)

Contains the list of configuration options This variable contains an array of configuration options, loaded by default from config.ini. The list is specified below:

  • config['line'] = The line ending to use. Leave at unix or else.
  • config['div'] = The column divider to use. Default is "|". You can adjust this to use your existing flatfile databases.

int $error (line 83)

Contains the current error code

This variable contains the current error code. The error codes are as specified in the list below:

  • 0 - Success - No error
  • 1 - FileNotFound - The specified datafile was not found
  • 2 - InvalidIndex - The specified row/column does not exist
  • 3 - WritingError - An error occoured while the datafile was written to disk
  • 4 - ExplosionError - The program blew up during the explosion process

Methods
add_line (line 318)

Adds a row/line to the flatfile database

Adds a new row/line in an array of columns. You can call get_number_of_cols to get the number of columns. To get the number of columns starting with zero instead of one, use get_number_of_cols_zero instead. To add a raw line, use add_line_raw.

void add_line (Array(string) $data)
  • Array(string) $data: - The row/line to add
add_line_raw (line 333)

Adds a row/line to the flatfile database in raw format

Adds a new row/line in an array of columns. You can call get_number_of_cols to get the number of columns. To get the number of columns starting with zero instead of one, use get_number_of_cols_zero instead.

void add_line_raw (string $data)
  • string $data: - The row/line to add, in raw format
apply (line 403)

Applies all changes

Applies all the changes made with the set* family of functions. It calles the methods commit and write to apply all changes in the buffers and applies the changes to disk.

void apply ()
commit (line 164)

Commits the changes so write can process them

Commits the changes so the buffers to write can proccess them and make the changes you made using set_field and set_line. Always rembember to call this method before you write to your file.

void commit ()
get_cols (line 360)

Get the specified columns in the database

Gets the specified column in the database for all the rows.

  • return: - The return columns
Array(string) get_cols (int $col)
  • int $col: - The column ID
get_field (line 381)

Gets a specified field from the database.

Gets a specified field from the database using the specified row and column

  • return: - The data in the specified field
string get_field (int $row, int $col)
  • int $row: - The field's row
  • int $col: - The column of the field
get_line (line 276)

Retrieves the specified line/row

Retrieves the line/row specified in an array. To get the raw data for the line, call commit followed by get_line_raw.

  • return: - An array of all the columns in that row
Array(string) get_line (int $line)
  • int $line: - The row/line to retrieve. Line 0 gets the column definitions.
get_line_raw (line 300)

Retrieves the specified row, in raw format

Retrieves the specified row from the buffers. Don't forget to call commit before running this method. See get_line for more details.

  • return: - A string (raw format with the column dividers) with all columns
string get_line_raw (int $line)
  • int $line: - The row to retrieve, in raw format. Line 0 gets the raw column definitions.
get_number_of_cols (line 454)

Gets the number of columns in the database

Gets the number of columns in the database using the column descriptor.

  • return: - The number of columns
int get_number_of_cols ()
get_number_of_cols_zero (line 466)

Gets the number of columns in the database starting from zero

Alias of get_number_of_cols

  • 1.

  • return: - The number of columns, subtracted by 1
int get_number_of_cols_zero ()
get_number_of_lines (line 441)

Gets the number of rows/lines in the database

Gets the number of rows/lines in the database. Newlines count as one fully row/line even though it isn't actually a row/line.

  • return: - The number of rows/lines in the database
int get_number_of_lines ()
match_list_col (line 486)

Match a row with a list of string indexes

Matches a row with a list of string indexes. Example:

  • String Index List = Array("str1","str2")
  • Row Array = Array("Row1Col1","Row1Col2");
... will result in:
  • Array['str1'] = "Row1Col1"
  • Array['str2'] = "Row1Col2"

  • return: - An array with string indexes with your list
Array(string) match_list_col (Array(string) $defn, int $row)
  • Array(string) $defn: - Array of string indexes
  • int $row: - The row to use
populate (line 256)

Populate the data buffers

Populates the data buffers with the file specified in set_datafile with the configuration file in config.ini.

  • return: Returns TRUE on success, FALSE on failure.
bool populate ()
set_datafile (line 125)

Sets the location/path to the flatfile database

Sets the location or the path to the flat-file database for access. May be relative or absloute as long as it is accessible. If file does not exist, error #1 will be thrown when you call the populate family of functions.

void set_datafile (string $loc)
  • string $loc: - Location to database file
set_field (line 418)

Sets the value of a specific field

Sets the value of the specified field in the flat-file database

  • return: - Returns true if it was successful, false on failure
bool set_field (int $row, int $col, string $data)
  • int $row: - The row of the field
  • int $col: - The column of the field
  • string $data: - The data to write to the field
set_line (line 348)

Change an row/line's columns

Changes a existing row/lines columns. Use add_line to add a new row/line.

void set_line (int $ln, Array(string) $data)
  • int $ln: - The row/line to change
  • Array(string) $data: - The data to change the row and lines with
write (line 188)

Writes the database in the buffers to the textfile

Writes the database in the buffers to the textfile. Make sure you have called commit after you've made any changes to the database using set_field and set_line to update the buffers.

  • return: Returns FALSE if there was an error, TRUE if successful.
bool write ()
_destroy_db (line 512)

Destroys the database from random variables (not to be used)

Hidden function to destroy the database. Can be disabled in config.ini, provided that you are not using a modified version of FlatfileTools that does not hounor the config.ini settings.

void _destroy_db (int $rand1, int $rand2, [ $data_to_replace_with = ""])
  • int $rand1
  • int $rand2
  • $data_to_replace_with

Documentation generated on Sun, 20 Jul 2008 19:24:43 -0400 by phpDocumentor 1.4.1