Page 1 of 1
dynamically alter table is column doesn't exist
Posted: Mon Aug 29, 2005 1:57 pm
by knipper
Does anyone know how to do this. My situation is that I have an application that has many tables/columns. I want to have a function that examines the query and checks to make sure the columns exist and creates them if not. This would be a housekeeping function for when adding content.
Posted: Mon Aug 29, 2005 3:23 pm
by Burrito
you're goign to have to do it with multiple queries.
you could use MySQL's built in table structure query "desc %tablename%" or you could simply select data from the table then use php to find the field names with
mysql_fetch_field().
you'll then need to loop over the results and match them against the field names you know you have. If there is a new one, you'll have to alter the table and add it to the list of fields.