How can I check if mysql table column even exists?

后端 未结 8 983
闹比i
闹比i 2020-12-30 08:44

How can I check if mysql table field even exists ?

The column name is \'price\' and I need to see if it exists.

Haven\'t understood really how the \'EXISTS\'

8条回答
  •  不思量自难忘°
    2020-12-30 09:13

    I just done something like this using this function for Wordpress, this for update tables that having new chnages on it

    public function alterTable() {
    
        $table_name = $this->prefix . $this->tables['name'];
    
        $select = "select * from `{$table_name}` where 0=0 limit 1;";
        $query = $this->db->get_results($select, ARRAY_A);
    
    
        if (isset($query[0]) && !key_exists('adv', $query[0])) {
            $sql = "ALTER TABLE `{$table_name}` ADD `me` INT NULL DEFAULT NULL ;";
            $this->db->query($sql);
        }
    

    }

提交回复
热议问题