Sure, some code ... here you go.
This is going to be messy, no tab's and all:
// file mysql_class.php3
<?
class MySQL {
// Variables
var $mysql_host;
var $mysql_database;
var $mysql_user;
var $mysql_pass;
var $mysql_link;
var $result;
var $result_count;
// MySQL Functions:
// MySQL ();
// SetHost ();
// Connect ();
// Disconnect ();
// Query ();
// Row_Count ();
// Row_Affected ();
// Row_Inserted ();
// Row ();
// Destroy_Query ();
function MySQL ($dbHost = "") {
// Set the Host
$this->SetHost ($dbHost);
$this->result_count = 0;
$this->mysql_link = 0;
} // End of Constructor
function SetHost ($dbHost) {
$this->mysql_host = $dbHost;
} // End of SetHost ()
function Connect ($dbName, $dbUserID, $dbPassWord, $persistant = false) {
$this->mysql_database = $dbName;
$this->mysql_user = $dbUserID;
$this->mysql_pass = $dbPassWord;
if ($persistant == false) {
if (!($this->mysql_link = mysql_connect ($this->mysql_host, $this->mysql_user, $this->mysql_pass))) {
return -1;
} else {
if (!mysql_select_db ($this->mysql_database, $this->mysql_link)) {
return mysql_errno();
}
}
} else {
if (!($this->mysql_link = mysql_pconnect ($this->mysql_host, $this->mysql_user, $this->mysql_pass))) {
return -1;
} else {
if (!mysql_select_db ($this->mysql_database, $this->mysql_link)) {
return mysql_errno();
}
}
}
} // End of Connect()
function Query ($query) {
// Query the database. If successful, store pointer, and return it
// If failed, return -1
if ($query) {
if (!($this->result[$this->result_count++] = mysql_query ($query, $this->mysql_link))) {
$this->result_count--;
return 0;
} else
return $this->result[$this->result_count - 1];
}
} // End of Query()
function Row_Count ($result = -1) {
if ($result == -1) {
// Latest query
if (($this->result_count - 1) >= 0)
return mysql_num_rows ($this->result[$this->result_count - 1]);
} else {
// Another query
if ($result <= $this->result_count)
return mysql_num_rows ($this->result[$result]);
}
} // End of Row_Count ()
function Row_Affected ($result = -1) {
return mysql_insert_id ($this->mysql_link);
} // End of Affected_Row ()
function Row_Inserted () {
return mysql_insert_id ($this->mysql_link);
} // End of Row_Inserted ()
function Row ($result = -1) {
if ($result == -1) {
// Latest query
if ($row = mysql_fetch_row ($this->result[$this->result_count - 1]))
return $row;
else
return 0;
} else {
// Another query
if ($result <= $this->result_count) {
if ($row = mysql_fetch_row ($this->result[$result]))
return $row;
else
return 0;
}
}
} // End of Row ()
function Row_Array ($result = -1) {
if ($result == -1) {
// Latest query
if ($row = mysql_fetch_array ($this->result[$this->result_count - 1]))
return $row;
else
return 0;
} else {
// Another query
if ($result <= $this->result_count) {
if ($row = mysql_fetch_array ($this->result[$result]))
return $row;
else
return 0;
}
}
} // End of Row ()
function Row_Object ($result = -1) {
if ($result == -1) {
// Latest query
if ($row = mysql_fetch_object ($this->result[$this->result_count - 1]))
return $row;
else
return 0;
} else {
// Another query
if ($result <= $this->result_count) {
if ($row = mysql_fetch_object ($this->result[$result]))
return $row;
else
return 0;
}
}
} // End of Row_Object ()
function Destroy_Query () {
if ($this->result_count >= 0) {
unset ($this->result[$this->result_count]);
$this->result_count--;
if ($this->result_count <= 0)
$this->result_count = 0;
}
} // End of Destroy_Query ()
function Disconnect () {
if ($this->mysql_link)
@mysql_close ($this->mysql_link);
} // End of DisConnect ()
} // End of class MySQL definition
?>
// file database_class.php3
<?
class Database {
//
// Purpose:
// Wrapper for the database being used on the back end
// Version:
// .1
// Known Bugs:
// None.
//
var $sql;
function Database ($host, $db, $user, $pass, $persistant = false) {
$this->sql = new MySQL ($host);
if ($persistant == false)
return ($this->sql->Connect ($db, $user, $pass, false));
else
return ($this->sql->Connect ($db, $user, $pass, true));
} // End of Database ()
function Query ($qry) {
return ($this->sql->Query ($qry));
} // End of Query ()
function Size () {
return ($this->sql->Row_Count ());
} // End of Size ()
function Affected () {
return ($this->sql->Row_Affected ());
} // End of Affected ()
function Inserted () {
return ($this->sql->Row_Inserted ());
} // End of Inserted ()
function Fetch () {
return ($this->sql->Row ());
} // End of Fetch ()
function Fetch_Array () {
return ($this->sql->Row_Array ());
} // End of Fetch ()
function Fetch_Object () {
return ($this->sql->Row_Object ());
} // End of Fetch ()
function Backup () {
return ($this->sql->Destroy_Query ());
} // End of Backup ()
function Disconnect () {
return ($this->sql->Disconnect ());
} // End of Disconnect ()
} // End of Class Database
?>
// A "master" include file
<?
$directory['home'] = "/home/glass/www/advertising/src/";
$directory['class'] = "classes/";
require ($directory['home'] . $directory['class'] . "mysql_class.php3");
require ($directory['home'] . $directory['class'] . "database_class.php3");
?>
// My "concerned" file
<?
//
// Functions for viewing the advertisements
//
require ("../classes/mysql_class.php3");
$dbUserID = "root";
$dbPassword = "";
$dbName = "USGlass";
$dbHost = "localhost";
$Advertising_Image_Table = "Advertisement_Image";
function View_Advertisement ($id) {
global $dbHost, $dbName, $dbUserID, $dbPassword, $Advertising_Image_Table;
$mysql = new MySQL ($dbHost);
$mysql->Connect ($dbName, $dbUserID, $dbPassword);
$query = "SELECT image_type, image_data FROM $Advertising_Image_Table WHERE id=$id";
$mysql->Query ($query);
$row = $mysql->Row_Object ();
Header ("Content-type: $row->image_type");
echo $row->image_data;
}
if ($id >= 0) {
View_Advertisement ($id);
}
?>
<b>If I include the the "master" include file, I get several lines of output (somewhere it's generating a header) -- regardless of whether or not I use the Database class, which I don't want. If I include ONLY the mysql_class.php3 file, it works like a champ.
</b>
Some help is appreciated ... I'm pretty confused.