Problems with new fields in PHP mysql

Database table table
New field json

how can I tell if the json field exists? If it does not exist, create a field json in varchar format

because the code is common to many programs. Some databases already have the json field, and some do not.. How to judge when inserting.

Mar.16,2021

there is a COLUMNS table in MySQL's information_schema library that records the field information of all tables in all mysql libraries. So check whether there is a json field in each table directly according to the information of this table, and then create it.

IF NOT EXISTS( SELECT NULL
            FROM INFORMATION_SCHEMA.COLUMNS
           WHERE table_name = 'tablename'
             AND table_schema = 'db_name'
             AND column_name = 'json')  THEN
  ALTER TABLE `TableName` ADD `json` VARCHAR(255) NOT NULL;
END IF;

IF NOT EXISTS(SELECT 1 FROM  information_schema.COLUMNS WHERE TABLE_SCHEMA='()' AND table_name='table' AND COLUMN_NAME='json') THEN
     ALTER TABLE `table` ADD `json` VARCHAR(255) NOT NULL;
END IF;
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36bd5-2c02d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36bd5-2c02d.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?