You can try 'select `testcol` from `table`' and then check if you got a mysql_error(). -----Original Message----- From: Robin Vickery [mailto:robinv@xxxxxxxxx] Sent: Wednesday, August 13, 2008 10:33 AM To: php List Subject: Re: [PHP] If Column Exists 2008/8/12 VamVan <vamseevan@xxxxxxxxx>: > Hello, > > I am working on data migration for one mysql db to another using PHP. How do > I check if a particular table has a particular column. If not alter... > > Thanks > Use the information_schema: SELECT COUNT(*) AS column_exists FROM information_schema.COLUMNS WHERE TABLE_SCHEMA='db_name' AND TABLE_NAME='table_name' AND COLUMN_NAME='column_name'; -robin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php No virus found in this incoming message. Checked by AVG - http://www.avg.com Version: 8.0.138 / Virus Database: 270.6.2/1609 - Release Date: 13/08/2008 06:43 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php