ВОТ СТО ПИШЕТ sTableName = ($sTableName) ? $dbsettings['prefix'].$sTableName:''; $this->sDbName = ($sDbName) ? $sDbName:$dbsettings['name']; $this->sDbHost = $dbsettings['server']; $this->sDbUser = $dbsettings['user']; $this->sDbPass = $dbsettings['pass']; $this->sDbPref = $dbsettings['prefix']; $this->dLink = mysql_connect($this->sDbHost,$this->sDbUser,$this->sDbPass) or $this->aErrors[]='Could not connect to DB'; $this->bReturnRow = false; if (!isset($GLOBALS['iQUERYCOUNTER'])) $GLOBALS['iQUERYCOUNTER'] = 1; if ($this->dLink) { if (mysql_select_db($this->sDbName, $this->dLink)) { // $this->exist = ($this->sTableName && $this->TableExist($this->sTableName)) ? true:false; $this->exist = ($this->sTableName) ? true:false; mysql_query("SET NAMES 'utf8'"); } } } // Подсчет количества запросов function _incQuery() { $this->iQueryCounter++; if (isset($GLOBALS['_iQueryCounter'])) $GLOBALS['_iQueryCounter']++; } // Создание новой таблицы в базе function CreateTable($sQuery) { mysql_query(preg_replace('/(\r\n)|(\n)/','',$sQuery)) or $this->aErrors[]="Invalid query: $sQuery";; } // �?нформация о таблице function GetTableInfo($sTableName='') { if (!$sTableName) $sTableName = $this->sTableName; $sQuery="SELECT * FROM {$this->sTableName} LIMIT 0,1"; $queryRes = mysql_query($sQuery,$this->dLink) or $this->aErrors[]="Invalid query: $sQuery"; $iNumFields = mysql_num_fields($queryRes); for ($i=0; $i<$iNumFields; $i++) { $sName=mysql_field_name($queryRes, $i); $this->aTableInfo[$sTableName][$sName]['type'] = mysql_field_type($queryRes, $i); $this->aTableInfo[$sTableName][$sName]['len'] = mysql_field_len($queryRes, $i); $this->aTableInfo[$sTableName][$sName]['flags'] = mysql_field_flags($queryRes, $i); } } // Проверяет, существует ли таблица function TableExist() { if (!count($this->aTableList)) { $this->aTableList = array(); $res=@mysql_list_tables($this->sDbName,$this->dLink); while ($row=mysql_fetch_row($res)) { $this->aTableList[] = $row[0]; } } $result=(array_search($this->sTableName,$this->aTableList)===false) ? false:true; return $result; } // Запрос function Query($sQuery,$bEcho=false) { // echo $sQuery.$this->exist; if ($this->exist) { $sQuery=str_replace('#table',$this->sTableName,$sQuery); $sQuery=str_replace('#pref_',$this->sDbPref,$sQuery); $sQuery=str_replace('#preF',$this->sDbPref,$sQuery); if (preg_match('/SELECT/',$sQuery) && preg_match('/LIMIT ([0-9\,]+)/',$sQuery,$aMatches)) { $sQuery=preg_replace('/^[\s]*SELECT/i','SELECT SQL_CALC_FOUND_ROWS',$sQuery); //echo $sQuery.' '; $this->queryRes = mysql_query($sQuery,$this->dLink) or $this->aErrors[]="Invalid query: $sQuery"; $queryRes = mysql_query('SELECT FOUND_ROWS();',$this->dLink); $row = mysql_fetch_row($queryRes); $this->iAffectedRows = $row[0]; } else $this->queryRes = mysql_query($sQuery,$this->dLink) or $this->aErrors[]="Invalid query: $sQuery"; $this->sQuery = $sQuery; $this->_incQuery(); if ($bEcho) echo " {$GLOBALS['iQUERYCOUNTER']} $sQuery "; //echo mysql_error($this->dLink); } } // Возвращает строку таблицы function GetRow($where=null) { if (!$this->exist) return false; if ($where===null) { if ($this->queryRes) { if ($this->bReturnRow) return mysql_fetch_assoc($this->queryRes); else return ($this->r = mysql_fetch_assoc($this-> Добавлено через 55 секунд да кстате хоть на форум вошол!