-
-
Notifications
You must be signed in to change notification settings - Fork 3
Quick start guide
Greg Bowler edited this page Mar 3, 2026
·
6 revisions
Here, we will build a minimal working setup in a bare repository, and run our first query.
Note
WebEngine projects already have the Database object instantiated, available to your code's go function 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.
If you'd like to learn more of the basics first, move on to Configuration and connections or Query collections.
PHP.GT/Database is a separately maintained component of PHP.GT/WebEngine.