Alex-Grim Posted January 16, 2008 Share Posted January 16, 2008 Ok, i have a mysql class, and it's worked fine for months now, it's not the problem. I just created a Bug Reporting class, and it works... when implemented correctly. When something doesn't go as planned, i call the bug class. Well, i was trying to include the Mysql Errors in the bug reports, but i'm not able to freakin catch them! If i say mysql_query($blah) or die (mysql_error()); It's fine, it KILLS the script, and give the error. BUT, if i do this: function Q($sql){ $query = mysql_query($sql) or $this->bugout($sql); return $query; } I get NOTHING; I've also tried this: function Q($sql){ $query = mysql_query($sql); if ($query == false){ $B = new Bug("There was an error in a query. Details: " . mysql_error()); }else{ return $query; } } and this (con being the connection object.) function Q($sql){ $query = mysql_query($sql); if ($query == false){ $B = new Bug("There was an error in a query. Details: " . mysql_error($this->con)); }else{ return $query; } } and this function Q($sql){ $query = mysql_query($sql); if ($query == false){ $B = new Bug("There was an error in a query. Details: " . $sql); }else{ return $query; } } And i'm getting NOTHING in return. I get the plain text section of the error, but not the variables or the mysql_error. I could eat glass right now! Thanx Quote Link to comment https://forums.phpfreaks.com/topic/86276-solved-freakin-error-reporting-errors-trying-to-catch-mysql-errors-inside-class/ Share on other sites More sharing options...
rajivgonsalves Posted January 16, 2008 Share Posted January 16, 2008 you bugout function has to return something true or false. does it return using the return statement. Quote Link to comment https://forums.phpfreaks.com/topic/86276-solved-freakin-error-reporting-errors-trying-to-catch-mysql-errors-inside-class/#findComment-440714 Share on other sites More sharing options...
Alex-Grim Posted January 16, 2008 Author Share Posted January 16, 2008 I even tried this just now (completely different approach) to no avail function BugOut($args){ $this->O(); $this->Q("insert into BugReports (host,uri,uid,ctime,description)values('{$_SERVER['HTTP_HOST']}','{$_SERVER['REQUEST_URI']}','{$_COOKIE['uid']}','".date("Y-m-d H:i:s")."','$args')"); $this->C(); return true; } function Q($sql){ $query = mysql_query($sql); if ($query == false){ $this->BugOut(mysql_error()); return false; }else{ return $query; } } Quote Link to comment https://forums.phpfreaks.com/topic/86276-solved-freakin-error-reporting-errors-trying-to-catch-mysql-errors-inside-class/#findComment-440715 Share on other sites More sharing options...
Alex-Grim Posted January 16, 2008 Author Share Posted January 16, 2008 I've narrowed it down to the Bug Class. I'm having a problem on autoloading AND extending the Mysql class. How the hell am i to call the parent constructor when extending and autoloading, if the Bug class is being called from a page that has also already included the Mysql class via autoload? <?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:(); parent::Q("insert into BugReports (host,uri,uid,ctime,description)values('{$this->host}','{$this->uri}','{$this->uid}','{$this->ctime}','{$this->desc}')"); 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>"; parent::C(); } function R(){ } } ?> Fatal error: Undefined class constant '__construct' in This is due to auto loading it... Quote Link to comment https://forums.phpfreaks.com/topic/86276-solved-freakin-error-reporting-errors-trying-to-catch-mysql-errors-inside-class/#findComment-440724 Share on other sites More sharing options...
Alex-Grim Posted January 16, 2008 Author Share Posted January 16, 2008 That's fkn stupid that i can't edit my post. IGNORE THAT LAST POST. i found that error, but that's still not the one that's not catching the mysql errors. I still have the same problem Quote Link to comment https://forums.phpfreaks.com/topic/86276-solved-freakin-error-reporting-errors-trying-to-catch-mysql-errors-inside-class/#findComment-440730 Share on other sites More sharing options...
rajivgonsalves Posted January 16, 2008 Share Posted January 16, 2008 is the table getting updated is the connection properly ? Quote Link to comment https://forums.phpfreaks.com/topic/86276-solved-freakin-error-reporting-errors-trying-to-catch-mysql-errors-inside-class/#findComment-440731 Share on other sites More sharing options...
Alex-Grim Posted January 16, 2008 Author Share Posted January 16, 2008 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:(); 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. Quote Link to comment https://forums.phpfreaks.com/topic/86276-solved-freakin-error-reporting-errors-trying-to-catch-mysql-errors-inside-class/#findComment-440740 Share on other sites More sharing options...
Alex-Grim Posted January 16, 2008 Author Share Posted January 16, 2008 if i add this to the end of my bug report's insert statement, like so: $con->Q("insert into BugReports (host,uri,uid,ctime,description)values('{$this->host}','{$this->uri}','{$this->uid}','{$this->ctime}','{$this->desc}')") [color="Red"]or die (mysql_error())[/color]; It gives my the OTHER INSERT STATEMENT'S error Message!?!? Why would it do this? This must be why it's not getting entered into the DataBase. Quote Link to comment https://forums.phpfreaks.com/topic/86276-solved-freakin-error-reporting-errors-trying-to-catch-mysql-errors-inside-class/#findComment-440744 Share on other sites More sharing options...
Alex-Grim Posted January 16, 2008 Author Share Posted January 16, 2008 if i add this to the end of my bug report's insert statement, like so: $con->Q("insert into BugReports (host,uri,uid,ctime,description)values('{$this->host}','{$this->uri}','{$this->uid}','{$this->ctime}','{$this->desc}')") [color="red"]or die (mysql_error())[/color]; It gives me the OTHER INSERT STATEMENT'S error Message!?!? Why would it do this? This must be why it's not getting entered into the DataBase. Quote Link to comment https://forums.phpfreaks.com/topic/86276-solved-freakin-error-reporting-errors-trying-to-catch-mysql-errors-inside-class/#findComment-440748 Share on other sites More sharing options...
Alex-Grim Posted January 16, 2008 Author Share Posted January 16, 2008 I tried to use mysql_free_result(); but it's not working either. With the following code, i get the following error: $r2 = $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 ($r2 != true){ mysql_free_result($r2); Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource Quote Link to comment https://forums.phpfreaks.com/topic/86276-solved-freakin-error-reporting-errors-trying-to-catch-mysql-errors-inside-class/#findComment-440756 Share on other sites More sharing options...
trq Posted January 16, 2008 Share Posted January 16, 2008 Your code is seriously all over the place. Why does Bug extend MySql? It has nothing at all to do with database abstraction. As for your last error, read what it says. supplied argument is not a valid MySQL result resource. You check it $r2 equals false, if it does you call mysql_free_result passing the bool false as its argument. Quote Link to comment https://forums.phpfreaks.com/topic/86276-solved-freakin-error-reporting-errors-trying-to-catch-mysql-errors-inside-class/#findComment-440798 Share on other sites More sharing options...
Alex-Grim Posted January 16, 2008 Author Share Posted January 16, 2008 It doesn't matter anymore, i've gotten past that part, to the part that allows me to echo the error from the bug script, so i can access it now, but when i try to insert it into the db, it acts as if it were an object instead of a string. I fkn quit. I'm just going to have to use a seperate page, and pass the mysql error as a query, and then catch it. Till then, it's not being treated as a string. Quote Link to comment https://forums.phpfreaks.com/topic/86276-solved-freakin-error-reporting-errors-trying-to-catch-mysql-errors-inside-class/#findComment-440801 Share on other sites More sharing options...
trq Posted January 16, 2008 Share Posted January 16, 2008 Inserting errors into a log stored in a database is a poor design anyway (IMO), what if the db goes down causing errors? You'll never know. Quote Link to comment https://forums.phpfreaks.com/topic/86276-solved-freakin-error-reporting-errors-trying-to-catch-mysql-errors-inside-class/#findComment-440808 Share on other sites More sharing options...
Alex-Grim Posted January 16, 2008 Author Share Posted January 16, 2008 4 hours wasted on a stupid mistake that i have never made before: forgetting to ESCAPE the single quotes! Here's the finished product, which works exactly as it should've to begin with: class Bug extends MySql{ function __construct($description){ $h = $_SERVER['HTTP_HOST']; $q = $_SERVER['REQUEST_URI']; if (isset($_COOKIE['uid'])){ $u = stripslashes(str_replace("'","''",$_COOKIE['uid'])); }else{ $u = "Guest, or Not Logged In"; } $d = str_replace("'","''",$description); $t = date("Y-m-d H:i:s"); parent::Q("insert into BugReports (host,uri,uid,ctime,description)values('{$h}','{$q}','{$u}','{$t}','{$d}')"); 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>"; } } Quote Link to comment https://forums.phpfreaks.com/topic/86276-solved-freakin-error-reporting-errors-trying-to-catch-mysql-errors-inside-class/#findComment-440827 Share on other sites More sharing options...
Alex-Grim Posted January 16, 2008 Author Share Posted January 16, 2008 Inserting errors into a log stored in a database is a poor design anyway (IMO), what if the db goes down causing errors? You'll never know. Well, if the DB Goes awry, that's GoDaddy''s problem, as i pay for hosting now. But thenx for the help. Oh, and i kow that mysql isn't needed to be extended, but it's already included in a parent script, so i use it like that for simplicity Thanx again, this one had me FUMING! Quote Link to comment https://forums.phpfreaks.com/topic/86276-solved-freakin-error-reporting-errors-trying-to-catch-mysql-errors-inside-class/#findComment-440830 Share on other sites More sharing options...
trq Posted January 16, 2008 Share Posted January 16, 2008 Obviously, with all the hints at profanities. Quote Link to comment https://forums.phpfreaks.com/topic/86276-solved-freakin-error-reporting-errors-trying-to-catch-mysql-errors-inside-class/#findComment-440832 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.