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_name', 'primary_key')]
class Model
{
    use Database;
}

$this->model->read('*');

$this->model->find('column, 'value');

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

$this->model->delete('column, 'value');

$this->model->save(['column' => 'value']);

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

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

#[From(SampleEntity::Table, SampleEntity::PrimarKey)]
class Model
{
    use Database;
}

$row = $this->model->find('id', 1)->record();

// Accessing properties
echo $row->id;
echo $row->sample;

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

$this->save($entity);

/** @extends Database<SampleEntity> */
#[From(SampleEntity::Table, SampleEntity::PrimaryKey, class: SampleEntity::class)]
class Model
{
    use Database;
}

// Fetch records directly as objects
$row = $this->model->find('id', 1)->record();

// Access the object's properties
echo $row->id;
echo $row->sample;

// Fetch all records
$allRecords = $this->model->read('*')->recordAll();