| [ Web Proxy ] |
| Viewing: https://php.gt/database | [Back] [Original] |
This library gives us a tidy way to keep SQL close to the application, without mixing query strings throughout our PHP code.
We can organise queries into collections, bind values safely, fetch predictable PHP types, and keep schema changes under version control.
[!NOTE] If you are building with WebEngine, most of the setup is already done for you. The framework wires up the database service, reads configuration, and exposes the migration command through
gt migrate. The WebEngine overview page is at https://www.php.gt/docs/webengine/database/.
Database object.use Gt\Database\Connection\Settings;
use Gt\Database\Database;
$settings = new Settings(
"query",
Settings::DRIVER_SQLITE,
"app.sqlite"
);
$db = new Database($settings);
$userRow = $db->fetch("user/getById", 42);
echo "User email address: " . $userRow->getString("email");
In a nutshell: queries live on disk, the PHP code calls them by name, and the result comes back through a small type-safe API.
To see the full setup from scratch, move on to the Quick start guide.
The docs you are viewing are currently being imported from the GitHub Wiki, and may have formatting/linking issues.
Please view the appropriate GitHub wiki while we transition everything over.
| Web Proxy Viewer | New URL | Original Page |