My first project with PHP and postgreSQL, I have a good experience in MSSQL and ASP. I was run test connections with pg_connect and PDO and everything was OK, making some test with a 3000 rows resultsets I was encounter that pg_connect have is at least 20% more speed than PDO. In other hand I see most people use PDO, why? In your opinion what are the pros and cons for each one? Thank's.
Asked
Active
Viewed 3,344 times
3
-
2See [What kind of questions should I not ask here?](http://stackoverflow.com/faq#dontask) – mishmash Jan 10 '13 at 20:12
-
You should clarify, whether or not your tests run under the same circumstances, which sadly includes nearly every default setting of both interfaces. The 30% appears slightly too much (not saying, that one may not be faster than the other). – KingCrunch Jan 10 '13 at 20:17
-
@vanneto sorry, I ask because is a practical problem, I need to choose and many experienced people here can have the key for that decision. – HMarioD Jan 10 '13 at 20:27
-
@KingCrunch, I'm running the defaults installation of PHP and postgreSQL in my machine, your are right I repeat the test many times and never reach 30%, but is never under 14% and usually is around 22%. I will check if some missconfiguration. Thanks. – HMarioD Jan 10 '13 at 20:34
-
See [this similar question](http://stackoverflow.com/questions/10384224/pdo-vs-pg-functions) – Daniel Vérité Jan 10 '13 at 20:44
-
@HMarioD And this is only the time for `connect()` (or similar)? hmm... 20% sounds a little bit more realistic :) But I guess we are talking about very small values? – KingCrunch Jan 10 '13 at 20:56
-
@KingCrunch is the time for all, connection and retrieve the data, and yes there are small values ~600ms. But in my app. the response time is critical. Thanks for your time. – HMarioD Jan 10 '13 at 21:04
1 Answers
2
If you are comfortable with object-oriented programming, I would recommend PDO. For most projects that feature a reasonable amount of database interaction, you would probably want to use a wrapper class for your *_connect functions anyway. PDO eliminates this need since you are using objects already.
Also, PDO has convenient methods for prepared statements, which is a secure way to insert / update data.

Jason Fingar
- 3,358
- 1
- 21
- 27
-
Thanks for your answer, now I think I may use both because some "pages" are actually services and need to give very quick responses, and other are regular pages. – HMarioD Jan 10 '13 at 20:41