CodeIgniter Forums
queryBuilder + getFieldNames - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: queryBuilder + getFieldNames (/showthread.php?tid=78395)



queryBuilder + getFieldNames - okatse - 01-13-2021

Hi 

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

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



RE: queryBuilder + getFieldNames - includebeer - 01-15-2021

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();
var_dump($users->db->getFieldNames()); 



RE: queryBuilder + getFieldNames - okatse - 01-16-2021

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