Askarali Makanadar
Askarali Makanadar

Reputation: 48

How to access the database in Helper Functions in CI4

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

Answers (2)

myself
myself

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

MnTanProject
MnTanProject

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

Related Questions