debug = $debug; } function gethost() { return $this->dbhost; } function sethost($req_host) { $this->dbhost = $req_host; } function getdb() { return $this->db; } function setdb($req_db) { $this->db = $req_db; } function getdbuser() { return $this->dbuser; } function setdbuser($req_user) { $this->dbuser = $req_user; } function getdbpassword() { return $this->dbpassword; } function setdbpassword($req_password) { $this->dbpassword = $req_password; } function getsql() { return $this->sql; } function setsql($req_sql) { $this->sql = $req_sql; $this->result = array(); // Added by Larry 20060715 } function getnumberrows() { return $this->numberrows; } function setnumberrows($req_numberresults) { $this->numberesults = $req_numberresults; } function setdbconnection($req_dbconnection) { $this->dbconnection = $req_connection; } function getdbconnection() { return $this->dbconnection; } /* This is the constructor for the object. In this case I have set the initial values of a number of the object properties to those values declared in the global constants.inc. By doing this, I only need to change the values of these properties for specific operations, which we will not need to do throughout this example */ function mysqldb() { global $HOST, $DB, $WEBUSER, $WEBPASSWORD; global $TRUE, $FALSE; $this->sethost($HOST); $this->setdb($DB); $this->setdbuser($WEBUSER); $this->setdbpassword($WEBPASSWORD); $this->setdbconnection($FALSE); //$this->resulttype = "array"; } /* These are the methods for the object. They provide for opening a connection to the database, closing a connection and executing a SELECT query. Of course, these can be expanded upon to allow for INSERT's, UPDATE's and DELETE's etc... */ function opendbconnection() { global $TRUE, $FALSE; $this->dbconnection = mysql_connect("$this->dbhost", "$this->dbuser", "$this->dbpassword"); if ($this->dbconnection != 0) { $this->db = mysql_select_db("$this->db"); $this->setdbconnection($TRUE); } else { $this->setdbconnection($FALSE); return false; } return true; } function closedbconnection() { if ($this->dbconnection = $TRUE) { mysql_close($this->dbconnection); } } function setfetchtype($type) { $this->fetchtype = $type; } function setresulttype($type) { $this->resulttype = $type; } function selectquery() { global $TRUE, $FALSE; if ($this->fetchtype == "") { $this->setfetchtype(MYSQL_BOTH); } if ($this->dbconnection == $FALSE) { $this->opendbconnection(); } unset($this->qry); $this->qry = mysql_query($this->sql); $this->trace(); if (!$this->qry) { return(false); } else { $this->numberrows = @mysql_num_rows($this->qry); if ($this->numberrows > 0 and $this->resulttype != "row") { for($x = 0; $x < $this->numberrows; $x++) { $this->result[$x] = mysql_fetch_array($this->qry,$this->fetchtype); } } return(true); } } function getnextrow() { $this->result[0] = mysql_fetch_array($this->qry,$this->fetchtype); } function insertquery() { global $TRUE, $FALSE; if ($this->dbconnection == $FALSE) { $this->opendbconnection(); } unset($this->qry); $this->qry = mysql_query($this->sql); $this->trace(); if (!$this->qry) { return(false); } else { return true; } } function updatequery() { global $TRUE, $FALSE; if ($this->dbconnection == $FALSE) { $this->opendbconnection(); } unset($this->qry); $this->qry = mysql_query($this->sql); $this->trace(); if (!$this->qry) { return(false); } else { return true; } } function deletequery() { global $TRUE, $FALSE; if ($this->dbconnection == $FALSE) { $this->opendbconnection(); } unset($this->qry); $this->qry = mysql_query($this->sql); $this->trace(); if (!$this->qry) { return(false); } else { return true; } } function checkquery() { global $TRUE, $FALSE; if ($this->dbconnection == $FALSE) { $this->opendbconnection(); } unset($this->qry); $this->qry = mysql_query($this->sql); $this->trace(); if (!$this->qry) { return(false); } else { return true; } } // Added by Larry function getinsertid() { return (mysql_insert_id()); } function trace() { global $HTTP_ENV_VARS; if ($this->debug > 0 and !$this->qry) { echo "
MySQL Error = " . mysql_error() . "
"; echo "SQL=" . $this->sql . "
"; echo "Script="; echo $HTTP_SERVER_VARS["SCRIPT_FILENAME"]; echo "
Req ID=$this->query_nbr"; echo "

"; } } function set_query_nbr($nbr) { $this->query_nbr = $nbr; } function set_diag_level($diag) { $this->debug = $diag; } }