mercredi 24 décembre 2014

Database vs. server-sided scripting language


To keep my question short and to the point, consider this:



$relation = $mysql->query("SELECT relation($loggeduser, $requesteduser) AS a")->fetch_assoc()['a'];
if ($relation != BLOCKED)
{
return $mysql->query("SELECT stuff FROM sometable WHERE powerlevel>9000 LIMIT 39");
} else {
return '{"error":"not enough jquery"}';
}


Where relation is some MySQL function. When would this^ approach be better than something like this:



$stuff = $mysql->query("SELECT getstuff($loggeduser, $requesteduser) AS a")->fetch_assoc()['a'];
return ($stuff != null) ? $stuff : '{"error":"stop it"}';


Where getstuff is some MySQL function that just does everything that the first code would do.


In this scenario, the second seems to make a lot more sense. In reality, the second makes sense for so many other scenarios I can think of to the point where you can have a web app essentially composed of just MySQL functions that deal with almost everything you need (i.e. getUsers, getFollowers, pageInfo, etc.).


However, I'm surely missing something, and my question is this - When should I not use MySQL functions over server-sided scripting operations? You can omit the obvious (i.e. saving/processing files, etc.).





Aucun commentaire:

Enregistrer un commentaire