Here, i'm just going to post the whole freakin thing:
I've got an index page. EVERYTHING in the WHOLE site come through the index page.
The index page includes the MySql class, so, it's already available for any other scripts included in the page later.
I have a script that is supposed to insert a record into the database, but i purposely name one of the fields wrong, so that i can test my Bug Class. I will include all the code in a second.
If the query returns FALSE then the Bug Class is called. The Bug class's constructor accepts one argument -- the error details. It has NO OTHER methods. It takes the details, along with some server variables, and inserts them into my Bugs table.
The Bugs class Extends MySql -- which is already included via the index page.
The problem is, i am NOT able to catch the mysql_error and pass it along to the Bug class. BUT, it the MySql class, when calling a query, i can say "or die(mysql_error)", and it will give me the error just fine. This is crap... Here's the codes:
Insert statement:
$r = $db->Q("insert into WretchedComments (uid,fromid,ctime,message,subject,label,mode)values('".$f->DbSafe($_POST['name'])."','{$_COOKIE['uid']}','".date("Y-m-d H:i:s")."','".$f->DbSafe($_POST['comment'])."','".$f->DbSafe($_POST['subject'])."','unread','$t1')");
if ($r != true){
$b = new Bug("Could not insert new comment: ". mysql_error());
}
And here's the mysql function for queries:
function Q($sql){
$query = mysql_query($sql);// or die(mysql_error());
return $query;
}
and here's the bug class:
<?php
class Bug extends MySql{
private $host;
private $uri;
private $uid;
private $desc;
private $ctime;
function __construct($description){
$this->host= $_SERVER['HTTP_HOST'];
$this->uri = $_SERVER['REQUEST_URI'];
if (isset($_COOKIE['uid'])){
$this->uid = stripslashes(str_replace("'","''",$_COOKIE['uid']));
}else{
$this->uid = "Guest, or Not Logged In";
}
$this->desc= $description;
$this->ctime=date("Y-m-d H:i:s");
parent::__construct();
parent::O();
parent::Q("insert into BugReports (host,uri,uid,ctime,description)values('{$this->host}','{$this->uri}','{$this->uid}','{$this->ctime}','{$this->desc}')");
parent::C();
echo "<h1>There was a bug, but it was caught and reported. You may be contacted with more questions about this bug at a later time.</h1>";
}
function R(){
}
}
?>
Now, when there IS an ERROR, the bug class will output it's error message, but it won't catch the error from the previous mysql statement, and insert it into the db. One of the ways i was tryig this, it would insert the bug report, but without the mysql_error. Now, i've messed with it so much, it's not even doing that.