table

table is a way of dealing with a single record in your database table. Some users have reported issues when MySql is operating in strict mode. You can turn off strict mode in PHPMYADMIN with the following SQL statement: SET @@global.sql_mode= 'NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

Parent Class

None


Public Properties

$tableName
Name of the database table
Data Type: string
Default Value: empty string
$field
An associative (key=value pair) array of field names in the database table and the associated value for each field on the current record in the table
Data Type: array
Default Value: empty array
$fieldTypes
An associative (key=value pair) array of field names and their data type. Note: tinyint(1) is assumed to be a boolean. Only boolean, integer, timestamp, datetime, date, float and varchar are supported. I *rarely* use any other database field data type. If you need the others, please let me know and I will add them.
Data Type: string
Default Value: empty string
$clearedValues
An associative (key=value pair) array of field names and their associated “cleared” value. ie: a field of type integer, would have a clearedValue of 0. A field of type varchar would have a clearedValue of an empty string. Boolean would have a clearedValue of false. etc.
Data Type: string
Default Value: empty string
$saved
Is this current record saved in the database? True if it is, otherwise false.
Data Type: boolean
Default Value: false
$lastSql
The last SQL statement used to actually pull data for this record from the database
Data Type: string
Default Value: empty string
$sqlParams
A list of parameters “bound” to the $lastSql.
Data Type: array
Default Value: empty array

Public Methods

\ipinga\table __construct( string $tableName )
This is the class constructor.
Parameters:
$tableName (string: required) is the name of the database table you want to work with
Returns:
A table instance
Example:
void clear()
Clears the contents of the table object and sets all fields to their “cleared values”
Parameters:
None
Returns:
null
Example:
void __set( string $fieldName, mixed $value )
This is the setter.
Parameters:
$fieldName (string: required) is the name of the field you want to change the value for
$value (mixed: required) is the value to store in the named field.
Returns:
null
Example:
void __get( string $fieldName )
This is the getter.
Parameters:
$fieldName (string: required) is the name of the field you want to retrieve the value of
Returns:
The value currently stored associated with the fieldname provided.
Example:
boolean save()
Saves the current data in the table object to the database. Note: the fields named id, passwd and timestamp are special. id is used to locate the desired record in the database. ie: If you set the table field id to 120, then when you save the table object, it will put the contents on the matching record in the database. If you set the table field id to 0, then when you save the table object, it will create a new record in the database. All id fields are assumed to be auto-incrementing primary keys for the database table. passwd is encrypted when written to the database and decrypted when read from the database. passwd fields are kept in clear text in the table object. A field named ‘timestamp’ is never written to the database and is assumed to be a timestamp database field with ‘on update’ set in the database correctly.
Parameters:
None
Returns:
True if successful, otherwise, false.
Example:
void delete()
Deletes the associated record from the database.
Parameters:
None
Returns:
null
Example:
void deleteById(integer $id)
Deletes the associated record from the database. Essentially the same as delete()
Parameters:
$id (integer: required) is the id of the record you wish to delete
Returns:
null
Example:
boolean loadById(integer $id)
Locates the specified record from the database and loads its contents into the table object
Parameters:
$id (integer: required) is the id of the record you wish to load
Returns:
True if successful, otherwise false
Example:
boolean loadBySecondaryKey(string $fieldName, mixed $desiredValue)
Locates the specified record from the database and loads its contents into the table object
Parameters:
$fieldName (string: required) is name of the field in the database to search
$desiredValue (mixed: required) is the value to locate
Returns:
True if successful, otherwise false
Example:
boolean loadByCustomWhere(string $where)
Locates the specified record from the database and loads its contents into the table object. WARNING: This is a dangerous function. You are responsible for making sure there is no SQL injection, etc in the where clause you pass.
Parameters:
$where (string: required) is the SQL where clause used to locate the database record
Returns:
True if successful, otherwise false
Example: