core-bundle/src/Resources/contao/library/Contao/Database.php
public function listFields($strTable, $blnNoCache=false)
	{
		if ($blnNoCache || !isset($this->arrCache[$strTable]))
		{
			$arrReturn = array();
			$objFields = $this->query("SHOW FULL COLUMNS FROM $strTable");

			while ($objFields->next())
			{
				$arrTmp = array();
				$arrChunks = preg_split('/(\([^\)]+\))/', $objFields->Type, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);

				$arrTmp['name'] = $objFields->Field;
				$arrTmp['type'] = $arrChunks[0];

				if (!empty($arrChunks[1]))
				{
					$arrChunks[1] = str_replace(array('(', ')'), '', $arrChunks[1]);

					// Handle enum fields (see #6387)
					if ($arrChunks[0] == 'enum')
					{
						$arrTmp['length'] = $arrChunks[1];
					}
					else
					{
						$arrSubChunks = explode(',', $arrChunks[1]);
						$arrTmp['length'] = trim($arrSubChunks[0]);

						if (!empty($arrSubChunks[1]))
						{
							$arrTmp['precision'] = trim($arrSubChunks[1]);
						}
					}
				}

				if (!empty($arrChunks[2]))
				{
					$arrTmp['attributes'] = trim($arrChunks[2]);
				}

				if ($objFields->Key != '')
				{
					switch ($objFields->Key)
					{
						case 'PRI':
							$arrTmp['index'] = 'PRIMARY';
							break;

						case 'UNI':
							$arrTmp['index'] = 'UNIQUE';
							break;

						case 'MUL':
							// Ignore
							break;

						default:
							$arrTmp['index'] = 'KEY';
							break;
					}
				}

				// Do not modify the order!
				$arrTmp['collation'] = $objFields->Collation;
				$arrTmp['null'] = ($objFields->Null == 'YES') ? 'NULL' : 'NOT NULL';
				$arrTmp['default'] = $objFields->Default;
				$arrTmp['extra'] = $objFields->Extra;
				$arrTmp['origtype'] = $objFields->Type;

				$arrReturn[] = $arrTmp;
			}

			$objIndex = $this->query("SHOW INDEXES FROM `$strTable`");

			while ($objIndex->next())
			{
				$strColumnName = $objIndex->Column_name;

				if ($objIndex->Sub_part != '')
				{
					$strColumnName .= '(' . $objIndex->Sub_part . ')';
				}

				$arrReturn[$objIndex->Key_name]['name'] = $objIndex->Key_name;
				$arrReturn[$objIndex->Key_name]['type'] = 'index';
				$arrReturn[$objIndex->Key_name]['index_fields'][] = $strColumnName;
				$arrReturn[$objIndex->Key_name]['index'] = (($objIndex->Non_unique == 0) ? 'UNIQUE' : 'KEY');
			}

			$this->arrCache[$strTable] = $arrReturn;
		}

		return $this->arrCache[$strTable];
	}
public function listFields($strTable, $blnNoCache=false)
	{
		if ($blnNoCache || !isset($this->arrCache[$strTable]))
		{
			$arrReturn = array();
			$objFields = $this->query("SHOW FULL COLUMNS FROM $strTable");

			while ($objFields->next())
			{
				$arrTmp = array();
				$arrChunks = preg_split('/(\([^\)]+\))/', $objFields->Type, -1, PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_NO_EMPTY);

				$arrTmp['name'] = $objFields->Field;
				$arrTmp['type'] = $arrChunks[0];

				if (!empty($arrChunks[1]))
				{
					$arrChunks[1] = str_replace(array('(', ')'), '', $arrChunks[1]);

					// Handle enum fields (see #6387)
					if ($arrChunks[0] == 'enum')
					{
						$arrTmp['length'] = $arrChunks[1];
					}
					else
					{
						$arrSubChunks = explode(',', $arrChunks[1]);
						$arrTmp['length'] = trim($arrSubChunks[0]);

						if (!empty($arrSubChunks[1]))
						{
							$arrTmp['precision'] = trim($arrSubChunks[1]);
						}
					}
				}

				if (!empty($arrChunks[2]))
				{
					$arrTmp['attributes'] = trim($arrChunks[2]);
				}

				if ($objFields->Key != '')
				{
					switch ($objFields->Key)
					{
						case 'PRI':
							$arrTmp['index'] = 'PRIMARY';
							break;

						case 'UNI':
							$arrTmp['index'] = 'UNIQUE';
							break;

						case 'MUL':
							// Ignore
							break;

						default:
							$arrTmp['index'] = 'KEY';
							break;
					}
				}

				// Do not modify the order!
				$arrTmp['collation'] = $objFields->Collation;
				$arrTmp['null'] = ($objFields->Null == 'YES') ? 'NULL' : 'NOT NULL';
				$arrTmp['default'] = $objFields->Default;
				$arrTmp['extra'] = $objFields->Extra;
				$arrTmp['origtype'] = $objFields->Type;

				$arrReturn[] = $arrTmp;
			}

			$objIndex = $this->query("SHOW INDEXES FROM `$strTable`");

			while ($objIndex->next())
			{
				$strColumnName = $objIndex->Column_name;

				if ($objIndex->Sub_part != '')
				{
					$strColumnName .= '(' . $objIndex->Sub_part . ')';
				}

				$arrReturn[$objIndex->Key_name]['name'] = $objIndex->Key_name;
				$arrReturn[$objIndex->Key_name]['type'] = 'index';
				$arrReturn[$objIndex->Key_name]['index_fields'][] = $strColumnName;
				$arrReturn[$objIndex->Key_name]['index'] = (($objIndex->Non_unique == 0) ? 'UNIQUE' : 'KEY');
			}

			$this->arrCache[$strTable] = $arrReturn;
		}

		return $this->arrCache[$strTable];
	}
public function listFields ( $ strTable , $ blnNoCache = false ) { if ( $ blnNoCache || ! isset ( $ this -> arrCache [ $ strTable ] ) ) { $ arrReturn = array ( ) ; $ objFields = $ this -> query ( "SHOW FULL COLUMNS FROM $strTable" ) ; while ( $ objFields -> next ( ) ) { $ arrTmp = array ( ) ; $ arrChunks = preg_split ( '/(\([^\)]+\))/' , $ objFields -> Type , - 1 , PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ) ; $ arrTmp [ 'name' ] = $ objFields -> Field ; $ arrTmp [ 'type' ] = $ arrChunks [ 0 ] ; if ( ! empty ( $ arrChunks [ 1 ] ) ) { $ arrChunks [ 1 ] = str_replace ( array ( '(' , ')' ) , '' , $ arrChunks [ 1 ] ) ; // Handle enum fields (see #6387) if ( $ arrChunks [ 0 ] == 'enum' ) { $ arrTmp [ 'length' ] = $ arrChunks [ 1 ] ; } else { $ arrSubChunks = explode ( ',' , $ arrChunks [ 1 ] ) ; $ arrTmp [ 'length' ] = trim ( $ arrSubChunks [ 0 ] ) ; if ( ! empty ( $ arrSubChunks [ 1 ] ) ) { $ arrTmp [ 'precision' ] = trim ( $ arrSubChunks [ 1 ] ) ; } } } if ( ! empty ( $ arrChunks [ 2 ] ) ) { $ arrTmp [ 'attributes' ] = trim ( $ arrChunks [ 2 ] ) ; } if ( $ objFields -> Key != '' ) { switch ( $ objFields -> Key ) { case 'PRI' : $ arrTmp [ 'index' ] = 'PRIMARY' ; break ; case 'UNI' : $ arrTmp [ 'index' ] = 'UNIQUE' ; break ; case 'MUL' : // Ignore break ; default : $ arrTmp [ 'index' ] = 'KEY' ; break ; } } // Do not modify the order! $ arrTmp [ 'collation' ] = $ objFields -> Collation ; $ arrTmp [ 'null' ] = ( $ objFields -> Null == 'YES' ) ? 'NULL' : 'NOT NULL' ; $ arrTmp [ 'default' ] = $ objFields -> Default ; $ arrTmp [ 'extra' ] = $ objFields -> Extra ; $ arrTmp [ 'origtype' ] = $ objFields -> Type ; $ arrReturn [ ] = $ arrTmp ; } $ objIndex = $ this -> query ( "SHOW INDEXES FROM `$strTable`" ) ; while ( $ objIndex -> next ( ) ) { $ strColumnName = $ objIndex -> Column_name ; if ( $ objIndex -> Sub_part != '' ) { $ strColumnName .= '(' . $ objIndex -> Sub_part . ')' ; } $ arrReturn [ $ objIndex -> Key_name ] [ 'name' ] = $ objIndex -> Key_name ; $ arrReturn [ $ objIndex -> Key_name ] [ 'type' ] = 'index' ; $ arrReturn [ $ objIndex -> Key_name ] [ 'index_fields' ] [ ] = $ strColumnName ; $ arrReturn [ $ objIndex -> Key_name ] [ 'index' ] = ( ( $ objIndex -> Non_unique == 0 ) ? 'UNIQUE' : 'KEY' ) ; } $ this -> arrCache [ $ strTable ] = $ arrReturn ; } return $ this -> arrCache [ $ strTable ] ; }
Return all columns of a particular table as array

@param string  $strTable   The table name
@param boolean $blnNoCache If true, the cache will be bypassed

@return array An array of column names
Return all columns of a particular table as array