<?php
class mysql
{
var $record,$debug,$numrows,$insert_id,$info;
var $DB_NAME = "fsbiggsa_freesite";
var $DB_USER = "fsbiggsa_m2";
var $DB_PASS = "en-MH1982";
var $HOST = "localhost";
var $error_title = "ERROR!";
var $perfix = "fs_";
//throw out the error;
function error($msg)
{
if(strstr($msg, "|"))
{
$msg = str_replace("[/font]","</font></b>", $msg);
$msg = str_replace("|","", $msg);
}
else
{
$msg = str_replace("[/font]","</font></b>", $msg);
}
$msg = str_replace("[", "<b><font color=\"", $msg);
$msg = str_replace("]", "\">", $msg); 
$msg = '<h3>'.ucwords($this->error_title).'</h3>'.$msg;
return $msg;
}
//content to database
function connect()
{
@mysql_connect($this->HOST, $this->DB_USER, $this->DB_PASS)or die("This site is experiencing an extremely large volume of traffic at the moment, and as a result, you're unable to access this site temporarily. Please try again later.");
@mysql_select_db($this->DB_NAME);
}

//mysql fields in sql format
function format_fields($fields)
{
$explode = explode(",", $fields);
for($x = 0; $x<=count($explode); $x++)
{
if(!empty($explode[$x]))
{
$explode[$x] = trim($explode[$x]);
if($x < 1)
{
$formated = "$explode[$x]";
}
else
{
$formated .= ", $explode[$x]";
}
}
}
return $formated;
}
//
function do_query($query)
{
global $queries_done;
if($this->debug)
{
echo "<pre><font color='red'>$query</font></pre>";
}
$result = mysql_query($query);
$queries_done++;
return $result;
}
//
function query($fields, $table, $where)
{
$fields = $this->format_fields($fields);
$query = "SELECT $fields FROM $table WHERE $where";
if($this->numrows)
{
$t = eregi_replace(' LIMIT [0-9]*, [0-9]*|limit [0-9]*,[0-9]*','',$query);
$this->numrows = $this->num_rows($this->do_query($t));
}
$query = $this->do_query($query)or die($this->error("[red]Invild Query![/font][blue]$query [/font]".mysql_error()));
return $query;
}
//
function get_array($query_id)
{
$this->record = $this->fix(mysql_fetch_array($query_id));
return $this->record;
}
//
function num_rows($query_id)
{
$num_rows = mysql_num_rows($query_id);
return $num_rows;
}
////////////
function nextpage($start,$perpage)
{
$numrows = (int)$this->numrows;
$page = $this->current_page();
if($start > 0)
{
$li = "<a href=\"".$page."&start=".($start - $perpage)."\">< Last</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}
$pages = ceil($numrows / $perpage) + 1;
$current_page = ceil($start / $perpage) + 1;
$stfrom = (($current_page - 10) < 0) ? 1 : ($current_page - 10);
$end = (($current_page + 10) <= $pages) ? ($current_page + 10) : $pages;
$x = 1;
//
for($x = $stfrom; $x < $end; $x++)
{
$s = $perpage * ($x - 1);
if($x > 0)
{
$li .= ($x == $current_page) ? '<span class="pagenum">'.$x.'</span>&nbsp;&nbsp;' : "<a href=\"$page&start=$s\">$x</a>&nbsp;&nbsp;";
}
}
if($numrows > ($start + $perpage))
{
$li .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=\"".$page."&start=".($start + $perpage)."\">Next ></a>";
}
//
return $li;
}
//////////
function insert($table, $fields, $values) 
{
$into = explode(",", $fields); 
$value = explode(",", $values); 
if(sizeof($value) != sizeof($into)) 
{
echo "<pre>";
print_r($into);
print_r($value);
echo $this->info;
echo "</pre>";
die($this->error("[red]Insert Fields Count Mismatch![/font]<br />Unable to insert record."));
} 
for($x = 0; $x<count($value); $x++)
{ 
$value[$x] = trim($value[$x]); 
$into[$x] = trim($into[$x]); 
if($x == 0) 
{ 
$fields = "`$into[$x]`"; 
$gen_query = "'$value[$x]'"; 
}
else 
{ 
$fields .= ", `$into[$x]`"; 
$gen_query .= ", '$value[$x]'"; 
} 
} 
$deb = "<pre>INSERT INTO `$table` ($fields) VALUES ($gen_query)</pre>";
if($this->debug)
{
echo $deb;
}
$query = $this->do_query("INSERT INTO `$table` ($fields) VALUES ($gen_query)")or die($this->error($deb."[red]Invild Query![/font]Unable to insert record.<br />".mysql_error()));
$this->insert_id = mysql_insert_id();
}
//
function Delete($table, $where)
{
$query = $this->do_query("DELETE FROM `$table` WHERE $where")or die($this->error("[red]Invild Query![/font]Unable to delete record.<br />[blue]DELETE FROM `$table` WHERE $where [/font]".mysql_error()));
}
//
function update($toupdate, $value, $table, $where)
{
$toupdate = explode(",", $toupdate);
$value = explode(",", $value);
if(count($value) != count($toupdate))
{
die($this->error("[red]Field count mismatch[/font]<br />Unable to update record."));
}
$gen_query = "";
for($x = 0; $x<=count($value); $x++)
{
if(!empty($toupdate[$x]))
{
if($x == 0)
{
$gen_query .= "`$toupdate[$x]` = '$value[$x]'";
}
else
{
$gen_query .= ", `$toupdate[$x]` = '$value[$x]'";
}
}
}
$update = $this->do_query("UPDATE `$table` SET $gen_query WHERE $where")or die($this->error("[red]Invild Query![/font]Unable to update record.<br />[blue]UPDATE `$table` SET $gen_query WHERE $where [/font]".mysql_error()));
}
//
function current_page()
{
$url = parse_url($_SERVER['REQUEST_URI']);
$page = $url['path'];
if(!empty($url['query']))
{
$page .= "?".eregi_replace('&start=[0-9]*|\?start=[0-9]*', '', $url['query']);
}
else
{
$page .= "?";
}
return $page;
}
//
function fix($array)
{
$find = array('&#8218;','&#8218','&','&nbsp;','"');
$replace = array(',',',','&',' ','"');
if(is_array($array))
{
foreach($array as $key => $value)
{
$array[$key] = str_replace($find, $replace, stripslashes($value));
}
}
return $array;
}
//
}
$mysql = new mysql();
$mysql->connect();
?>