sql and php in a foldr