Forum Moderators: coopster

Message Too Old, No Replies

Check if column in mysql exists with php

         

Twisted Mind

1:45 pm on Jan 13, 2006 (gmt 0)

10+ Year Member



Hi i wanted to know if you can let php check if a column exists in a table.
cuz i have a 1 script script and i want it to check a table for having the following columns and if 1 o fthem is missing it would automaticly add the column.

U understand? pleas helpzos mezos :p

Twisted Mind

3:12 pm on Jan 13, 2006 (gmt 0)

10+ Year Member



Please tell me how to check if a collumn exists i really need this...

stu_uk

3:25 pm on Jan 13, 2006 (gmt 0)

10+ Year Member



use

SHOW COLUMNS FROM tablename FROM dbname;

and check to see if the column name is in the result

Twisted Mind

3:27 pm on Jan 13, 2006 (gmt 0)

10+ Year Member



I know this but i want a script to autodetect if it is there and if not to create it...

stu_uk

3:30 pm on Jan 13, 2006 (gmt 0)

10+ Year Member



if you are using php you might want to look up the mysql_fetch_field function

Twisted Mind

8:32 am on Jan 16, 2006 (gmt 0)

10+ Year Member



Ill try that

Twisted Mind

8:58 am on Jan 16, 2006 (gmt 0)

10+ Year Member



lol tryd a script there and i get Page cannot be displayed and the wole site stops working i just used the example on my table :S