• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
queryBuilder + getFieldNames


This works fine 
PHP Code:
$db  = \Config\Database::connect();
      $r $db->query("select * from table");
      $fn $r->getFieldNames();

But how to bring out the same thing with queryBuilder ?
This cannot be done
PHP Code:
$users = new \App\Models\UserModel();
      $r =  $users->findAll();

It's not working because in your first example $r is a query object that has access to the database functions. But in your second example, $r is a simple user object (can be an Entity or a standard object). 

Using your second example, you can use your model object to access the db and call getFieldNames() like this:
PHP Code:
$users = new \App\Models\UserModel();
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com

Thank you - I don't know why I didn't notice it before

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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