-
-
Notifications
You must be signed in to change notification settings - Fork 3
Home
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/.
- Stores queries in files or PHP query classes.
- Executes named queries through one
Databaseobject. - Supports positional and named parameter binding.
- Returns rows and result sets through consistent helper types.
- Supports multiple named connections.
- Runs schema migrations with integrity checks.
- Supports branch-local development migrations as well as canonical migrations.
- Quick start guide
- Configuration and connections
- Query collections
- Parameter binding
- Raw SQL and result sets
- Type-safe getters
- Database migrations
- Examples
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.
PHP.GT/Database is a separately maintained component that powers database features in PHP.GT/WebEngine.