CodeIgniter Forums
Is there a way to get more metadata - 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: Is there a way to get more metadata (/showthread.php?tid=70206)



Is there a way to get more metadata - javiecholson188 - 03-08-2018

according to documentation the only metadata we can get with this "$fields = $this->db->field_data('table_name');"
are $field->name; $field->type;$field->max_length;$field->primary_key; but is there a way to check if a field is required or a foreign key?

thanks


RE: Is there a way to get more metadata - Kaosweaver - 03-08-2018

This might help

It is for mySQL, so you may need to implement something else to make it work for your database.


RE: Is there a way to get more metadata - DanielRhodes - 03-11-2018

(03-08-2018, 01:20 AM)javiecholson188 Wrote: according to documentation the only metadata we can get with this "$fields = $this->db->field_data('table_name');"
are $field->name; $field->type;$field->max_length;$field->primary_key; but is there a way to check if a field is required or a foreign key?

thanks

Yes, it will basically boil down to a manual parse of your RDBMS's "SHOW CREATE TABLE" return. And, as Kaosweaver mentions, the format here will depend on the database vendor. 

For cases where the table structure is more_or_less known, you could consider supplementing CI's metadata return with some hardcoded additions :-\