RE: [PHP] If Column Exists
| From: | Simcha | Date: | Wed, 13 Aug 2008 13:02:25 +0000 |
| Subject: | RE: [PHP] If Column Exists | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-45214@lists.php.net to get a copy of this message | ||
You can try 'select
testcol from table' and then check if you
got a
mysql_error().
-----Original Message-----
From: Robin Vickery [mailto:robinv@gmail.com]
Sent: Wednesday, August 13, 2008 10:33 AM
To: php List
Subject: Re: [PHP] If Column Exists
2008/8/12 VamVan <vamseevan@gmail.com>:
> 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