PHP code example of drago-ex / database

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

    

drago-ex / database example snippets


#[Table('table', 'id')]
class Model {}

$this->model->table();

$this->model->table('email = ?', '[email protected]');

$this->model->get(1);

$this->model->remove(1);

$this->model->put(['column' => 'record']);

class SampleEntity extends Drago\Database\Entity
{
	public const Table = 'table';
	public const PrimaryKey = 'id';

	public ?int $id = null;
	public string $sample;
}

#[Table(SampleEntity::Table, SampleEntity::PrimarKey)]
class Repository {}

function find(int $id): array|SampleEntity|null
{
	return $this->get($id)->fetch();
}

$row = $this->find(1);
echo $row->id;
echo $row->sample;

$entity = new SampleEntity;
$entity->id = 1;
$entity->sample = 'sample';

$this->save($entity);

function save(SampleEntity $entity): Result|int|null
{
	return $this->put($entity);
}