Haunted Dawg Posted May 11, 2008 Share Posted May 11, 2008 Well i made a little function its pretty easy to use, its easier also. For those of you who like to use the mysql_query("") or die(mysql_error()); But ok lets shorten it, how about using query(""); and it still displays the mysql_error BUT it does not kill the rest of the game. Ok so here it is. Mainly made for v2 users. Add this code right a the bottom of globals.php <?php function query($sql) { global $h; $val = mysql_query($sql) or print '[b]You have a mysql error:[/b] '.mysql_error(); $h->endpage(); exit; return $val; } ?> I mainly made it because im sick and tired of the thing always displaying an error but killing the rest of the page. I know there is the $db->query(""); but i prefer using the old manual. So hope you like. NOTE: If you like to use my mods i suggest adding this since all my new mods are going to be using it. Quote Link to comment Share on other sites More sharing options...
Guest Anonymous Posted May 11, 2008 Share Posted May 11, 2008 Re: Almost a nice idea except for 2 little points. 1. Displaying the error message from queries may give people clues about you application and how it can be subverted. 2. There are a few occasions when I can happily ignore execution errors. Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted May 11, 2008 Author Share Posted May 11, 2008 Re: Well its simple, dont put a mod on your game that has errors. Thats why i have given this code because all the new mods i will be making will be using this function :) Quote Link to comment Share on other sites More sharing options...
Isomerizer Posted May 11, 2008 Share Posted May 11, 2008 Re: Well its simple, dont put a mod on your game that has errors. Thats why i have given this code because all the new mods i will be making will be using this function :) I don't think shes on about simple mis typed query errors, it could cause injections to become slightly easier with MySQL errors telling them exactly whats going wrong. Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted May 11, 2008 Author Share Posted May 11, 2008 Re: Anyways Here is a updated one, [code] <?php function query($sql) { global $h; $val = mysql_query($sql); if(!$val) { echo '[b]You have a mysql error:[/b]'.mysql_error(); $h->endpage(); exit; } return $val; } ?> [/code] Works better. Quote Link to comment Share on other sites More sharing options...
Floydian Posted May 12, 2008 Share Posted May 12, 2008 Re: I do something similar, except I only display the error to high level staff. Any one else gets a generic error message. Regardless of which of the above happens, it then mails me the error. Simple and effective. Quote Link to comment Share on other sites More sharing options...
Haunted Dawg Posted May 12, 2008 Author Share Posted May 12, 2008 Re: Floy that could be quite a easy script to make. [code] <?php function query($sql) { global $h, $ir; $val = mysql_query($sql); $error = mysql_error(); if(!$val) { if($ir['user_level'] == 2) { echo '[b]You have a mysql error:[/b] '.$error; $h->endpage(); exit; } else { echo '[b]A simple query error has been detected.[/b]'; event_add(1,"A query error has been detected in the ".$_SERVER['REQUEST_URI']." file, error is: ".$error); $h->endpage(); exit; } } return $val; } ?> [/code] Quote Link to comment Share on other sites More sharing options...
Guest Anonymous Posted May 12, 2008 Share Posted May 12, 2008 Re: Gotta love you guys ... Come on THINK.... If you are sending an event or a mail on a SQL error, guess what folks.. I'll take your boxes in minutes. How? Simple - force your system to generate multiple erroneous queries. As for register_shutdown_function() ... well, lovely idea, but newp. not powerful enough LostOne - although you are thinking along the right lines. Quote Link to comment Share on other sites More sharing options...
Floydian Posted May 14, 2008 Share Posted May 14, 2008 Re: That's assuming your code can fail :p And if mine can, I wanna know about it. Sometimes I login and see a hundred mails waiting for me, and I fix the problem making 100% sure it can never happen again. Quote Link to comment Share on other sites More sharing options...
Guest Anonymous Posted May 17, 2008 Share Posted May 17, 2008 Re: LostOne waits for ridicule from that cute like programmer... No ridicule L1, just a suggestion you look more closely at the manual and think a little more - You are on the right lines, but you need to extend this a little further... Quote Link to comment 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.