PHP code example of ctrbts / base-model

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

    

ctrbts / base-model example snippets


use BaseModel\BaseModel;

$db = new BaseModel([
    'type' => 'mysql',
    'host' => 'localhost',
    'username' => 'root',
    'password' => 'secret',
    'dbname' => 'mi_app',
    'charset' => 'utf8mb4'
]);

// Obtener todos los usuarios activos
$users = $db->where('active', 1)
            ->get('users');

// Obtener un solo usuario
$user = $db->where('id', 15)
           ->getOne('users');

$data = [
    'username' => 'nuevo_usuario',
    'email' => '[email protected]',
    'created_at' => $db->now()
];

$id = $db->insert('users', $data);

$data = ['active' => 0];
$db->where('last_login', $db->interval('-1 year'), '<');
$db->update('users', $data);

$db->where('id', 50)->delete('users');