Question about Postgresql functions/stored procedures

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
barb woolums
Forum Contributor
Posts: 134
Joined: Sun Feb 08, 2009 9:52 pm

Question about Postgresql functions/stored procedures

Post 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");
 
Post Reply