<?php
    /*
      ** Monster Top List 1.4
      ** Supplied By: lord
      ** Nullification By: Zygote
      ** */
class DB
{    var $query_count = 0;
  var $db_count = 0;
  function connect($host,$user,$pass,$db,$pfx,$con_name,$def=  0)
  {
    if(!$con = mysql_connect($host,$user,$pass))
    {    $this->error(0, 'Attempting to connect to mySQL',$con_name);    }
    if(!mysql_select_db($db, $con))
    {    $this->error(0, 'Attempting to Select Database',$con_name);    }
    if($def == 1)
    {    $this->defaultcon = $con;    }
    $this->pfx[$con] = $pfx;
    $this->$con = $con;
    return $con;
  }
  function query($query, $con='', $no_error=0)
  {
    if($con == '')
    {    $con = $this->defaultcon;
    }
    $pfx = $this->pfx[$con];
    if($pfx != "mtl_")
    {    $query = preg_replace("/mtl_(\S+?)([\s\.,]|$)/", $pfx."\\1\\2", $query);
    }
    $this->query_count++;
    $t = (float) array_sum(explode(' ', microtime()));
    $this->query_id = mysql_query($query, $con);
    $t = $t - (float) array_sum(explode(' ', microtime()));
    $this->query_data[] = $query . ' [ Time: ' . $t . ' sec]';
    //echo "<p><pre>" . htmlentities($query) . "</pre></p>";
    if(!$this->query_id AND $no_error == 0)
    {    $this->error(1, $query);    }
    return $this->query_id;
  }
  function fetch_row($rid='a')
  {    if($rid == "" OR $rid == 'a')
    {    $rid = $this->query_id;     }
    return mysql_fetch_array($rid);
  }
  function row_query($query, $con = '', $no_error = 0)
  {
    $oldqid = $this->query_id;
    $this->query($query, $con, $no_error);
    $row = $this->fetch_row();
    $this->query_id = $oldqid;
    return $row;
  }
  function col_query($query, $col = 0, $con='', $no_error = 0)
  {
    $oldqid = $this->query_id;
    $this->query($query, $con, $no_error);
    $col = $this->fetch_col($col);
    $this->query_id = $oldqid;
    return $col;
  }
  function fetch_col($col = 0, $rid='a')
  {
    $a = array();
    while($r = $this->fetch_row($rid))
    {
      $a[] = $r[$col];
    }
    return $a;
  }
  function fetch_one($col = 0, $rid='a')
  {
    if($this->count())
    {
      $r = $this->fetch_row($rid);
      return $r[$col];
    }
    return NULL;
  }
  function one_query($query, $col = 0, $con='', $no_error = 0)
  {
    $oldqid = $this->query_id;
    $this->query($query, $con, $no_error);
    $fld = $this->fetch_one($col);
    $this->query_id = $oldqid;
    return $fld;
  }
  function count($rid="")
  {    if($rid == "")
    {    $rid = $this->query_id;     }
    return mysql_num_rows($rid);
  }
  function insert_id()
  {    return mysql_insert_id();
  }
  function disconnect($con='1')
  {    if($con == '1')
    {    $con = $this->defaultcon;
    }
    mysql_close($con);
  }
  function insert($data)
  {    foreach($data as $n => $v)
    {
      $columns[] = $n;
      $rows[] = "'" . addslashes($v) . "'";
    }
    return array (
            'columns' => implode(",", $columns),
            'values' => implode(",", $rows),
    );
  }
  function update($data)
  {
    foreach($data as $n => $v)
    {    $output[] = "$n='".addslashes($v)."'";    }
    return implode(",", $output);
  }
  function error($error=1, $q, $con="")
  {    if($error == 1)
    {    $error = mysql_error();        }
    if($con == "" OR is_numeric($con))
    {    $con = $this->default;
    }
    if($this->query == "")
    {    $this->query = "N/A";    }
    $time = date('l dS F Y, g:iA', time());
print <<<data
<html>
<head>
<title>Monster Top List Fatal Error</title>
</head>
<body>
<font size='4'><b>Fatal MySQL Error in Monster Top List 1.4</b></font><br>
A fatal MySQL Error has occured. Please contact the list owner with the information in the text box below.
<br><br>
<textarea cols='80' rows='10' noscrolling>MySQL Error: {$error}
Query: {$q}
Connection: {$con}
Time: {$time}
</textarea>
</body>
</html>
data;
exit;
  }
  function escape($string)
  {
    return mysql_escape_string($string);
  }
}
?>