dbhelper.php (1806B)
1 <?php 2 function getColumnValues($table, $columnName) { 3 $db = dbconnection::getInstance(); 4 $pdo = $db->getPdo(); 5 6 try { 7 $query = "SELECT DISTINCT $columnName FROM $table"; 8 $stmt = $pdo->prepare($query); 9 $stmt->execute(); 10 11 $values = $stmt->fetchAll(PDO::FETCH_ASSOC); 12 13 $values = array_column($values, $columnName); 14 15 return $values; 16 } catch (PDOException $e) { 17 echo "Error: " . $e->getMessage(); 18 return []; 19 } 20 } 21 22 function GetCompositeKeyValues($table, $columns) { 23 $db = dbconnection::getInstance(); 24 $pdo = $db->getPdo(); 25 26 try { 27 $query = "SELECT CONCAT_WS(', ', " . implode(", ", $columns) . ") AS composite_key FROM $table"; 28 $stmt = $pdo->prepare($query); 29 $stmt->execute(); 30 31 $values = $stmt->fetchAll(PDO::FETCH_COLUMN); 32 33 return $values; 34 } catch (PDOException $e) { 35 echo "Error: " . $e->getMessage(); 36 return []; 37 } 38 } 39 40 function getTableCount($table) { 41 $db = dbconnection::getInstance(); 42 $pdo = $db->getPdo(); 43 44 try { 45 $query = "SELECT COUNT(*) FROM $table"; 46 $stmt = $pdo->prepare($query); 47 $stmt->execute(); 48 49 return (int) $stmt->fetchColumn(); 50 } catch (PDOException $e) { 51 echo "Error: " . $e->getMessage(); 52 return 0; 53 } 54 } 55 56 function RefreshTables() { 57 $location = $_SERVER['PHP_SELF']; 58 if (!empty($_SERVER['QUERY_STRING'])) { 59 $location .= "?" . $_SERVER['QUERY_STRING']; 60 } 61 header("Location: " . $location); 62 exit(); 63 } 64 ?>