1000) { // Truncate very long values $value = substr($value, 0, 1000) . '... [truncated]'; } // Ensure proper encoding $csv_row[] = $value; } fputcsv($output, $csv_row); $record_count++; // Flush buffer every 100 rows to prevent memory issues if ($record_count % 100 === 0) { flush(); } } error_log("Table export successful: $table_name - $record_count records"); // Close connections fclose($output); pg_close($dbconn); exit; } catch (Exception $e) { // If there was an error, output an error CSV header('Content-Type: text/csv; charset=utf-8'); header('Content-Disposition: attachment; filename="error_report.csv"'); $output = fopen('php://output', 'w'); fwrite($output, "\xEF\xBB\xBF"); fputcsv($output, ['Error Report - Database Table Export']); fputcsv($output, ['']); fputcsv($output, ['Status', 'Failed']); fputcsv($output, ['Error', $e->getMessage()]); fputcsv($output, ['Table', $table_name]); fputcsv($output, ['Time', date('Y-m-d H:i:s')]); fclose($output); exit; } } // Main page - list all tables $db_url = "postgres://read-only:p147df9f6343b30dc75381d0198126b2851cdee0cb3ca540d2f12769b73c0e302@ec2-3-255-54-175.eu-west-1.compute.amazonaws.com:5432/d5r8pqj7lsdfmc"; try { // Parse the database URL $db_parts = parse_url($db_url); $db_host = $db_parts['host']; $db_port = $db_parts['port']; $db_name = substr($db_parts['path'], 1); $db_user = $db_parts['user']; $db_pass = $db_parts['pass']; // Create PostgreSQL connection $conn_string = "host=$db_host port=$db_port dbname=$db_name user=$db_user password=$db_pass sslmode=require"; $dbconn = pg_connect($conn_string); if (!$dbconn) { throw new Exception('Unable to establish connection with Production Passport database'); } // Get all tables from the public schema $query = " SELECT table_name, obj_description(('public.' || table_name)::regclass, 'pg_class') as table_comment FROM information_schema.tables WHERE table_schema = 'public' AND table_type = 'BASE TABLE' ORDER BY table_name "; $result = pg_query($dbconn, $query); if (!$result) { // Alternative query if the first one fails $query = "SELECT tablename as table_name FROM pg_tables WHERE schemaname = 'public' ORDER BY tablename"; $result = pg_query($dbconn, $query); } $tables = []; while ($row = pg_fetch_assoc($result)) { // Get row count for each table $table_name = $row['table_name']; $count_query = "SELECT COUNT(*) as row_count FROM public." . pg_escape_identifier($dbconn, $table_name); $count_result = pg_query($dbconn, $count_query); $count_row = pg_fetch_assoc($count_result); $row['row_count'] = $count_row ? $count_row['row_count'] : 0; $tables[] = $row; } pg_close($dbconn); } catch (Exception $e) { $error = $e->getMessage(); $tables = []; } ?>
Browse and export any table as CSV with one click
Host:
Database:
User:
Time:
No description available
Could not retrieve tables from the database.