PHP code example of ppeco / dbpp

1. Go to this page and download the library: Download ppeco/dbpp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ppeco / dbpp example snippets


class SimpleDatabase extends Database {

}

class TableDao extends Dao {

}

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;
}

class SimpleDatabase extends Database {
   public TableDao $table;
}

$pdo = new PDO(*data*);
$database = new SimpleDatabase($pdo);