Alex Rivera | Logout

How does "do something OR DIE()" work in PHP?

Asked 2009-01-11T06:14:24.463
113

I'm writing a php app to access a MySQL database, and on a tutorial, it says something of the form

mysql_connect($host, $user, $pass) or die("could not connect");

How does PHP know that the function failed so that it runs the die part? I guess I'm asking how the "or" part of it works. I don't think I've seen it before.

Edit
Report

1 Answer

1

If you would like to add more code if the connection doesn't work, beyond a die statement:

$con=mysql_connect($host, $user, $pass)
if(!$con)
{
     // ... add extra error handling code here
     die("could not connect");
}
else
{
     echo "Connected";
}
answered 2010-08-31T03:46:27.380

Your Answer