CodeIgniter Forums

Full Version: Is there a way to get more metadata
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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
This might help

It is for mySQL, so you may need to implement something else to make it work for your database.
(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 :-\