how to check wether the column in table exists or not in php
You can get the columns of the table and just check if the column you're looking for is available in the result of that.
You can execute mysql_query() to issue an SQL SHOW COLUMNS FROM table [LIKE 'name']. This will give you all columns including specifications.
$result = mysql_query($query);
if(!$result)
{
print "Error";
}
Essentially, if the column doesn't exist, a result won't be brought up and and the variable won't be set.
Concretely it depends on your database.
For example with Oracle databases you can query USER_TAB_COLUMNS
or ALL_TAB_COLUMNS
.
There exists however abstract solutions that let you to be not tight to a specific implementation. Zend comes to my mind but there certainly exist others. For example with Zend you can do:
$cols = $table->info(Zend_Db_Table_Abstract::COLS);
Here is the manual for Zend table: http://framework.zend.com/manual/en/zend.db.table.html