/ Published in: PHP
Drupal helper function to debug a table. Returns the contents and some explanation of a database table in a rendered format (HTML table).
**NOTE** You REALLY do not want to put this function behind any kind of menu_callback and/or on other pages. Use it for debugging only: Because we return any contents, regardless of permissions and so forth, you potentially open up your site to data mining and or session hijacking!
**NOTE** You REALLY do not want to put this function behind any kind of menu_callback and/or on other pages. Use it for debugging only: Because we return any contents, regardless of permissions and so forth, you potentially open up your site to data mining and or session hijacking!
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
function helpers_database_render_table($table_name) { $result = db_queryd('SHOW columns in {%s}', $table_name); while ($column = db_fetch_object($result)) { $header[] = t('@columnname (@columntype)', array('@columnname' => $column->Field, '@columntype' => $column->Type)); $columns[] = $column->Field; } $result = pager_query('SELECT * FROM {%s}', 50, 0, NULL, $table_name); while ($record = db_fetch_object($result)) { foreach($columns as $column) { //@TODO: include spans with title=fullresult on large results, and add ellipses in that case. $row[$column] = drupal_substr($record->$column, 0, 36); } $rows[] = $row; } $count = db_result(db_query("SELECT count(%s) FROM {%s}", $columns[0], $table_name)); $caption = t('SELECT * FROM {%table_name} resulted in %count results', array('%table_name' => $table_name, '%count' => $count)); }