tags:

views:

76

answers:

2

I am writing a plugin for wordpress. When the plugin is initialised I need to find out if the users table contains the columns I am trying to insert to ensure I am not overwriting anything. Can someone provide me with the syntax that does this; I think it looks something like this:

SELECT DISTINCT TABLE_NAME 
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE COLUMN_NAME IN ('columnA','ColumnB')
        AND TABLE_SCHEMA='YourDatabase';

Thanks

+2  A: 

If you're just trying to find out if the column exists, I'd do

SELECT 1
FROM information_schema.COLUMNS
WHERE COLUMN_NAME = 'column_name'
AND TABLE_NAME = 'table_name'
AND TABLE_SCHEMA = 'database_name'
LIMIT 1
chaos
cheers dude, this does the trick.
Drew
A: 

pseudocode:

DBQuery("SHOW COLUMNS FROM ".$table);
while (DBGetRow())
   {
   $columns[]=$access["Field"];
   }
dusoft