Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Database abstraction

jimmysparkle edited this page · 1 revision

Database Abstraction

Atsumi has built in database abstraction, making it easy to swap database engines, add caching, encryption, debugging, etc.

Database Adapters

  1. Database Adapter PostgreSQL
  2. Database Adapter MySQL
  3. Database Adapter SQLite

Database results

Database results are returned as arrays of database row objects. for more information see Database Row

Database API

Getting data our of your database

select

Allows you to freely query your database. Returns an array of database rows.

$db->select($sql);
Parameter Type Required Default Description
$sql String Required

selectOne

Same as select() but returns a single database row rather than array and throws an exception if more than one row returned.

fetch

Fetches results from the database. TODO: describe API.

fetchOne

Fetches a single row from the database. TODO: describe API.

Inserting & Updating your database

insert

Insert a row

$db->insert($tableName, $colDataSchema);
Parameter Type Required Default Description
$tableName String Required Table inserting to
$colDataSchema String(s) Required Data schema to insert

Example:

$db->insert('fridge', 'name = %s', 'Apples', 'quantity = %i', 12);

update

Update a row or series of rows in a given table.

$db->update($table, $where, $colDataSchema);
Parameter Type Required Default Description
$tableName String Required Table inserting to
$where String(s) Required where statement
$colDataSchema String(s) Required Data schema to insert

Example:

$db->update('fridge', 'name = %s', 'Apples', 'quantity = %i', 10);

updateOne

Same as update() however throws db_UnexpectedResultException if more than one row was updated. Should be used in conjunction with transactions to avoid updating multiple rows.

insertOrUpdateOne

Inserts a row to a table if not found in database, updates otherwise.

$db->insertOrUpdateOne($table, $where, $colDataSchema);
Parameter Type Required Default Description
$tableName String Required Table inserting to
$where String(s) Required where statement
$colDataSchema String(s) Required Data schema to insert

Example:

$db->insertOrUpdateOne('fridge', 'name = %s', 'pizza', 'quantity = quantity + 2');

Misc

exists

Checks to see if row exists in a database

$db->exists($table, $where);
Parameter Type Required Default Description
$tableName String Required Table inserting to
$where String(s) Required where statement

Example:

$db->exists('fridge', 'name = %s AND quantity > %i', 'pizza', 4);

delete

deleteOne

Transactions

transactionBegin

transactionRollback & transactionAutoRollback

Something went wrong with that request. Please try again.