Automattic\WooCommerce\Internal\Utilities

DatabaseUtil::get_index_columns()publicWC 1.0

Get the columns of a given table index, or of the primary key.

Method of the class: DatabaseUtil{}

No Hooks.

Return

Array. The index columns. Empty array if the table or the index don't exist.

Usage

$DatabaseUtil = new DatabaseUtil();
$DatabaseUtil->get_index_columns( $table_name, $index_name ): array;
$table_name(string) (required)
Table name.
$index_name(string)
Index name, empty string for the primary key.
Default: ''

DatabaseUtil::get_index_columns() code WC 7.1.0

public function get_index_columns( string $table_name, string $index_name = '' ): array {
	global $wpdb;

	if ( empty( $index_name ) ) {
		$index_name = 'PRIMARY';
	}

	// phpcs:disable WordPress.DB.PreparedSQL
	return $wpdb->get_col(
		"
SELECT column_name FROM INFORMATION_SCHEMA.STATISTICS
WHERE table_name='$table_name'
AND table_schema='" . DB_NAME . "'
AND index_name='$index_name'"
	);
	// phpcs:enable WordPress.DB.PreparedSQL
}