pTutorial

New way to learn PHP function

PHP die() Function

Syntax


die("string");

Parameter Description
String Any string message(required)

Definition & Usage

Die function is used to print a user-friendly message and exit the script instead of the language defined error message. Die function does not return anything.

Note: In case of die function string message is printed, variable cannot be printed either its string variable or a number variable.

Example of die function



<?php
if(5)
{
die("True");
}
else
{
die('False');
}
echo "It will not execute.";
?>



Output

True

According to the above example, the condition is true and the first die function will execute and stop the execution so that the last echo statement will not be executed.

More example of die function


<?php

$db= mysql_connect("localhost","root","") or die("Could not connect");

?>

In the above example, if the connection is failed to connect due to any reason die function displays given message "Could not connect" and terminate script from where die function called.

Note: Rest of the script after the die function will not be executed shown in the example.

QUOTES OF THE DAY

Beauty is truth, Truth beauty- That is all

LIKE ON FACEBOOK

+1 ON GOOGLE

SHARE ON TWITTER