• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Best way to use db table prefix

#1
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";
    ... 

Thanks.
Reply

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.