-
Notifications
You must be signed in to change notification settings - Fork 7
Database abstraction
Atsumi has built in database abstraction, making it easy to swap database engines, add caching, encryption, debugging, etc.
Database results are returned as arrays of database row objects. for more information see Database Row
Allows you to freely query your database. Returns an array of database rows.
$db->select($sql);| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| $sql | String | Required |
Same as select() but returns a single database row rather than array and throws an exception if more than one row returned.
Fetches results from the database. TODO: describe API.
Fetches a single row from the database. TODO: describe API.
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 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);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.
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');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);