September 7th, 2000, 07:00 PM
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?
September 8th, 2000, 12:52 AM
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!");
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.
[This message has been edited by swanicke (edited September 07, 2000).]
September 8th, 2000, 01:02 AM
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.
September 8th, 2000, 01:22 AM
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).]