Magento:如何检查Mysql列是否存在?


Answers:


18

您可以使用它来检查表列是否存在。

$installer = $this;
$installer->startSetup();

$connection = $installer->getConnection();

$tableName = $installer->getTable('your_table_name');
$columnName = 'testcolumn';

if ($connection->tableColumnExists($tableName, $columnName) === false) {
    $connection->addColumn($tableName, $columnName, array(
        'type'      => Varien_Db_Ddl_Table::TYPE_TEXT,
        'nullable'  => false,
        'length'    => 255,
        'after'     => null, // column name to insert new column after
        'comment'   => 'Title'
    ));  
}

是的,它是检查表的列。你试过这个吗?
Priyank
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.