Re: [PHP] If Column Exists

2008-08-17 Thread Luke
There is IF EXISTS for tables, is there the same thing for columns in the
table
like

IF EXISTS column IN TABLE table

? Just an idea

2008/8/13 VamVan <[EMAIL PROTECTED]>

> Interesting. Thanks guys!!
>
> On Wed, Aug 13, 2008 at 1:32 AM, Robin Vickery <[EMAIL PROTECTED]> wrote:
>
> > 2008/8/12 VamVan <[EMAIL PROTECTED]>:
> > > 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
> >
> >
>



-- 
Luke Slater


Re: [PHP] If Column Exists

2008-08-13 Thread VamVan
Interesting. Thanks guys!!

On Wed, Aug 13, 2008 at 1:32 AM, Robin Vickery <[EMAIL PROTECTED]> wrote:

> 2008/8/12 VamVan <[EMAIL PROTECTED]>:
> > 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
>
>


Re: [PHP] If Column Exists

2008-08-13 Thread Robin Vickery
2008/8/12 VamVan <[EMAIL PROTECTED]>:
> 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



RE: [PHP] If Column Exists

2008-08-13 Thread Per Jessen
Jay Blanchard wrote:

> [snip]
> 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...
> [/snip]
> 
> Use DESCRIBE TABLE;
> 

Then you'd have to parse the output - how about

SELECT  FROM  LIMIT 1  ?

The query will fail if the column doesn't exist.


/Per Jessen, Zürich


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] If Column Exists

2008-08-12 Thread Jay Blanchard
[snip]
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...
[/snip]

Use DESCRIBE TABLE;

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] If Column Exists

2008-08-12 Thread VamVan
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