How to troubleshoot PHP critical code using die()

If you are complex issue in PHP and you do not have debugger install or do not want to use debugger, there is an easy way to troubleshoot your code.

Place die(); function right at the point where you want to troublesheet/example values. The program will stop at that point and you see your values.

Example of Using Die

You have a query that is returning unsuspected result. There is no way you can debug the code directly or you can’t output the content because the page redirects. In this case use die();

$query = "select * from mytable where id='$id'";
echo $query;
die();

The execution will stop at this point and you can examine your query.

Advertisements
This entry was posted in Tutorials/Tips and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s