Jump to content
MakeWebGames

[PHP Snippet]


Haunted Dawg

Recommended Posts

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.

Link to comment
Share on other sites

Guest Anonymous

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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]
Link to comment
Share on other sites

Guest Anonymous

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.

Link to comment
Share on other sites

Guest Anonymous

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...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...