PHP,MySQL动态数学

I am trying to find out a way to do maths dynamically. I want to be able to add a formula to MySQL and then solve it in PHP and display the answer.

So I'll save it like getItemPrice(10) * getItemPrice(50) However I'm unsure how to execute functions in PHP if its saved like that.

I thought about splitting the date but I want to be able to do more advanced formulas then that. I have no idea how to do this to be honest...

If the text you stored in db is a valid php code you can use

eval — Evaluate a string as PHP code

http://php.net/manual/en/function.eval.php

otherwise if the text is a valid mysql code you can generate a dinamic sql statementes and the execute as a normal sql statemets ..