2021-12-05 12:56:23 +00:00
|
|
|
<!DOCTYPE html>
|
|
|
|
<?php
|
|
|
|
/*
|
2021-12-05 13:04:53 +00:00
|
|
|
* Copyright (C) 2021 Eichehome
|
2021-12-05 12:56:23 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stellt eine Verbindung zu einer DB bereit
|
|
|
|
*
|
2022-01-23 11:16:08 +00:00
|
|
|
* @author Eichehome
|
2021-12-05 12:56:23 +00:00
|
|
|
*/
|
|
|
|
class DBClass extends stdClass
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Zeiger auf die DB
|
|
|
|
* @var PDO
|
|
|
|
*/
|
|
|
|
private $pdo = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Das Abgrage-Statement
|
|
|
|
* @var PDOStatement
|
|
|
|
*/
|
|
|
|
private $stmt = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Verbindet mit Server und DB
|
|
|
|
* @param string $dbname Name der Datenbank
|
|
|
|
* @param string $user Benutzername
|
|
|
|
* @param string $passwort Passwort des Benutzers
|
|
|
|
* @param string $host Adresse des Datenbankservers
|
|
|
|
*/
|
|
|
|
public function __construct($dbname, $user, $passwort, $host)
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$this->pdo = new PDO('mysql:host=' . $host . ';dbname=' . $dbname, $user, $passwort);
|
|
|
|
} catch (PDOException $e) {
|
|
|
|
echo $e->getMessage();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Führt eine SQL-Anweisung ohne Rückgabe eines Datensatzes aus
|
|
|
|
* @param string $querystring
|
|
|
|
* @param array $params
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function query($querystring, array $params = array())
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
$this->stmt = $this->pdo->prepare($querystring);
|
|
|
|
return $this->stmt->execute($params);
|
|
|
|
} catch (PDOException $ex) {
|
|
|
|
$this->stmt = null;
|
|
|
|
} catch (Exception $ex) {
|
|
|
|
$this->stmt = null;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Führt eine SQL-Anweisung mit Rückgabe eines Datensatzes aus
|
|
|
|
* @param string $querystring
|
|
|
|
* @param array $params
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function select($querystring, array $params = array())
|
|
|
|
{
|
|
|
|
if ($this->query($querystring, $params)) {
|
|
|
|
return $this->stmt->fetchAll();
|
|
|
|
} else {
|
|
|
|
return array();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|