Brain now uses Doctrine DBAL for database interaction, and models are typically where all of the queries will live. Load a model anywhere and use it easily:
Loading & Using Models
// Load the model with filename example_model.php $example = Model::load('example_model'); // Call a method named "get_stuff" from the example model $stuff = $example->get_stuff('cool');
All models should extend BaseModel, which allows for easy DBAL usage via $this->db.
use \Brain\Lib\Container; use \App\Lib\BaseModel; use \Brain\Lib\Container; class Example_model extends BaseModel { public function __construct( Container $container ) { parent::__construct( $container ); } public function get_stuff( $type ) { $sql = ' SELECT * FROM stuff WHERE type = :type'; $stmt = $this->db->executeQuery( $sql, [ 'type' => $type ] ); if( $rows = $stmt->fetchAll() ) { return $rows; } return NULL; } }