Results 1 to 9 of 9

Thread: Or Die "Blah Blah Blaa"

  1. #1

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349

    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.

  2. #2
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  3. #3

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    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.

  4. #4

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    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.

  5. #5
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    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."); 

    ?>
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  6. #6
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Ickenham, UK
    Posts
    4,906
    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.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  7. #7

    Thread Starter
    Ex-Super Mod'rater Electroman's Avatar
    Join Date
    Sep 2000
    Location
    Newcastle, England
    Posts
    4,349
    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.

  8. #8
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    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..
    Like Archer? Check out some Sterling Archer quotes.

  9. #9
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    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.
    Like Archer? Check out some Sterling Archer quotes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width