1. Go to this page and download the library: Download bjornbasar/karhu-db 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/ */
bjornbasar / karhu-db example snippets
use Karhu\Db\Connection;
$db = new Connection('mysql:host=localhost;dbname=myapp', 'user', 'pass');
// Query helpers
$rows = $db->fetchAll('SELECT * FROM users WHERE active = :active', ['active' => 1]);
$user = $db->fetchOne('SELECT * FROM users WHERE id = :id', ['id' => 42]);
$count = $db->fetchScalar('SELECT COUNT(*) FROM users');
// Insert / update / delete
$id = $db->insert('users', ['name' => 'Bjorn', 'email' => '[email protected]']);
$db->update('users', ['name' => 'Updated'], ['id' => $id]);
$db->delete('users', ['id' => $id]);
use Karhu\Db\TableBase;
final class UserTable extends TableBase {
protected string $table = 'users';
protected string $primaryKey = 'id';
}
$users = new UserTable($db);
$users->getAll();
$users->get(42);
$users->getBy(['role' => 'admin']);
$users->create(['name' => 'New User']);
$users->update(42, ['name' => 'Updated']);
$users->delete(42);
$users->count(['role' => 'admin']);
use Karhu\Db\PdoUserRepository;
$userRepo = new PdoUserRepository($db);
$app->container()->set(UserRepositoryInterface::class, $userRepo);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.