Using miSqlRecord
miSqlRecord is an active record class. It can be used to read, insert, update and delete a specific record from the database. When reading if the record cannot be found in the database, miDBException will be thrown.
* Reading a record by primary key example:
<?php
try {
$sqlRecord = new miSqlRecord('Contacts', 'ContactID');
$sqlRecord->readPK($id);
}
catch (miDBException $exception)
{
// Error handling here ...
}
?>
* Reading a record by any key example:
<?php
$sqlRecord = new miSqlRecord('Contacts', 'ContactID');
$sqlRecord->read($key, $value);
?>
* Inserting new record example:
<?php
$sqlRecord = new miSqlRecord('Contacts', 'ContactID');
$sqlRecord->set('ContactName', 'some test name');
$id = $sqlRecord->insert();
?>
* Updating a record example:
<?php
$sqlRecord = new miSqlRecord('Contacts', 'ContactID');
$sqlRecord->readPK($id);
$sqlRecord->set('ContactName', 'some test name');
$sqlRecord->update();
?>
* Deleting a record example:
<?php
$sqlRecord = new miSqlRecord('Contacts', 'ContactID');
$sqlRecord->set('ContactID', '10'); // or read() the record from the DB
$sqlRecord->delete();
?>