Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Set CONSTANTS for Query result variable type
- define("GET_OBJECT", 1);
- define("GET_ARRAY", 2);
- define("GET_ASSOC", 3);
- class db {
- var $CFG;
- var $Connection;
- var $Result;
- var $Result2;
- var $DevMode;
- var $Rows;
- var $ErrorEmail;
- var $db;
- var $FH;
- function db() {
- $this->ErrorEmail = "cbake6807@comcast.net";
- $this->Connect();
- return $this->Connection;
- }
- function getDate($format = "Ymd h:m:s"){
- $date = date($format, time());
- return $date;
- }
- function logError($error){
- $this->FH = fopen("./errorlogs/MySQLErrors_".$this->getDate("Ymd").".log", "a");
- $file = fwrite($this->FH, $this->getDate("Y-m-d h:m:s A")." - ERROR: ".$error."\n\r");
- fclose($this->FH);
- }
- function Connect($db = '') {
- global $CFG;
- $CFG->DBNAME = "seminar";
- $CFG->DBUSER = "script";
- $CFG->DBPASS = "3y34ml33t";
- $CFG->DBHOST = "173.203.127.28";
- $Host = $CFG->DBHOST;
- $User = $CFG->DBUSER;
- $Password = $CFG->DBPASS;
- $dbname = empty($db) ? $CFG->DBNAME : $db;
- $this->Connection = mysql_connect($Host, $User, $Password);
- if(!$this->Connection) {
- echo "We're sorry. The Database appears to be temporarily offline. Please check back soon!";
- exit;
- }else{ $this->db = mysql_select_db($CFG->DBNAME); }
- }
- // Return last inserted row ID
- function get_insert_id(){
- return mysql_insert_id($this->Connection);
- }
- // Close the current database connection
- function Close() {
- mysql_close($this->Connection);
- }
- // Process query and return resultset as a class object
- function Execute($SQL) {
- $this->Result = mysql_query($SQL, $this->Connection) or $this->DBDie($SQL);
- return $this->Result;
- }
- // Process and Return the resultset directly to a variable
- function ExecuteAndReturn($SQL) {
- $Query = mysql_query($SQL, $this->Connection) or $this->DBDie($SQL);
- $this->Result = mysql_fetch_object($Query);
- return $this->Result;
- }
- // Retrieve the current resultset row
- function GetRow($Type = GET_OBJECT) {
- if ($Type == GET_OBJECT) {
- return mysql_fetch_object($this->Result);
- } elseif ($Type == GET_ARRAY) {
- return mysql_fetch_array($this->Result);
- } elseif ($Type == GET_ASSOC) {
- return mysql_fetch_assoc($this->Result);
- } else {
- }
- }
- // Return total resultset rows returned
- function NumRows(){
- return mysql_num_rows($this->Result);
- }
- // Notify's admin via email for every DB error and provides information for debugging
- // Active mailserver required for php's mail() function
- function DBDie($SQL = "") {
- global $_SERVER;
- echo $SQL . "<br /><br />";
- echo mysql_errno() . ":" . mysql_error() . "<br /><br /><br />";
- echo "We are sorry for the inconvenience, but there was a problem processing your request.<br />The Webmaster has been notified and this error will be corrected immediately. Please check back soon!<br><br>";
- }
- } // end db Class
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement