mysql数据库表中判断字段是否存在,如果不存在则创建该字段

时间:2022-09-21 16:51:24

 

$key_answer     = 'answer'.$question_num; 
                  $test_question = mysql_query('DESCRIBE question_manage {$key_question}'); 
                $test_question = mysql_fetch_array($test_question); 
                if(!is_array($test_question)){ 
                    mysql_query("ALTER TABLE `question_manage` ADD `{$key_question}` VARCHAR( 500 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL "); 
                }