PHP code example of remils / database

1. Go to this page and download the library: Download remils/database 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/ */

    

remils / database example snippets




use Remils\Database\Manager;

$manager = new Manager();



use Remils\Database\AbstractRepository;
use Remils\Database\Manager;
use Remils\Database\PDO\Connect;

ger->getConnect('default');

$connect->execute(<<<SQL
    CREATE TABLE IF NOT EXISTS `users` (
        `id` INTEGER PRIMARY KEY AUTOINCREMENT,
        `name` VARCHAR(255)
    );
SQL);

class User
{
    private int $id;

    private string $name;

    public function getId(): int
    {
        return $this->id;
    }

    public function getName(): string
    {
        return $this->name;
    }
}

class UserRepository extends AbstractRepository
{
    public function getConnectName(): string
    {
        return 'default';
    }

    public function getTableName(): string
    {
        return 'users';
    }

    public function getEntityClassName(): string
    {
        return User::class;
    }
}

$userRepository = new UserRepository($manager);

$user = $userRepository->insert([
    'name' => 'Иван',
]);

var_dump($user);

$userRepository->update([
    'name' => 'Василий',
], [
    'id' => $user->getId(),
]);

$user = $userRepository->first([
    'id' => $user->getId(),
]);

var_dump($user);

$userRepository->delete([
    'id' => $user->getId(),
]);