update
This commit is contained in:
34
modules/empikmarketplace/src/Utils/DbUtils.php
Normal file
34
modules/empikmarketplace/src/Utils/DbUtils.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Empik\Marketplace\Utils;
|
||||
|
||||
class DbUtils
|
||||
{
|
||||
public static function safeAddColumn($table, $column, $def)
|
||||
{
|
||||
if (!self::columnExists($table, $column))
|
||||
return \Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . $table . '` ADD `' . $column . '` ' . $def);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function columnExists($table, $column)
|
||||
{
|
||||
$query = 'SELECT COUNT(*)
|
||||
FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE()
|
||||
AND COLUMN_NAME = \'' . pSQL($column) . '\'
|
||||
AND TABLE_NAME = \'' . _DB_PREFIX_ . pSQL($table) . '\'';
|
||||
|
||||
return (bool)\Db::getInstance()->getValue($query);
|
||||
}
|
||||
|
||||
public static function safeDropColumn($table, $column)
|
||||
{
|
||||
if (self::columnExists($table, $column)) {
|
||||
\Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . $table . '` DROP `' . $column . '` ');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user