57 lines
2.2 KiB
PHP
57 lines
2.2 KiB
PHP
<?php
|
|
header('Content-Type: application/json');
|
|
$R = ['ts' => date('c'), 'results' => []];
|
|
|
|
try {
|
|
$pdo = new PDO('pgsql:host=10.1.0.3;port=5432;dbname=adx_system', 'admin', 'admin123');
|
|
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
// 3 tables à tester
|
|
$tables = ['admin.inbox_replies', 'admin.weval_messages', 'admin.wevia_messages', 'admin.hamid_messages'];
|
|
|
|
foreach ($tables as $t) {
|
|
try {
|
|
// Count
|
|
$cnt = $pdo->query("SELECT COUNT(*) FROM $t")->fetchColumn();
|
|
|
|
// Columns
|
|
$cols_stmt = $pdo->query("SELECT column_name FROM information_schema.columns WHERE table_schema='admin' AND table_name='" . substr($t, strpos($t,'.')+1) . "' LIMIT 15");
|
|
$cols = $cols_stmt->fetchAll(PDO::FETCH_COLUMN);
|
|
|
|
// Sample row
|
|
$sample = $pdo->query("SELECT * FROM $t LIMIT 1")->fetch(PDO::FETCH_ASSOC);
|
|
|
|
$R['results'][$t] = [
|
|
'count' => $cnt,
|
|
'columns' => $cols,
|
|
'sample_keys' => $sample ? array_keys($sample) : []
|
|
];
|
|
} catch (Exception $e) {
|
|
$R['results'][$t] = ['error' => $e->getMessage()];
|
|
}
|
|
}
|
|
|
|
// Search Kaouther in all 3
|
|
foreach (['admin.inbox_replies', 'admin.weval_messages', 'admin.wevia_messages'] as $t) {
|
|
try {
|
|
// Try different column names
|
|
foreach (['sender', 'from_email', 'from_addr', 'email_from', 'from', 'sender_email'] as $col) {
|
|
try {
|
|
$stmt = $pdo->prepare("SELECT * FROM $t WHERE $col ILIKE :e OR subject ILIKE :s ORDER BY received_at DESC LIMIT 3");
|
|
$stmt->execute([':e' => '%najar%', ':s' => '%HCP%']);
|
|
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
if ($rows) {
|
|
$R['found_in_' . $t] = ['via_col' => $col, 'rows' => $rows];
|
|
break;
|
|
}
|
|
} catch (Exception $e) { /* col doesn't exist */ }
|
|
}
|
|
} catch (Exception $e) { /* table issue */ }
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
$R['error'] = $e->getMessage();
|
|
}
|
|
|
|
echo json_encode($R, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE);
|