-
-
Notifications
You must be signed in to change notification settings - Fork 3
Home
phpgt/database gives us a structured way to keep database access close to the application without scattering SQL strings throughout our PHP code.
We can keep queries in files or PHP classes, bind values safely, work with predictable result objects, and apply schema changes in a controlled order.
Note
If we are building with WebEngine, most of the wiring is already in place. WebEngine reads the database configuration, exposes the database service in page logic, and makes the migration command available through gt migrate. The framework overview is at https://www.php.gt/docs/webengine/database/.
- Query files organised into collections.
- PHP query collections, including
phpgt/sqlbuilderbuilders. - Positional, named, special, and dynamic parameter binding.
- Typed fetch helpers for common single-column queries.
- Raw SQL execution when a named query file would not add much.
- Multiple named connections in one
Databaseobject. - Schema migrations with sequence and integrity checks.
- Quick start guide
- Configuration and connections
- Query collections
- Parameter binding
- Raw SQL and result sets
- Type-safe getters
- Multiple connections
- 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);
$user = $db->fetch("user/getById", 42);
echo $user?->getString("email");In practice, that means the PHP code names the query, the SQL stays on disk, and the returned row is already wrapped in the helper API used throughout the rest of the library.
To see the setup from scratch, continue with the Quick start guide.
PHP.GT/Database is a separately maintained component used by PHP.GT/WebEngine.