2020-11-19 23:10:06 +01:00
|
|
|
<?php
|
|
|
|
// Datenbank-Verbindungsparameter
|
|
|
|
require_once ('config.php');
|
|
|
|
|
|
|
|
class DbUtils {
|
2020-11-19 23:12:37 +01:00
|
|
|
public static $TYPE_LOGO = 1;
|
|
|
|
public static $TYPE_PRODIMG = 2;
|
2020-11-19 23:10:06 +01:00
|
|
|
|
|
|
|
public static function openDbAndReturnPdoStatic () {
|
|
|
|
$dsn = 'mysql:host=' . MYSQL_HOST . ';dbname=' . MYSQL_DB;
|
|
|
|
$user = MYSQL_USER;
|
|
|
|
$password = MYSQL_PASSWORD;
|
|
|
|
$pdo = null;
|
|
|
|
try {
|
|
|
|
$pdo = new PDO($dsn, $user, $password);
|
|
|
|
$pdo ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
|
|
}
|
|
|
|
catch (PDOException $e) {
|
|
|
|
echo 'Connection failed: ' . $e->getMessage();
|
|
|
|
}
|
|
|
|
return $pdo;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static function substTableAlias($sqlString) {
|
|
|
|
$out = str_replace("%ossystem%",TAB_PREFIX . 'ossystem',$sqlString);
|
|
|
|
$out = str_replace("%gueststatus%", TAB_PREFIX . 'gueststatus',$out);
|
|
|
|
$out = str_replace("%queue%", TAB_PREFIX . 'queue',$out);
|
2020-11-19 23:12:37 +01:00
|
|
|
$out = str_replace("%images%", TAB_PREFIX . 'images',$out);
|
2020-11-19 23:10:06 +01:00
|
|
|
return $out;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function getRowSqlObject($pdo,$sql,$params) {
|
|
|
|
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
|
|
|
|
if (is_null($params)) {
|
|
|
|
$stmt->execute();
|
|
|
|
} else {
|
|
|
|
$stmt->execute($params);
|
|
|
|
}
|
|
|
|
return ($stmt->fetchObject());
|
|
|
|
}
|
|
|
|
public static function fetchSqlAll($pdo,$sql,$params) {
|
|
|
|
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
|
|
|
|
if (is_null($params)) {
|
|
|
|
$stmt->execute();
|
|
|
|
} else {
|
|
|
|
$stmt->execute($params);
|
|
|
|
}
|
|
|
|
return ($stmt->fetchAll(PDO::FETCH_ASSOC));
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function execSql($pdo,$sql,$params) {
|
|
|
|
$stmt = $pdo->prepare(DbUtils::substTableAlias($sql));
|
|
|
|
if (is_null($params)) {
|
|
|
|
$stmt->execute();
|
|
|
|
} else {
|
|
|
|
$stmt->execute($params);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-11-19 23:10:21 +01:00
|
|
|
|
|
|
|
public static function getConfigItem($pdo,$item,$default) {
|
|
|
|
$sql = "SELECT value FROM %ossystem% WHERE item=?";
|
|
|
|
$result = self::fetchSqlAll($pdo, $sql, array($item));
|
|
|
|
if (count($result) == 0) {
|
|
|
|
return $default;
|
|
|
|
} else {
|
|
|
|
return $result[0]["value"];
|
|
|
|
}
|
|
|
|
}
|
2020-11-19 23:10:06 +01:00
|
|
|
}
|