Reputation: 48
CI4: I have created database object in Controller, i want to execute helper function which has some queries,
Question: How to access the database in Helper Functions in CI4?
Upvotes: 0
Views: 1509
Reputation: 21
you can use by adding these lines in your helper function
$db = db_connect();
$result = $db->query("SELECT * FROM table")->getResult();
Upvotes: 1
Reputation: 33
You can access the builder from the model.
$model = new SomeModel();
$builder = $model->builder();
$builder->db //returns the db conn used in model
Upvotes: 0