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); $out = str_replace("%images%", TAB_PREFIX . 'images',$out); 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); } } 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"]; } } }