or die() question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Guy
Forum Commoner
Posts: 53
Joined: Sun Jan 12, 2003 3:34 am

or die() question

Post by Guy »

do I always have to do die() after an or when calling a function?

Code: Select all

(mysql_connect() or die("text") )
or is it just a convention?
all the examples I saw had die() after the or.
thanks
Guy
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

No you don't - it's used to prevent further code from running if an important function fails. For example if you can't connect to a database you wouldn't then want to try and query it because you'll just get loads of errors.

You don't see it used much except when it comes to database functions.

Mac
User avatar
Guy
Forum Commoner
Posts: 53
Joined: Sun Jan 12, 2003 3:34 am

Yes,

Post by Guy »

but instead of stopping everything you can instead return something
that indicates failure and catch it.
I always thought that die() is too harsh.
Guy
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Of course you can. Or die() isn't always appropriate.

Mac
Post Reply