The last observation with the php file was with regards to building the $fields and $values where you use array_walk and implode, etc. All of that is fine and great, but I had a situation where I had a column in my grid that was not in the database table (it was calculated elsewhere). In any event, my point is, I simply added a check to see if the $field was in_array($the_object_fields_that_you_set_up). So just a quick little check to make sure the query wasn't built using fields that were not in the database table.
Again, these last two are rather application specific, but since I thought they could be generalized a bit I thought I'd point them out anyway.