You are here

function dba_get_fields in Database Administration 7

Same name and namespace in other branches
  1. 5 dba.module \dba_get_fields()

Attempt to get table fields in a db agnositc way. Simply request one row of the table, and parse the output. This won't work if the table is empty.

1 call to dba_get_fields()
dba_view_table in ./dba.admin.inc

File

./dba.admin.inc, line 157

Code

function dba_get_fields($table) {
  $fields = array();
  $conn = db_set_active(variable_get('dba_active_database', 'default'));
  $query = db_select($table)
    ->fields($table)
    ->extend('PagerDefault');
  $rows = $query
    ->limit(1)
    ->execute();
  db_set_active($conn);
  while ($row = $rows
    ->fetchAssoc()) {
    foreach ($row as $key => $value) {
      $fields[$key] = $key;
    }
  }
  return $fields;
}