<?
/********************************************************************************\
* Copyright (C) Joe Stump <joestump98@yahoo.com>, *
* Emir Musabasic <emusabasic@softhome.net> *
* *
* This program is free software; you can redistribute it and/or *
# modify it under the terms of the GNU General Public License *
# as published by the Free Software Foundation; either version 2 *
# of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
\********************************************************************************/
// Created By: Joe Stump
// Created On: 2000-11-13
// History:
// 2000-11-13 : Created
//
// This is a homebrew abstraction layer that I created - it's heavily based on
// a tutorial I found at the following URL:
// http://www.phpbuilder.com/columns/mark20000727.php3
// I made some changes to a few of the functions and added a the update function
// it all works well IMO.
class DB{
var $host;
var $username;
var $password;
var $db;
var $sql;
var $rows;
var $num_rows;
var $affected_rows;
var $insert_id;
var $result;
var $db_status = 0;
var $db_link = 0;
function return_host(){
return $this->host;
}
function set_host($new_host){
$this->host = $new_host;
}
function return_db(){
return $this->db;
}
function set_db($new_db){
$this->db = $new_db;
}
function return_user(){
return $this->username;
}
function set_user($new_user){
$this->username = $new_user;
}
function return_password(){
return $this->password;
}
function set_password($new_password){
$this->password = $new_password;
}
function return_sql(){
return $this->sql;
}
function set_sql($new_sql){
$this->sql = $new_sql;
}
function set_num_rows($new_num_rows){
$this->num_rows = $new_num_rows;
}
function return_num_rows(){
return $this->num_rows;
}
function set_affected_rows($new_affected_rows){
$this->affected_rows = $new_affected_rows;
}
function return_affected_rows(){
return $this->affected_rows;
}
function return_db_status(){
return $this->db_status;
}
function set_db_status($new_status){
$this->db_status = $new_status;
}
function set_insert_id($new_insert_id){
$this->insert_id = $new_insert_id;
}
function return_insert_id(){
return $this->insert_id;
}
function DB(){
global $HOST, $DB, $USERNAME, $PASSWORD, $TRUE, $FALSE;
$this->set_host($HOST);
$this->set_db($DB);
$this->set_user($USERNAME);
$this->set_password($PASSWORD);
$this->set_db_status($FALSE);
}
function open_connection(){
global $TRUE, $FALSE, $NOTIFY;
$this->db_link = @mysql_connect($this->host,$this->username,$this->password);
if($this->db_link){
$this->db = @mysql_select_db("$this->db");
if(!$this->db){
$this->set_db_status($FALSE);
return $FALSE;
if($NOTIFY){
$msg = 'There was a problem selecting your DB on the MySQL server!'."\n";
$msg .= 'Host: '.$this->host."\n";
$msg .= 'Database: '.$this->db."\n";
$msg .= 'Username: '.$this->username."\n";
$msg .= 'Password: '.$this->password."\n";
mail($ADMIN_EMAIL,"MYSQL ERROR @ ".$HOST,$msg,'From: Error Bot <bounce@bounce.com>');
}
}else{
$this->set_db_status($TRUE);
return $TRUE;
}
}else{
$this->set_db_status($FALSE);
return $FALSE;
if($NOTIFY){
$msg = 'There was a problem connecting to the MySQL server!'."\n";
$msg .= 'Host: '.$this->host."\n";
$msg .= 'Username: '.$this->username."\n";
$msg .= 'Password: '.$this->password."\n";
mail($ADMIN_EMAIL,"MYSQL ERROR @ ".$HOST,$msg,'From: Error Bot <bounce@bounce.com>');
}
}
}
function close_connection(){
if($this->db_status){
mysql_close($this->db_status);
}
}
function select_query(){
global $TRUE, $FALSE;
if($this->db_status == $FALSE){
$this->open_connection();
}
$this->result = @mysql_query($this->sql);
if(!$this->result){
return $FALSE;
}else{
$this->set_num_rows(@mysql_num_rows($this->result));
if($this->return_num_rows()){
while($row = mysql_fetch_array($this->result)){
$this->rows[] = stripslashes_array($row);
}
@mysql_free_result($this->result);
return $TRUE;
}else{
return $FALSE;
}
}
}
function alter_query(){
global $TRUE, $FALSE;
if($this->db_status == $FALSE){
$this->open_connection();
}
$this->result = @mysql_query($this->sql);
if(!$this->result){
return $FALSE;
}else{
$this->set_affected_rows(@mysql_affected_rows($this->result));
$this->insert_id = @mysql_insert_id();
if($this->return_affected_rows()){
// @mysql_free_result($this->result);
return $TRUE;
}else{
return $FALSE;
}
}
}
}
?>
|