I have a script which generates my PHP models dynamically based on the structure of my MySQL database. I get the list of tables with mysql_list_tables(), for each table get the list of fields with mysql_ list_ fields(), and depending on the table structure I create my methods accordingly: for instance if I find the integer field "order" defined, then my SELECT statements are ordered by the values of that field.
I would like to extend this approach by using the field flags returned by mysql_field_flags() to add internationalization support to by models. What I want is to add a custom flag type – in addition to the existing not_null, auto_increment and others – that I would for instance call i18n, then whenever a field has this flag set, I know I would need to add methods to fetch/add the values from a translation table. To allow me administrate the database (e.g. enable or disable translation on a field), it would be great if database administration interfaces like phpMyAdmin could automatically pick up on my custom flags.
Can I add custom flags to MySQL table fields, and have them picked up by phpMyAdmin and PHP?
AFAIK there is no way to add custom flags to fields, as such. One way you could implement this is to us the COMMENT attribute with some kind of serialised data –
I would advise against using the mysql_list_* functions for retrieving the table and field data. Instead you should select from the INFORMATION_SCHEMA. I would also suggest using PDO or mysqli as, with a bit of luck, the old mysql extension will be deprecated soon.
Instead of
mysql_list_tables()you would use –and instead of
mysql_list_fields()you would use –