wpdb::get_col_info() WordPress Method

The wpdb::get_col_info() method is used to get column information from a database table. This can be useful when trying to determine the structure of a database table.

wpdb::get_col_info( string $info_type = 'name', int $col_offset = -1 ) #

Retrieves column metadata from the last query.


Parameters

$info_type

(string)(Optional) Possible values include 'name', 'table', 'def', 'max_length', 'not_null', 'primary_key', 'multiple_key', 'unique_key', 'numeric', 'blob', 'type', 'unsigned', 'zerofill'.

Default value: 'name'

$col_offset

(int)(Optional) 0: col name. 1: which table the col's in. 2: col's max length. 3: if the col is numeric. 4: col's type.

Default value: -1


Top ↑

Return

(mixed) Column results.


Top ↑

Source

File: wp-includes/wp-db.php

	public function get_col_info( $info_type = 'name', $col_offset = -1 ) {
		$this->load_col_info();

		if ( $this->col_info ) {
			if ( -1 === $col_offset ) {
				$i         = 0;
				$new_array = array();
				foreach ( (array) $this->col_info as $col ) {
					$new_array[ $i ] = $col->{$info_type};
					$i++;
				}
				return $new_array;
			} else {
				return $this->col_info[ $col_offset ]->{$info_type};
			}
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
0.71Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.