Automatically Collapse FirePHP Responses

3rd November 2010

FirePHP is a Firefox extension that allows you to log directly to the Firebug console from PHP. This is great for AJAX applications because you can debug your server side scripts without interferring with the responses.

Each script that returns a FirePHP log will generate it’s own group in the Firebug console which is expanded by default which means if you are logging a lot of data on the server side (such as database queries) then there will be a lot of data displayed in the console which you may not want to see all the time.

My solution to this was to edit the FirePHP extension so that each script response is collapsed automatically. You can then click a response to expand it if you want to view more details.

Read Full Post…

Alternative DATEDIFF for MySQL

26th October 2010

The DATEDIFF() function was added in MySQL version 4.1.1. For earlier versions that do not support this function you can make a work-around for it using the TO_DAYS function. This article show you how to do just that.

The following code shows how to perform the equivalent of DATEDIFF() when it is not available:

SELECT TO_DAYS(date1) - TO_DAYS(date2);

-- example
SELECT TO_DAYS('2010-01-03') - TO_DAYS('2010-01-01'); -- returns '2'

This will give the same effect as DATEDIFF(date1, date2) by converting each date to the number of days since year 0 and subtracting them.

Note: According the MySQL manual, TO_DAYS() is not intended for use with dates that precede the year 1582 because it does not take into account the days that were lost when the Gregorian calendar was introduced so using this method is not advisable for dates earlier than this.

Read Full Post…