faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

28 of 31 people (90%) answered Yes
Recently 8 of 10 people (80%) answered Yes


What's the best policy? Connect once, store the query results in several arrays to use later or p_connect and query at the moment I need the results?

Feb 18th, 2008 19:31
dman, Vincent E, Wiebe de Wolf, http://www.ttnr.org

First, a database connection stays open until you close it,
so using Pconnect does not have any benefits within one script.
It only saves time when another script is run (or the same script is run
again), it can re-use the opened connection.
Second, it depends very much on how you are going to use the data.
If you run a query to get a list of names that you need to print 34
times, then an array would be better.
But if you are just printing it once, a query is more efficient.
From a memory-usage point of view, storing results in an array means
that while you are filling the array, you need a lot more memory than
when you would just do a query.