What is the difference between die() and exit() in PHP?
Hello everyone! I started learning PHP and came across two functions that seem to do the same thing: die() and exit(). I've seen them used in different scripts and can't understand what the difference between them is.
For example, I write a simple database connection check:
```php
$connection = mysqli_connect('localhost', 'user', 'pass', 'db');
if (!$connection) {
die('Connection error: ' . mysqli_connect_error());
}
```
But I've also seen some people write exit() instead of die():
```php
if (!$connection) {
exit('Connection error: ' . mysqli_connect_error());
}
```
They both stop script execution and output a message. This is confusing. Maybe one of them is deprecated? Or is there some subtle difference in behavior that I'm missing? In the documentation
No answers yet.
Log in to leave an answer