how to add new value to ENUM list when installing my add-on? (ALTER TABLE ___ MODIFY COLUMN)

Earl

Well-known member
I'm writing an add-on to add-on
I need to modify one of his column and append new ENUM value to the list.

I know I can just modify the column with this code

Code:
public static function install()
{
   $db = XenForo_Application::getDb();

   $db->query("ALTER TABLE his_table MODIFY COLUMN his_column ENUM('post','thread','resource')");
}
But I have to get already existing list and just append the value 'resource' to the list.
In what way can I do this?

And I need to reverse that process with the uninstall code as well.

Somebody please help
 
Last edited:
You can get a column's datatype with Zend like this:
PHP:
  Zend_Db_Table::setDefaultAdapter($db);      
  $table = new Zend_Db_Table('tableName');
  $metaData = $table->info(Zend_Db_Table_Abstract::METADATA);
  $dataType = $metaData['columnName']['DATA_TYPE'];
After that you can extract the individual items with functions like preg_match(), explode() and trim() and then put it back together with the new item..
 
You can get a column's datatype with Zend like this:
PHP:
  Zend_Db_Table::setDefaultAdapter($db);     
  $table = new Zend_Db_Table('tableName');
  $metaData = $table->info(Zend_Db_Table_Abstract::METADATA);
  $dataType = $metaData['columnName']['DATA_TYPE'];
After that you can extract the individual items with functions like preg_match(), explode() and trim() and then put it back together with the new item..
That worked! Thanks a lot :cool:
 
Top Bottom