Início / Optitravel / Models
setDB($db)
This method is used to assign the database connection object to the model. It's called internally by the framework, so in most cases, you don't need to use it manually.
When the model is loaded, the framework takes care of injecting the database connection into it using this method, allowing all other methods (like find, insert, etc.) to interact with the database.
By default the model uses the system database connection, so only use this method for the optitravel connection.
Parameters
- $db – This is the database connection instance (usually a PDO object) that the model will use for queries.
Example
You’ll rarely need to call this method directly, but for reference:
use \App\Core\Database\DB;
use \App\Models\User;
$user = new User();
$user->setDB(DB::getCentral());
↑ (Última atualização: 06/05/2025)