1
0
Fork 0
mirror of https://github.com/Oreolek/ifhub.club.git synced 2024-06-29 04:55:02 +03:00

!isFieldExists() для проверки существоания поля в таблице

This commit is contained in:
Mzhelskiy Maxim 2011-04-26 16:43:26 +00:00
parent 93ed300eba
commit 7ecb5c69d4
2 changed files with 39 additions and 0 deletions

View file

@ -194,6 +194,17 @@ abstract class Plugin extends Object {
return $this->Database_isTableExists($sTableName);
}
/**
* Проверяет наличие поля в таблице
*
* @param unknown_type $sTableName
* @param unknown_type $sFieldName
* @return unknown
*/
protected function isFieldExists($sTableName,$sFieldName) {
return $this->Database_isFieldExists($sTableName,$sFieldName);
}
/**
* Получает версию плагина
*

View file

@ -162,6 +162,13 @@ class ModuleDatabase extends Module {
return array('result'=>false,'errors'=>$aErrors);
}
/**
* Проверяет существование таблицы
*
* @param string $sTableName
* @param array $aConfig
* @return bool
*/
public function isTableExists($sTableName,$aConfig=null) {
$sTableName = str_replace('prefix_', Config::Get('db.table.prefix'), $sTableName);
$sQuery="SHOW TABLES LIKE '{$sTableName}'";
@ -170,6 +177,27 @@ class ModuleDatabase extends Module {
}
return false;
}
/**
* Проверяет существование поля в таблице
*
* @param string $sTableName
* @param string $sFieldName
* @param array $aConfig
* @return bool
*/
public function isFieldExists($sTableName,$sFieldName,$aConfig=null) {
$sTableName = str_replace('prefix_', Config::Get('db.table.prefix'), $sTableName);
$sQuery="SHOW FIELDS FROM '{$sTableName}'";
if ($aRows=$this->GetConnect($aConfig)->select($sQuery)) {
foreach ($aRows as $aRow){
if ($aRow['Field'] == $sFieldName){
return true;
}
}
}
return false;
}
}