/** * Returns an array describing the specified table, or false if the table * does not exist in the database. * The array contains one array per database column, keyed by the column * name. To see the structure of the array you could try: * <code> * print_r( MyActiveRecord::Columns('your_table') ); * </code> * * @static * @param string strTable The name of the database table * @return array Table columns. False if the table does not exist. */ static function Columns($strTable) { $strTable = MyActiveRecord::class2Table($strTable); // cache results locally static $cache = array(); // already cached? return columns array if (isset($cache[$strTable])) { return $cache[$strTable]; } else { if ($rscResult = MyActiveRecord::Query("SHOW COLUMNS FROM `{$strTable}`")) { $arrFields = array(); while ($col = mysql_fetch_assoc($rscResult)) { $arrFields[$col['Field']] = $col; } mysql_free_result($rscResult); // cache results for future use and return return $cache[$strTable] = $arrFields; } else { trigger_error("MyActiveRecord::Columns() - could not decribe table {$strTable}", E_USER_WARNING); return false; } } }