Welcome Guest, Not a member yet? Register   Sign In
Best way to use db table prefix

So I include $db = ... in every functions
and in each RAW $sql, I use $db->prefixTable('table_name')

It works but is this the ideal way of coding it in CI4?

PHP Code:
function get_include_files()
    $db = \Config\Database::connect();

    $include_files = array(); // must return something

    $sql "SELECT plugin_id, plugin_includes FROM " $db->prefixTable('plugins') . " WHERE plugin_enabled = 1";


If you define a prefix on your connection configuration then using the query builder will automatically prefix all you table names.

Theme © iAndrew 2016 - Forum software by © MyBB