Lightweight CRUD database system built using the OSSN database object, designed to simplify create, read, update, and delete operations.
Retrieve records from the database using the OSSN database object.
Fetch a single row from the database based on defined conditions.
| Code | Type | Description |
|---|---|---|
| from | String | Table name |
| wheres | array | Where conditions using OssnDatabase::wheres() |
| limit | string | Example: 0, 10 |
| order_by | string | Order by clause (default: null) |
| group_by | string | Group by value |
$database = new \OssnDatabase();
$params = array(
'from' => 'table_name',
'wheres' => array(
OssnDatabase::wheres('col', '=', 1),
OssnDatabase::wheres('col2', '!=', 2),
)
);
$single = $database->select($params);
To retrieve multiple rows, pass true as the second argument to the select method.
$database = new \OssnDatabase();
$params = array(
'from' => 'table_name',
'order_by' => 'name DESC',
'wheres' => array(
OssnDatabase::wheres('col', '=', 1),
OssnDatabase::wheres('col2', '!=', 2),
)
);
$result = $database->select($params, true);
Insert a new record into the database.
| Code | Type | Description |
|---|---|---|
| table | String | Table name |
Ensure that the names and values arrays match by index.
$database = new \OssnDatabase();
$insert = $db->insert(array(
'table' => 'table_name',
'names' => array('col1', 'col2', 'col3'),
'values' => array('col1_value', 'col2_value', 'col3_value'),
));
Remove records from the database based on specified conditions.
| Code | Type | Description |
|---|---|---|
| from | String | Table name |
| wheres | array | Where conditions using OssnDatabase::wheres() |
$database = new \OssnDatabase();
$params = array(
'from' => 'table_name',
'wheres' => array(
OssnDatabase::wheres('col', '=', 1),
OssnDatabase::wheres('col2', '!=', 2),
)
);
$delete = $database->delete($params);
Update existing records in the database.
| Code | Type | Description |
|---|---|---|
| table | String | Table name |
Ensure that the names and values arrays match by index.
$database = new \OssnDatabase();
$update = $db->update(array(
'table' => 'table_name',
'names' => array('col1', 'col2', 'col3'),
'values' => array('col1_value', 'col2_value', 'col3_value'),
'wheres' => array(
OssnDatabase::wheres('col', '=', 1),
)
));
WHERES
OssnDatabase::wheres(string, string, string|int|float|array)