PostgreSQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsDatabasesPostgreSQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 18th, 2002, 05:34 AM
niico.c niico.c is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: France
Posts: 55 niico.c User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 11
Parametrized Query From Php To Postgresql

hello!
i'm working wiz postgresql and php and i'd like to know what is the best
way to send a parameterized (?) query to the postgres server and in order
to process results in php.

the ones i found are the following :

1- dynamically construct the query in my php script and send it to the server, i don't
feel like doing so, i'd like to put every sql statement in the database for a better
structure

2- make a function in pl/pgsql taking required parameters and after making a few tests
according to the params makes dynamically the sql query and stores the results in a
temporary table... i'm sure it is not the smartest way...

3- i know this can also be done wiz cursors but i don't really know how it works and how to use
them from a php script...

thanks for reading, i'm waiting for your suggestions!

Reply With Quote
  #2  
Old October 2nd, 2002, 12:03 AM
rycamor rycamor is offline
Gödelian monster
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 1999
Location: Central Florida, USA
Posts: 2,306 rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level)rycamor User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 3 Days 6 h 42 m 51 sec
Reputation Power: 60
We discuss PHP and cursors in these two threads:

http://forums.devshed.com/showthrea...ghlight=cursors

http://forums.devshed.com/showthrea...ghlight=cursors

PHP/PostgreSQL at the moment does not support parameterized queries such as with PHP/Oracle, where you "bind" a PHP variable to a parameter of a pre-compiled query. I hope that we will eventually get this ability, because it can have performance benefits in certain situations.

So a "parameterized query" really just means the query is pre-compiled in the database and only takes certain parameters, which are said to be "bound" to the query. It is not necessarily the same thing as a query that manipulates cursors to store temporary result sets.

But, if you use the cursor method I describe in the threads above, combined with a PL/pgSQL function, you can get some performance improvements. You might want to look at http://www.postgresql.org/idocs/ind...ql-cursors.html , and pay attention to the section about bound cursor variables. The point here is that the query plan is cached (maintained in a compiled state), which gives you the same performance advantages of a parameterized query.

The real point of all of this, to sum it up, is "push as much intelligence as you can into the database". If you need to do something that involves several queries, but only requires a couple incoming variables, then creating a stored procedure to handle all these queries will save a lot on I/O, since PHP doesn't have to talk back and forth to the database as much. (this is especially important if you are connecting to a database via network on another server).
__________________
The real n-tier system:

FreeBSD -> PostgreSQL -> [any_language] -> Apache -> Mozilla/XUL

Amazon wishlist -- rycamor (at) gmail.com

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesPostgreSQL Help > Parametrized Query From Php To Postgresql

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap