PHP code example of sukhrobnurali / querylite

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

    

sukhrobnurali / querylite example snippets


class UserModel extends QueryLite
{
    const TABLE = 'users';

    protected function create($name, $email) {
        $this->insert(['name' => $name, 'email' => $email]);
    }
}

$connection = new PDO(
    "mysql:host=127.0.0.1;dbname=your_database;charset=utf8mb4",
    "your_user",
    "your_password",
    [
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    ]
);

$userModel = new UserModel($connection);

$users = $userModel->select(['id', 'name'])
    ->where('age', '>', 18)
    ->orderBy('name ASC')
    ->limit(100)
    ->getAllRows();


$userModel->insert([
    'name' => 'John Doe',
    'email' => '[email protected]'
]);

$userModel->update(['email' => '[email protected]'])
    ->whereEqual('id', 1);

$userModel->delete()
    ->whereEqual('id', 5);