Possible Duplicate:
what are the differences in die() and exit() in PHP?
I am totally confused in the difference of die
and exit
.
Most programmers use die
like this.
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); //don't see mysql_* problem it is just example
if (!$link) {
die('Could not connect: ' . mysql_error());
}
and using exit
like this
$filename = '/path/to/data-file';
$file = fopen($filename, 'r')
or exit("unable to open file ($filename)");
According to there functionality , I don't think so there is any difference because both terminates the execution of the script.
My question is
1) Can I interchange die with exit and vice-versa in these examples?
2) And the difference between these also.
Cheers...
What is the difference between echo and die() or are they same? The die() function can accept an optional argument string that it will output just before terminating the script. echo() only outputs its arguments, it will not terminate the script.
The exit() function prints a message and terminates the current script.
The die() is an inbuilt function in PHP. It is used to print message and exit from the current php script. It is equivalent to exit() function in PHP. Syntax : die($message)
According to Die it is Equivalent to exit. So yes, you can interchange them .
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With