https://github.com/morphable/simpledatabase
https://github.com/morphable/simpledatabase
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/morphable/simpledatabase
- Owner: Morphable
- License: mit
- Created: 2019-01-30T19:21:56.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-15T10:31:42.000Z (about 7 years ago)
- Last Synced: 2025-01-01T02:35:02.282Z (over 1 year ago)
- Language: PHP
- Size: 21.5 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# Simple database component
A simple database component, easy to implement into any system
## Usage
Before using the library, I will tell you this is a very
limited ORM, I do this intentially because in my opinion it's
better to write raw sql when you have complicated queries.
```php
getMessage());
});
// execute raw query, returns PDOStatement
$stmt = $db->query("select ?", "1");
$stmt->fetch(\PDO::FETCH_COLUMN) // 1
// select
$select = $db->builder($table)
->select('`col1`, `col2`, `col3`')
->join('table on table.col1 = tale.col2')
->where('`col1` = ? and `col2` = ?', [$param1, $param2])
->orderBy('`col1` DESC')
->limit(5)
->offset(5)
->execute(); // returns QueryExecuter
$select->fetch(); // all rows
$select->fetchOne(); // first row
$select->fetchColumn(); // only possible when you only select 1 column
$select->getStatement(); // returns \PDOStatement
// insert
$insertId = $db->builder($table)
->insert([
'col1' => $col1,
'col2' => $col2,
'col3' => $col3,
])
->execute()
->getLastInsertId();
// update
$db->builder($table)
->update([
'col1' => $col1,
])
// throws exception when you don't have a where clause
->where('`id` = ?', $id)
->execute();
// delete
$db->builder($table)
->delete()
// throws exception when you don't have a where clause
->where('`id` = ?', $id)
->execute();
```
## Contributing
- Follow PSR-2 and the .editorconfig
- Start namespaces with \Morphable\SimpleDatabase
- Make tests