Skip to content

Instantly share code, notes, and snippets.

@deyvin
Created October 17, 2013 21:02
Show Gist options
  • Save deyvin/7032156 to your computer and use it in GitHub Desktop.
Save deyvin/7032156 to your computer and use it in GitHub Desktop.
Dynamic sql count - all mysql database tables
<?php
mysql_connect("localhost", "root", "1234");
$banco = 'ecommerce';
$db_selected = mysql_select_db($banco);
$result = mysql_query('SHOW TABLES');
while($row = mysql_fetch_assoc($result)) {
$resultTable = mysql_query("SELECT COUNT(*) FROM " . $row['Tables_in_' . $banco]);
$rsTable = mysql_fetch_assoc($resultTable);
if(strstr($row['Tables_in_' . $banco], 'carrier', true)) {
$carrier[] = $row['Tables_in_' . $banco] . " Registros: " . $rsTable['COUNT(*)'];
}
}
print_r($carrier);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment