Home Php PHP Error handling



PHP Error handling
Posted on: April 18, 2011 at 12:00 AM
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.

 

Related Tags for PHP Error handling:


More Tutorials from this section

Ask Questions?    Discuss: PHP Error handling  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.