Re: RE: [PHP] If Column Exists
| From: | Evert Lammerts | Date: | Wed, 13 Aug 2008 17:40:54 +0000 |
| Subject: | Re: RE: [PHP] If Column Exists | ||
| References: | 1 2 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-45215@lists.php.net to get a copy of this message | ||
SHOW COLUMNS FROM tablename;
Also check http://dev.mysql.com/doc/refman/5.0/en/
On Wed, Aug 13, 2008 at 3:02 PM, Simcha <simcha@syounger.com> wrote:
> 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
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>