uawdijnntqw1x1x1
IP : 216.73.216.39
Hostname : diefsweb003.fsit.ch
Kernel : Linux diefsweb003.fsit.ch 4.18.0-553.121.1.lve.el8.x86_64 #1 SMP Thu Apr 30 16:40:41 UTC 2026 x86_64
Disable Function : None :)
OS : Linux
PATH:
/
home
/
wirbesti
/
nousdecidons.ch
/
472b8
/
..
/
..
/
public_html
/
php
/
DBConnection.php
/
/
<?php /* * Class DBConnection * Create a database connection using PDO * @author jonahlyn@unm.edu * * Instructions for use: * * require_once('settings.config.php'); // Define db configuration arrays here * require_once('DBConnection.php'); // Include this file * * $database = new DBConnection($dbconfig); // Create new connection by passing in your configuration array * * $sqlSelect = "select * from ....."; // Select Statements: * $rows = $database->getQuery($sqlSelect); // Use this method to run select statements * * foreach($rows as $row){ * echo $row["column"] . "<br/>"; * } * * $sqlInsert = "insert into ...."; // Insert/Update/Delete Statements: * $count = $database->runQuery($sqlInsert); // Use this method to run inserts/updates/deletes * echo "number of records inserted: " . $count; * * $name = "jonahlyn"; // Prepared Statements: * $stmt = $database->dbc->prepare("insert into test (name) values (?)"); * $stmt->execute(array($name)); * */ class DBConnection { protected $_config; public $dbc; public function __construct(array $config) { $this->_config = $config; $this->getPDOConnection(); if (!$this->dbc) { $error = "Failed to establish database connection with config: " . json_encode($config, JSON_UNESCAPED_SLASHES | JSON_PARTIAL_OUTPUT_ON_ERROR); error_log($error); notifyTelegramError($error); throw new Exception($error); } } public function __destruct() { $this->dbc = null; } private function getPDOConnection() { if ($this->dbc == null) { $dsn = "{$this->_config['driver']}:host={$this->_config['host']};dbname={$this->_config['dbname']};charset=utf8mb4"; try { $this->dbc = new PDO( $dsn, $this->_config['username'], $this->_config['password'], [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4'] ); } catch (PDOException $e) { $error = "PDO connection error: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine(); error_log($error); notifyTelegramError($error); $this->dbc = null; } } } public function runQuery($sql) { try { $count = $this->dbc->exec($sql) or error_log("Query error: " . print_r($this->dbc->errorInfo(), true)); return $count; } catch (PDOException $e) { $error = "Run query error: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine(); error_log($error); notifyTelegramError($error); return false; } } public function getQuery($sql) { try { $stmt = $this->dbc->query($sql); $stmt->setFetchMode(PDO::FETCH_ASSOC); return $stmt; } catch (PDOException $e) { $error = "Get query error: " . $e->getMessage() . " in " . $e->getFile() . " on line " . $e->getLine(); error_log($error); notifyTelegramError($error); return false; } } } ?>
/home/wirbesti/nousdecidons.ch/472b8/../../public_html/php/DBConnection.php