A simple mysql database warpper for php
- Simple Interface
- Add, Edit, Delete, Fetch query helper methods
- Database transactions
Install by using composer
composer require bera/bera-dbSetup a connection
require_once __DIR__ . '/vendor/autoload.php';
use Bera\Db\Db;
try {
$db = new Db('music_app', 'localhost', 'root', '', null, true);
} catch( Bera\Db\Exceptions\DbErrorException $e ) {
echo $e->getMessage();
}Insert data
$db->insert('songs', [
'title' => 'A New Songs',
'author' => 'dev',
'duration' => 300
]);Update data
$db->update('songs', [
'title' => 'Another Songs'
], ['id' => 1]);Delete data
$db->delete('songs', ['id' => 1]);Select data
$db->query('SELECT * FROM songs')->all()
$db->query('SELECT * FROM songs WHERE id = ?', [1])->one()
$db->findAll('songs');
$db->findOne('songs', ['id' => 1]); $db = new Db('music_app', 'localhost', 'root', '', null, true); $db->setDebugMode(true) $db->insert('table_name', $data = []) $db->update('table_name', $data = [], $conditions = []) $db->delete($table, $conditions=[], $glue = 'AND') $db->deleteUsingAnd($table, $conditions=[]) $db->deleteUsingOr($table, $conditions=[]) $db->query($sql, $params = []) $db->getAffectedRows() $db->lastInsertId() $db->query($sql, $params = [])->one() $db->query($sql, $params = [])->oneAsObject() $db->query($sql, $params = [])->all() $db->findOne($table, $conditions = [], $glue = 'AND', $as = 'object'); $db->findAll($table, $conditions = [], $glue = 'AND'); $db->start_transaction() $db->end_transaction()