PHP code example of vista-php / database

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

    

vista-php / database example snippets


return [
    'DB_TYPE' => 'sqlite',
    'DB_NAME' => __DIR__ . '../database/database.sqlite',
];

return [
    'DB_TYPE' => 'mysql',
    'DB_NAME' => 'database',
    'DB_HOST' => 'localhost',
    'DB_USER' => 'root',
    'DB_PASS' => 'root'
];

use Vista\Model\Model;

class User extends Model
{
    protected string $table = 'users';
    protected string $primaryKey = 'id';
    protected array $columns = ['id', 'name', 'username', 'password'];
    protected array $relationships = ['posts']

    public function posts()
    {
        return Post::where('user_id', $this->id);
    }
}
bash
composer