day = date("Y:m:d"); $this->time = date("H:i:s"); $this->date = $day."::".$time; $this->system = $sys; $this->webmaster = "webmaster@-------.com"; } // END Constructor /*********************************************************************** ***** ERROR HANDLING FUNCTIONS ***************************************** ***********************************************************************/ /*********************************************************************** $this->err($msg) input: error message output: email to the webmaster write to log */ public function err($msg) { $to = $this->webmaster; // assign To: $subj = "[".$this->group."] Error"; // assign Subject: $msg .= "\n".$this->date; // assign Message: $from = "From: ".$this->webmaster; // assign From: mail($to,$subj,$msg,$from); // send mail $this->write_log("Error",$msg); // log error } // END $this->err() /*********************************************************************** ***** MYSQL FUNCTIONS ************************************************** ***********************************************************************/ /*********************************************************************** DB_connect() input: none output: link resource */ public function db_connect() { /* Squeeze of Lime server info*/ $server = "----------"; $usr = '----------'; $pswd = '----------'; $db = '----------'; // opening db connection $link = mysql_connect($server,$usr,$pswd); // OPEN mysql connection if(!$link) { // IF no connection $this->err("db_connect(): Unable to connect to db."); // --REPORT error return false; // --RETURN false } else { } // ELSE continue $dbselect = mysql_select_db($db, $link); // SELECT database if(!$dbselect) { // IF no selection $this->err("db_connect(): Unable to select db."); // --REPORT error return false; // --RETURN false } else { } // ELSE continue return $link; // RETURN link resource } // END db_connect() /*********************************************************************** insert input: mysql query string (insert, delete, or update) output: query result (false on fail, true on success) */ public function insert($query) { return $this->result($query,1,0); // CALL result function } /*********************************************************************** select input: mysql query string (select) output: query result (false on fail, single result on success) */ public function select($query) { return $this->result($query,0,0); // CALL result function } // END select /*********************************************************************** select_simple_list input: mysql query string (select) output: query result (false on fail, array of single field on success) */ public function select_simple_list($query) { return $this->result($query,0,1); // CALL result function } // END select_simple_list /*********************************************************************** result input: mysql query string, boolean, boolean output: */ public function result($query,$insert,$list) { $count = 0; // RESET count $link = $this->db_connect(); // GET a database link $data; // INITIALIZE variable if(!$link) { // IF we still don't connect $msg = "Function: check_result\n". // --CREATE error message "Problem: ".mysql_error()."\n". "Date: ".$this->date."\n"; $this->err($msg); // --REPORT error $this->logout(); // --LOGOUT return false; } // --RETURN FALSE $count = 0; // RESET count $result = mysql_query($query,$link); // QUERY database if(!$result) { // IF no result, $msg = "Function: check_result\n". // --CREATE error message "Problem: ".mysql_error()."\n". "Date: ".$this->date."\n". "Query: $query"; $this->err($msg); // --REPORT error $this->logout(); // --LOGOUT return false; } // --RETURN FALSE if($insert) { // IF an insert type query if(mysql_affected_rows() == 0) { // --CHECK for affected rows return false; } // --NONE? return false $data = true; // --OTHERWISE return true } else { // ELSE a select type query if(mysql_num_rows($result) == 0) { // --CHECK for number of rows return false; } // --NONE? return false else if($list) { // --ELSE IF we want a list while($row = mysql_fetch_row($result)) { // --LOOP through the rows returned $data[] = $row[0]; } // --SAVE first value in array } else { // --ELSE we want a single value $data = mysql_fetch_assoc($result); // --SAVE the query result } mysql_free_result($result); // FREE the result } mysql_close($link); // CLOSE database link return $data; // RETURN our query data (if good result) } /*********************************************************************** ***** SAFE FUNCTIONS *************************************************** ***********************************************************************/ /*********************************************************************** Mysql_safe($val) input: a string output: a safe, mysql 'executable' version of the string, in quotes note: (adapted from php.net) */ public function mysql_safe($value) { $link = $this->db_connect(); // GET a database link if (get_magic_quotes_gpc()) { $value = stripslashes($value); } // IF gmqg is turned on, USE it if (!is_numeric($value)) { // IF its not a number $value = "\"" . mysql_real_escape_string($value,$link) . "\""; } // --ESCAPE and put in quotes return $value; // --RETURN our safe string } // END mysql_safe /*********************************************************************** Mysql_safe_nq($val) input: a string output: a safe, mysql 'executable' version of the string, W/O quotes note: (adapted from php.net) */ public function mysql_safe_nq($value) { $link = $this->db_connect(); // GET a database link if (get_magic_quotes_gpc()) { $value = stripslashes($value); } // IF gmqg is turned on, USE it if (!is_numeric($value)) { // IF its not a number $value = mysql_real_escape_string($value,$link); } // --ESCAPE the string return $value; // --RETURN our safe string } // END mysql_safe } // END CLASS ?>