1. Go to this page and download the library: Download lukman-ss/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/ */
lukman-ss / database example snippets
declare(strict_types=1);
use Lukman\Database\Connection;
$pdo = new PDO('sqlite::memory:');
$connection = new Connection($pdo);
$connection->statement('CREATE TABLE users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL)');
$connection->statement('INSERT INTO users (name) VALUES (?)', ['Alice']);
$users = $connection->select('SELECT * FROM users');
declare(strict_types=1);
use Lukman\Database\ConnectionFactory;
$factory = new ConnectionFactory();
$connection = $factory->create([
'driver' => 'sqlite',
'database' => ':memory:',
]);
declare(strict_types=1);
use Lukman\Database\Expression;
use Lukman\Database\QueryBuilder;
$count = (new QueryBuilder($connection))
->table('users')
->select(new Expression('COUNT(*) AS total'))
->first();
$rows = (new QueryBuilder($connection))
->table('users')
->selectRaw('COUNT(CASE WHEN active = ? THEN 1 END) AS active_total', [1])
->whereRaw('email LIKE ?', ['%@example.com'])
->get();
declare(strict_types=1);
use Lukman\Database\QueryBuilder;
$rows = (new QueryBuilder($connection))
->table('users')
->select('users.name', 'posts.title')
->join('posts', 'posts.user_id', '=', 'users.id')
->where('posts.published', 1)
->get();
$rows = (new QueryBuilder($connection))
->table('users')
->select('users.name', 'posts.title')
->leftJoin('posts', 'posts.user_id', '=', 'users.id')
->get();
declare(strict_types=1);
$connection->transaction(function ($connection): void {
$connection->statement('INSERT INTO users (name) VALUES (?)', ['Alice']);
$connection->statement('INSERT INTO users (name) VALUES (?)', ['Bob']);
});
declare(strict_types=1);
use Lukman\Database\Schema\Blueprint;
use Lukman\Database\Schema\SchemaBuilder;
$schema = new SchemaBuilder($connection);
$schema->create('users', function (Blueprint $table): void {
$table->id();
$table->string('name');
$table->string('email');
$table->integer('age')->nullable();
$table->boolean('active')->default(true);
});
$exists = $schema->hasTable('users');
$schema->dropIfExists('users');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.