Skip to content

Commit

Permalink
Table: add columns() method.
Browse files Browse the repository at this point in the history
This change adds the ability to query a database table and get its columns as standard objects.

Fixes #111.
  • Loading branch information
JJJ committed May 28, 2021
1 parent d2834b9 commit fe6e235
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions table.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,31 @@ public function exists() {
return $this->is_success( $result );
}

/**
* Get columns from table.
*
* @since 1.2.0
*
* @return array
*/
public function columns() {

// Get the database interface
$db = $this->get_db();

// Bail if no database interface is available
if ( empty( $db ) ) {
return false;
}

// Query statement
$query = "SHOW FULL COLUMNS FROM {$this->table_name}";
$result = $db->get_results( $query );

// Does the table have columns?
return $this->is_success( $result );
}

/**
* Create the table.
*
Expand Down

0 comments on commit fe6e235

Please sign in to comment.