The error handling in PHP is very easy. An error message with filename, line number and a message describing the error are sent to the browser.
When generate scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unethical and you may be open to security risks.
Using the die() function
The first illustration shows a simple script that opens a text file:
<?php
$file=fopen(“chi1.txt”,”c”);
?>
If the file does not exist you might get an error like this:
Advice: fopen(chi1.txt) [function.fopen]: failed to open stream:
No such file or directory in C:\webfolder\test.php on line 2
To avoid that the user gets an error message like the one above, we test if the file exist before we try to access it:
<?php
if(!file_exists(“chi1.txt”))
{
die(“File not found”);
}
else
{
$file=fopen(“chi1.txt”,”c”);
}
?>
Now if the file does not exist you get an error like this:
File not found
The code above is more competent than the earlier code, because it uses a simple error handling device to stop the script after the error.
It is a solution fatal error “Fatal error: Call to undefined function mysql_connect()”
I tried to solve that by following those steps :
1. Made sure “c:\php” is in the PATH string
2. Put “libmySQL.dll” in the “c:\php” directory
3. Set: extension_dir = “c:\php\ext” (which is where “php_mysql.dll” and “php_mysqli.dll” are) in the “Paths and Directories” Section of php.ini
4. Enabled those DLL’s by adding:
extension=php_mysql.dll
extension=php_mysqli.dll
to the Dynamic Extensions section of php.ini
After that I tried to run a simple program but instead of the fatal error I conventional the following notice ” Notice: Object of class mysql result could not be converted to into in C:\PHP\phpFiles\mysql_up.php on line 15″
To change the memory limit for one specific script by including a line such as this at the top of the script:
ini_set(“memory_limit”,”12M”);
The 12M sets the limit to 12 megabytes (12582912 bytes). If this doesn’t work, keep increasing the memory limit until your script fits or your server squeals for mercy.