26 lines
886 B
PHP
26 lines
886 B
PHP
<?php
|
|
$c = pg_connect("host=127.0.0.1 port=5432 dbname=adx_system user=admin password=admin123");
|
|
|
|
// Find all contacts-like tables
|
|
$r = pg_query($c, "SELECT table_schema, table_name FROM information_schema.tables WHERE table_name ILIKE '%contact%' ORDER BY 1,2");
|
|
echo "Contact tables:\n";
|
|
$tables = [];
|
|
while($row = pg_fetch_row($r)) {
|
|
$tables[] = "$row[0].$row[1]";
|
|
echo " $row[0].$row[1]\n";
|
|
}
|
|
|
|
echo "\nRow counts:\n";
|
|
foreach ($tables as $t) {
|
|
$r = @pg_query($c, "SELECT COUNT(*) FROM $t");
|
|
if ($r) {
|
|
$n = pg_fetch_row($r)[0];
|
|
echo " $t = $n\n";
|
|
}
|
|
}
|
|
|
|
// Find which table has 'orphans_contacts' ref in code or KPI
|
|
$r = pg_query($c, "SELECT table_schema, table_name FROM information_schema.columns WHERE column_name = 'company_id' LIMIT 10");
|
|
echo "\nTables with company_id column:\n";
|
|
while($row = pg_fetch_row($r)) echo " $row[0].$row[1]\n";
|