Mysql functions for web apps

functionsMySQL

I have few questions about using functions in a MySQL database for plugins and extensions of web apps like Magento or WordPress. Mostly this is for a few extensions I want to do for Magento. The questions are:

  1. is it possible under normal average hosts out there, that functions can be added.
  2. (if 1) is it worth the effort to create function that would replace php in some manner (speed mostly is what I'm thinking)
  3. (if 1) can functions be looped? like timed or call to it's self x time like sleep or something.

I was wanting to use the db for simple things like removing rows that were older then or something like that. Examples are not as important as possibility here in my mind. This is more of a set of questions that are due to not every really seeing web app use functions, and it just seems like an area of untapped potential for optimization when designing web apps.

Best Answer

I can't answer to question 1 as I do not have enough information about the MySQL instances offered by different hosting providers.

To answer the rest of your questions, yes, if you can leverage the features of the RDBMS you're using, you might replace PHP code with SQL scripts that can run faster than your code. Just think about the time you're saving up by not transferring your data back and forth.

On the other hand you would probably still end up using PHP code or other programs (crontab or any other kind of scheduler) to run your timed tasks as there's no built-in scheduler in MySQL.