00001 <?php
00003
00008
00009
00014 class DB
00015 {
00016 private $con = null;
00018
00022 public $host = "localhost";
00024 public $username = null;
00026 public $password = null;
00028 public $dbname = null;
00030
00039 function manualConnect($dbname, $username, $password, $host = "localhost")
00040 {
00041
00042 $this->con = mysql_connect($host, $username, $password);
00043 if (!$this->con)
00044 {
00045 die('Could not connect: ' . mysql_error());
00046 }
00047
00048 mysql_select_db($dbname, $this->con);
00049
00050 }
00052
00055 function connect()
00056 {
00057
00058 $this->con = mysql_connect($this->host, $this->username, $this->password);
00059 if (!$this->con)
00060 {
00061 die('Could not connect: ' . mysql_error());
00062 }
00063
00064 mysql_select_db($this->dbname, $this->con);
00065
00066 }
00068
00071 function activeConnect()
00072 {
00073
00074 $this->con = mysql_pconnect($this->host, $this->username, $this->password);
00075 if (!$this->con)
00076 {
00077 die('Could not connect: ' . mysql_error());
00078 }
00079
00080 mysql_select_db($this->dbname, $this->con);
00081
00082 }
00084 function switchUser($username, $password)
00085 {
00086 $this->disconnect();
00087 $this->manualConnect($this->dbname, $username, $password);
00088
00089 }
00091
00094 function query($query)
00095 {
00096 return mysql_query($query, $this->con);
00097 }
00099
00102 function cleanString($str, $clean_html = false)
00103 {
00104 if ($clean_html == false)
00105 {
00106 return mysql_real_escape_string($str);
00107 }
00108 else
00109 {
00110 return mysql_real_escape_string(htmlentities($str));
00111 }
00112 }
00114 function cleanInt($int)
00115 {
00116 return $int + 0;
00117 }
00119 function disconnect()
00120 {
00121 mysql_close($this->con);
00122 }
00123 }
00124 ?>