Page 1 of 1

Question about Postgresql functions/stored procedures

Posted: Sun Sep 27, 2009 3:08 am
by barb woolums
I want to convert the queries on my website (php) to stored procedures in my Postgresql db for security reasons.

I have several similar queries as you can see below.

I was hoping I could create one function to cover all the queries by just substituting the different field as a parameter, but I can't figure out how to do this with the queries in thier current form. Is there a way of doing this?

Code: Select all

 
$dbdiet = pg_query($connection, "SELECT get_diet(diet) as diet FROM diet_owner where owner=$uid ORDER BY diet");
$dbunit = pg_query($connection, "SELECT get_unit(unit) as unit FROM unit_owner where owner=$uid ORDER BY unit");
$dbing = pg_query($connection, "SELECT get_ingredient(ingredient) as ingredient FROM ingredient_owner where owner=$uid ORDER BY ingredient");
$dbpp = pg_query($connection, "SELECT get_preprep(preprep) as preprep FROM preprep_owner where owner=$uid ORDER BY preprep");