This question could mean one of two things. It might be, "How do I write Perl or PHP code that uses a MySQL or PostgreSQL database?" Or, it might be, "Is it possible to write functions and procedures in MySQL and PostgreSQL using Perl or PHP?" For the former, there are a few choices. PHP offers extensions specific to MySQL and to PostgreSQL, so you might write code using mysql_query or pg_query. You can also use PDO or ODBC to connect in a more or less database agnostic manner.
With the aid of some user defined functions and a thread-safe compilation, it is possible to write functions for MySQL using Perl and PHP. See http://www.linuxjournal.com/article/6841 and http://www.sklar.com/page/article/myphp for details. It is possible that future versions of MySQL will allow a more "plug and play" approach to coding procedures in other languages.
This was first published in January 2007