|
-
Mar 19th, 2004, 07:16 AM
#1
Thread Starter
Ex-Super Mod'rater
Or Die "Blah Blah Blaa"
When an error occours in my code, for example say the MySQL server is off-line, is there a way to just show the error message (or rather a piece of text) instead of all the HTML already sent with the error message half way down?
Would I need to use the buffer option thing and if so how do I?
Thanx.
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Mar 19th, 2004, 07:58 AM
#2
-
Mar 19th, 2004, 08:43 AM
#3
Thread Starter
Ex-Super Mod'rater
I might of .
Thanx for the help. I'd actually read that thread just the other day, I think my memory must be going .
P.S. I guess the @ sign can be used on any functions, not just the mysql ones?
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Mar 19th, 2004, 08:49 AM
#4
Thread Starter
Ex-Super Mod'rater
Hang on a sec, what if I dont connect to the Database till further down the page when some of the page has already been output. The message will still get displayed after that output. I'm wanting to be able to tell it to forget all I've already told it to send and just send the message (note: not the standard message).
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Mar 19th, 2004, 08:57 AM
#5
Frenzied Member
You really shouldn't be displaying anything on a page before opening a connection to the database you are about to use.
Suggestion: Create a connection file with all your calls to open the database. Then include that at the top of any file you plan to do database work with.
Example:
PHP Code:
<?php
$myServer = "heclnt1-edl-iso.hag.bulldog.com";
$myUser = "sa";
$myPass = "";
$myDB = "[ISOCAL]";
$s = @mssql_connect($myServer, $myUser, $myPass)
or die("<br><br><br><p class=warn>Couldn't connect to SQL Server on $myServer<br><br><p class=other>Please contact system administrator or try again later.");
$d = @mssql_select_db($myDB, $s)
or die("<br><br><br><p class=warn>Couldn't open database $myDB<br><br><p class=other>Please contact system administrator or try again later.");
?>
-
Mar 19th, 2004, 09:07 AM
#6
Originally posted by Electroman
Hang on a sec, what if I dont connect to the Database till further down the page when some of the page has already been output. The message will still get displayed after that output. I'm wanting to be able to tell it to forget all I've already told it to send and just send the message (note: not the standard message).
In that case you'll need the output buffering functions:
http://uk.php.net/manual/en/ref.outcontrol.php
Its still a good idea to use the @ symbol with any functions which rely on external entities such as databases and files though.
-
Mar 19th, 2004, 09:15 AM
#7
Thread Starter
Ex-Super Mod'rater
Thanx guys.
ober5861:It was more of a general thing, like anywhere I could use Or Die "Msg", not just Databases. I normally use the method you mentioned but in couple of my files I sometimes dont need to connect on certain times they are run so I have the include further down in an If statement .
When your thread has been resolved please edit the original post in the thread (  )
and amend "-[RESOLVED]-" to the end of the title and change the icon to  , Thank you.
When posting Code use the [VBCode]Code Here[/VBCode] tags to be able to use the code highlighting.

-
Mar 19th, 2004, 12:24 PM
#8
well, you could redirect the page as soon as an error comes up.. not sure if you want to do that though.
you could also try using some javascript:
put this in your header type thing
Code:
<script language='javascript'>
function error(){
document.write("liek call the php police!!!11");
}
</script>
and put this in your die():
Code:
@exit("bye!") or die("<script language='javascript'>setTimeout('error()', 1)</script>");
that should just clear the screen as soon as that code is printed out to the browser, and print out the document.write() in the JS error() function.. you could have different functions for different things, or just one universal one.
yeah, weird how i used 'exit or die'.. die() is just an alias for exit().. it will do the same thing each time..
-
Mar 19th, 2004, 12:47 PM
#9
uploaded a demo of it if you want to see it first:
i suggest going to the demo links "0" and then "1", because otherwise it may cache either of the pages on you..
http://david.gamersepitome.net/files..._die.php?die=0 : doesn't show an error
http://david.gamersepitome.net/files..._die.php?die=1 : shows the error
source for that script:
http://david.gamersepitome.net/files...ile=js_die.php
by the way, my 'source-viewing-script' does filter out database hosts/usernames/passwords, so it does create a valid link to my database when you aren't killing the script, it just doesn't show you.. and it also creates a bad connection, but it doesn't show you that either. i called "mysql_connect(0,0,0)" for the bad connection.
also, if you want, to explain the setTimeout JS function, here's my basic explaination of it:
setTimeout('JS code', timeoutInMillas);
put some javascript in the first parameter (it can be anything javascript; but usually is a function so there isn't a lot of typing within the call), and put how long you want it to take to occur in the second parameter. I put 1, for 1 ms, which will just change it instantly.
Last edited by kows; Mar 19th, 2004 at 12:51 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|