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
Data Type: string
Default Value: empty string
Data Type: array
Default Value: empty array
Data Type: string
Default Value: empty string
Data Type: string
Default Value: empty string
Data Type: boolean
Default Value: false
Data Type: string
Default Value: empty string
$lastSql
.Data Type: array
Default Value: empty array
Public Methods
Parameters:
$tableName
(string: required) is the name of the database table you want to work withReturns:
A
table
instanceExample:
1 |
$myTable = new \ipinga\table('users'); |
table
object and sets all fields to their “cleared values”Parameters:
None
Returns:
null
Example:
1 2 3 4 5 6 7 |
$myTable = new \ipinga\table('users'); $myTable->first_name = 'Bob'; echo $myTable->first_name; // outputs: 'Bob' $myTable->clear(); echo $myTable->first_name; // outputs: '' |
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:
1 2 3 4 |
$myTable = new \ipinga\table('users'); $myTable->first_name = 'Bob'; echo $myTable->first_name; // outputs: 'Bob' |
Parameters:
$fieldName
(string: required) is the name of the field you want to retrieve the value ofReturns:
The value currently stored associated with the fieldname provided.
Example:
1 2 3 4 |
$myTable = new \ipinga\table('users'); $myTable->first_name = 'Bob'; echo $myTable->first_name; // outputs: 'Bob' |
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:
1 2 3 4 5 6 7 8 9 10 |
$myTable = new \ipinga\table('users'); // create a new record... $myTable->id = 0; // trigger a new record $myTable->first_name = 'Bob'; $myTable->last_name = 'Smith'; $myTable->passwd = 'strong password here'; $myTable->save(); echo $myTable->id; // outputs the database id number AFTER the insert was performed. |
Parameters:
None
Returns:
null
Example:
1 2 3 4 |
$myTable = new \ipinga\table('users'); $myTable->loadById(15); $myTable->delete(); // deletes record #15 from the database |
Parameters:
$id
(integer: required) is the id of the record you wish to deleteReturns:
null
Example:
1 2 3 |
$myTable = new \ipinga\table('users'); $myTable->deleteById(15); // deletes record #15 from the database |
table
objectParameters:
$id
(integer: required) is the id of the record you wish to loadReturns:
True if successful, otherwise false
Example:
1 2 3 4 |
$myTable = new \ipinga\table('users'); $myTable->loadById(15); // loads record #15 from the database echo $myTable->first_name; // outputs: 'Bob' (using the examples from above) |
table
objectParameters:
$fieldName
(string: required) is name of the field in the database to search$desiredValue
(mixed: required) is the value to locateReturns:
True if successful, otherwise false
Example:
1 2 3 4 5 |
$myTable = new \ipinga\table('users'); $myTable->loadBySecondaryKey( 'first_name', 'Bob'); // really bad example! echo $myTable->id; // outputs: the first record id that has a first_name of "Bob" |
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 recordReturns:
True if successful, otherwise false
Example:
1 2 3 4 5 |
$myTable = new \ipinga\table('users'); $myTable->loadByCustomWhere('first_name = "Bob"'); echo $myTable->id; // outputs: the first record id that has a first_name of "Bob" |