Thread: Or Die Command

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    36
    Rep Power
    14
    I'm a little bit unsure how the die command works.

    Let's say I have the following:
    $result = mysql_query("Select * from trials where login='$login' and pass='$pass';") or die("Server Busy. Hit back and try again");

    if the thing can't complete for the query for whatever reason, will it print "Server buys. Hit back and try again"?

    Or is that the value stored in $result.

    And secondly, if there is no match, I assume that that won't cause it to die, that will only result in $result being empty. Is that the case?


    Thanks

  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Gig Harbor, Washington, USA
    Posts
    29
    Rep Power
    0
    Well if I am right that command isn't excecuted until you use the $result variable. For example:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    $result = my_function($myvar);

    my_other_function($result) or die("Chicken tastes good!");
    [/code]
    So I think that the die() should be put on the execution line, not the variable one.

    By the way die() completly kills the script and displays a message (that you define) if your line could not be excecuted.

    ------------------
    chris swanicke
    swanicke@defected.net

    [This message has been edited by swanicke (edited September 07, 2000).]
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Gig Harbor, Washington, USA
    Posts
    29
    Rep Power
    0
    No, I think I am wrong I am seeing people using die() on the variables like you have. My advice is to purposely mess up the connection and see what happens. Then connect normally and see what happens.

    That'll work

    ------------------
    chris swanicke
    swanicke@defected.net
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    300
    Rep Power
    14
    die() raises an exception (at least it does so in Perl) and exits your script. When you write something lke you did, it will first check to see whether or not the query succeded. If it did, the pointer will be stored in the variable $result so you can later use it with mysql_fetch_array() and the like. If not, the die() function will terminate your script with the error message you supply. Thats why you have the or between these two statements.

    I hope this makes it a little clearer. Almost every scripting language that has some UNIX roots has the die() function. Tcl, Perl, various shells...

    [This message has been edited by dwarf (edited September 08, 2000).]

Similar Threads

  1. ftplib
    By XxChris in forum FTP Help
    Replies: 4
    Last Post: February 17th, 2004, 03:54 PM
  2. Evoke Shell Command in Perl
    By yannn in forum Perl Programming
    Replies: 0
    Last Post: February 16th, 2004, 02:14 PM
  3. MySQL "source" command in PHP
    By crackwombat in forum PHP Development
    Replies: 2
    Last Post: January 18th, 2004, 06:25 AM
  4. Problem executing mv command inside shell script
    By pablo.gosse in forum Linux Help
    Replies: 7
    Last Post: January 2nd, 2004, 01:58 AM
  5. problem with cal command
    By bob242 in forum Apache Development
    Replies: 0
    Last Post: September 16th, 2003, 06:52 AM

IMN logo majestic logo threadwatch logo seochat tools logo