Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- class dbase {
- private static $conn = NULL;
- private static $result = NULL;
- private static $counter = NULL;
- /**
- * connect to database and selct db
- * @param string $host
- * @param string $database
- * @param string $user
- * @param string $pass
- */
- #public static function connect($host=NULL, $database=NULL, $user=NULL, $pass=NULL) {
- public static function connect() {
- self::$conn = mysql_connect(DB_HOST, DB_USER, DB_PASSWD, TRUE) or
- die(self::Error("MySQL_Connect",
- "Kann keine Verbindung zur MySQL Datenbank herstellen!",
- mysql_error(),
- mysql_errno()));
- mysql_select_db(DB_DBASE, self::$conn) or
- die(self::Error("MySQL_Select_DB",
- "Kann die Datenbank nicht aufrufen!",
- mysql_error(),
- mysql_errno()));
- }
- /**
- * connection close
- */
- public static function close() {
- if (is_resource(self::$conn))
- mysql_close(self::$conn) or
- die(self::error("MySQL_Close",
- "Datenbankverbindung konnte nicht geschlossen werden!",
- mysql_error(),
- mysql_errno()));
- }
- /**
- * run mysql_query
- * @param string $query
- * @return string $result
- */
- public static function query($query) {
- if(!self::$conn) self::connect();
- self::$result = mysql_query($query, self::$conn) or
- die(self::error("MySQL_Query",
- $query,
- mysql_error(),
- mysql_errno()));
- self::$counter = NULL;
- return self::$result;
- }
- /**
- * fetch a array
- * @param string $query
- * @return string
- */
- public static function fetch_array($query) {
- $sql = @mysql_fetch_array($query);
- return $sql;
- }
- /**
- * fetch a array includes mysql_query
- * @param string $query
- * @return string
- */
- public static function fetchArray($query) {
- $result = self::query($query);
- $sql = @mysql_fetch_array($result);
- return $sql;
- }
- /**
- * give num of rows
- * @param string $query
- * @return string
- */
- public static function num_rows($query) {
- $sql = @mysql_num_rows($query);
- return $sql;
- }
- /**
- * get the last id
- * @return int
- */
- public static function last_id() {
- if(!self::$conn) self::connect();
- $sql = @mysql_insert_id(self::$conn);
- return $sql;
- }
- /**
- * escaoe the query string
- * @param string $query
- * @return string
- */
- public static function escape_string($query) {
- return mysql_real_escape_string($query);
- }
- /**
- * count the querys
- * @return int
- */
- public static function count() {
- if (self::$counter == NULL && is_resource(self::$result)) {
- self::$counter = mysql_num_rows(self::$result);
- }
- return self::$counter;
- }
- /**
- * show errors in connection
- * @param string $Abfrage
- * @param string $Query
- * @param string $MySQL_Error
- * @param string $MySQL_Errno
- */
- private static function error($Abfrage, $Query, $MySQL_Error, $MySQL_Errno) {
- echo "<br \>";
- echo "<title>Datenbank Error</title>";
- echo "<div style='width:500px; border:1px solid #800000; position:relative; top:125px; left:75px; background-color:#c3c3c3;'>";
- echo "Zur Zeit gibt es Probleme mit der Datenbank.<br> Bitte versuchen sie es später noch einmal.<br><br>";
- echo "<hr align='center' size='1' width='95%' color='#800000' />";
- echo sprintf("Fehler bei der Abfrage : %s <br \>", htmlspecialchars($Abfrage));
- echo sprintf("Query : %s <br \>", htmlspecialchars($Query));
- echo sprintf("Fehlermeldung : %s <br \>", htmlspecialchars($MySQL_Error));
- echo sprintf("Fehlerzahl : %s <br \>", htmlspecialchars($MySQL_Errno)); #
- echo "</div>";
- exit;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement