Introduction
Basic Concepts
Understanding Routing
Intercepting Requests
Module Fundamentals
Database Operations
Templates
Helpers
Form Handling
Form Validation
Working With Files
Image Manipulation
Working With Dates & Times
Language Control
Authorization & Authentication
Getting Connected
With Trongate, everything gets handled by modules. That includes database interaction.
Trongate v2 comes with a DB module for querying databases. The DB Module talks to MySQL and MariaDB. That’s the deal. Other databases? Possible, but you're on your own.
The Config File
All connection details live in config/database.php.
A fresh Trongate install gives you this:
<?php
$databases = [
'default' => [
'host' => '127.0.0.1',
'port' => '3306',
'user' => 'root',
'password' => '',
'database' => 'trongate'
],
];
Edit. Refresh. Done.
Multiple Databases? Yes.
Add as many groups as you want:
<?php
$databases = [
'default' => [
'host' => '127.0.0.1',
'user' => 'app_user',
'password' => 's3cureP@ss',
'database' => 'production'
],
'analytics' => [
'host' => 'analytics.yoursite.com',
'user' => 'reader',
'password' => 'R3ad0nly!',
'database' => 'stats'
],
'warehouse' => [ /* another one */ ]
];
Controllers can only use the default database connection.
Model files can use any database group you define:
$stats = $this->analytics->get('page_views');
$stock = $this->warehouse->get_where(42);
Secondary databases = models only. Keeps architecture sane.
What You’ll Learn Next
- How to use the
dbmodule - Fetching, inserting, updating, deleting records
- Raw queries + prepared statements
- Debug mode that actually shows you the SQL