Repository navigation
Quick start guide
Greg Bowler edited this page Mar 3, 2026
·
8 revisions
Here, we will build a minimal working setup in a bare repository, and run our first query.
Note
Note that WebEngine projects have the Database object instantiated and already available to your code by the ServiceLoader.
composer require phpgt/databaseCreate the file query/user/getById.sql:
select id, email
from user
where id = ?
limit 1use Gt\Database\Connection\Settings;
use Gt\Database\Database;
$settings = new Settings(
__DIR__ . "/query",
Settings::DRIVER_SQLITE,
__DIR__ . "/app.sqlite"
);
$db = new Database($settings);$user = $db->fetch("user/getById", 42);
echo $user?->email;$newId = $db->insert("user/insert", ["email" => "dev@example.com"]);
$rowsUpdated = $db->update("user/updateEmail", ["id" => $newId, "email" => "new@example.com"]);
$rowsDeleted = $db->delete("user/delete", ["id" => $newId]);Now we can move on to parameter binding and typed results.
PHP.GT/Database is a separately maintained component used by PHP.GT/WebEngine.