Home Php PHP Error handling
Questions:Ask|Latest

 
 

Share on Google+Share on Google+

PHP Error handling

Advertisement
This page discusses - PHP Error handling

PHP Error handling:

PHP provides so many techniques to handle error, if error occurs an error message is send to the browser.

Error handling should be the main concern whenever we develop any web application. If we do not take these things under consideration then we might develop an unprofessional web application.

In this tutorial you will come to know about different handling methods:

  • die() statement

We will see that what will be the output if we use die statement and don't.

Let's see what will be the output if we do not use die statement and try to connect with a MySQL server with an invalid user name:

Example:

<?php

$var=mysql_connect("localhost","rose","");

?>

Output:

Warning: mysql_connect() [function.mysql-connect]:
 Access denied for user 'rose'@'localhost' (using password: NO)
in C:\wamp\www\php\temp.php on line 2

Now we will examine what happen if we use die() statement.

Example:

<?php

$var=mysql_connect("localhost","rose","");

if(!($var))

{

die("Error".mysql_error());

}

else

{

echo("Welcome");

}

?>

 

Output:

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'rose'@'localhost' (using password: NO) in C:\wamp\www\php\temp.php on line 2
ErrorAccess denied for user 'rose'@'localhost' (using password: NO)

As we can see that die() statement generates a message regarding the error.

 

Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 18, 2011

Related Tutorials

Ask Questions?    Discuss: PHP Error handling  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com