Skip to content

Instantly share code, notes, and snippets.

@KarelWintersky
Last active August 15, 2016 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KarelWintersky/90f1a2a0d3340cf4ba3b5e106afac589 to your computer and use it in GitHub Desktop.
Save KarelWintersky/90f1a2a0d3340cf4ba3b5e106afac589 to your computer and use it in GitHub Desktop.
Fiddling with MySQL: information_scheme
$check_tables = array(
'table_1', 'table_2', 'table_3'
);
$check_tables_strs = array_map(function($n){
return "SELECT '{$n}' as table_name";
}, $check_tables);
$unions = implode($check_tables_strs, " UNION ALL \n");
$information_scheme_query = <<<IBQ
SELECT
tn.table_name, t.table_rows, t.data_length,
DATE_FORMAT(t.update_time, '{$date_format}') AS update_time_visible, t.update_time
FROM (
{$unions}
) tn LEFT JOIN
information_schema.tables t
ON tn.table_name = t.table_name;
IBQ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment