Php Check If Column Exists Mysql
I am trying to create a Column for my table only if it does not exist.I have researched a lot but I could not find any solution yet.
In this episode, you will learn how to check if some table exists in MySQL database using PHP function, for that we will create a new PHP function that gets the table name as parameter and returns. Q&A for Work. Setup a private space for you and your coworkers to ask questions and share information. Learn more about Teams.
Is this really possible to conditionally create Column ?
3 Answers
MySQL ALTER TABLE
does not have IF EXISTS
specification.
You can do the following through using a stored proc or a programming language if this is something that you'll need to do on a regular basis:
Pseudocode: Global maper download cracked android.
Find if the column exists using the SQL below:
SELECT
column_name
FROMINFORMATION_SCHEMA
.COLUMNS
WHERETABLE_SCHEMA
=[Database Name]ANDTABLE_NAME
=[Table Name];If the above query returns a result then it means the column exists, otherwise you can go ahead and create the column.
Actually it does exist now! The below works on MYSQL 5.5.5 Maria DB 10.219
Php Check If Column Exists Mysql Server
Bonus, it works for MODIFY as well
You can use this solution, already mentioned on another StackOverFlow post: (Ref.: https://stackoverflow.com/a/31989541/)
Php Mysql Check If Value Exists In Column
MySQL - ALTER TABLE to add a column if it does not exist: