How to: User defined function returns a result set

Is it possible to make a user defined function return a result set? How?

For example:

$rs = mysql_query("SELECT udf_students(2011);");

The above query will return all students who enrolled in 2011.

I know how to write user defined functions in mysql.
But cannot return a list of data into a result set that can be assigned to PHP resource variable.

This would help me hide a lot of business logic inside the database itself.
And save a big time.