https://github.com/ppeco/dbpp
The library makes working with database easier and simpler
https://github.com/ppeco/dbpp
database interface pdo php ppeco security-tools
Last synced: 5 months ago
JSON representation
The library makes working with database easier and simpler
- Host: GitHub
- URL: https://github.com/ppeco/dbpp
- Owner: ppeco
- License: mit
- Created: 2021-07-07T14:13:38.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2022-01-31T11:09:16.000Z (over 4 years ago)
- Last Synced: 2025-08-06T02:53:58.770Z (11 months ago)
- Topics: database, interface, pdo, php, ppeco, security-tools
- Language: PHP
- Homepage:
- Size: 28.3 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dbpp
dbpp is a library that simplifies database queries by collecting them into one class.
## Installation
dbpp requires composer and php 8.0 or higher.
For installation run this command in composer:
```shell
composer require ppeco/dbpp
```
## Usage
The main class for dbpp is Database.
Create a class extended from Database from dbpp.
```php
class SimpleDatabase extends Database {
}
```
Create a class that will contain all the queries for a specific table.
The class should be extended from the Dao class from dbpp.
```php
class TableDao extends Dao {
}
```
Create functions with query annotations from dbpp.
They can be Query and Insert.
Functions should call a function from parent.
```php
abstract class TableDao extends Dao {
#[Query("SELECT * FROM `table`")]
public abstract function getAll(): array|false;
#[Query("SELECT * FROM `table` WHERE `id` = :id")]
public abstract function getById(int $id): array|false;
#[Insert("INSERT `table`(`id`, `name`) VALUES(NULL, :name)")]
public abstract function insert(string $name): bool;
#[Insert("INSERT `table`(`id`, `name`) VALUES(NULL, :name)", ['id'])]
public abstract function insert2(string $name): int|bool;
}
```
Link your Dao to Database via class properties.
```php
class SimpleDatabase extends Database {
public TableDao $table;
}
```
Well, the final steps.
Create PDO object and create Database class
```php
$pdo = new PDO(*data*);
$database = new SimpleDatabase($pdo);
```
Now you can call methods from the Database class