Php Check If Column Exists Mysql

Posted on
  1. Php Check If Column Exists Mysql Server
  2. Php Mysql Check If Value Exists In Column

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 ?

zzzzzzzzzz

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:

Windows

Pseudocode: Global maper download cracked android.

  • Find if the column exists using the SQL below:

    SELECT column_nameFROM INFORMATION_SCHEMA.COLUMNSWHERE TABLE_SCHEMA=[Database Name]AND TABLE_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.

thatsaruthatsaru

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

ParoofkeyParoofkey

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:

Anto JoseAnto Jose

Not the answer you're looking for? Browse other questions tagged mysqlmysql-5.5mysql-5.6mysql-5.1 or ask your own question.