
Php Check If Column Exists Mysql
Is there a query that can be run on a database to see if a table (or column within a table) exists prior to performing an action (insert, update, etc) on the colum or table? I have an app, and want to be able to check to make sure that the various tables and columns exist before attempting to read/write to them (to reduce the possiblity of a.
- Related Questions & Answers
- Selected Reading
To understand whether a column exist or not, we have the following approaches −
- With the help of DESC command
- Using SHOW command
Firstly, we will create a table with columns −
Tupac discography torrent. In the first approach, we will get the entire column name with meaningful information. The syntax is as follows −
Let us apply the above query to check whether the column name exists or not. However, this approach is not good since it display all the columns.
The following is the output
The second approach is better, since we can check for a single column. The syntax is asfollows −
Now, I am applying the above query to check whether colum exist or not. The query is asfollows −

The following is the output