Increasing query efficiency<

windows

Guest
I have a site where I'm doing lots of statistical operations with PHP and mySQL. My code is broken down into many different functions, but it seems several of my functions required queries to the same databases.

I'm trying to increase the efficiency of the operations so of course I'm trying to minimize the amount of database queries. Would it make more sense to start off my code doing a complete query of the databases I will be using and just store them in a global 2-D or 3-D array? I figure this would require more memory but reduce the number of queries I'm doing and my databases are not very large. Is this a normal practice?

Also, is it possible to send an entire array as a parameter in PHP or a pointer to an array?

Thanks.is it possible to send an entire array as a parameter in PHP or a pointer to an array
yes

you can do a query and get the info you need for the page. you can also store it in an array as you said, but if your site is small then no need to.

use pconnect is the best you can do without doing anything to the code. I mean, if you use many functions to do the samething than something is wrong huh?It's not that the functions are doing the same thing, they each have their own unique purpose. But they are doing 'similar' things in that they work on the data from the same databases.

I wasn't sure if each function had to do its own query to get the data it needed, or if it would be more efficient to do the query one time and make the data global. Or if it would make more sense to do the query one time and pass the resulting array to each function.you can pass the resulting array to the function. you can have one query per page and have that query in an array. this forums does just that. but if it is small then the point is mute.If your function use the same basic info from the db, just send the resource identifier for the query to the different functions, instead of re-doing the query. Like this:function function1($results){
if($row_info = mysql_fetch_array($results)){
//Do something with data from db
}
}
function function2($results){
if($row_info = mysql_fetch_array($results)){
//Do something with data from db
}
}
function function3($results){
if($row_info = mysql_fetch_array($results)){
//Do something with data from db
}
}
$db = mysql_pconnect("localhost","user_name","password") or die("Could Not Connect to MySQL");
mysql_select_db("db_name", $db) or die("Could Not Connect To Database");
$results = mysql_query("***put query here***",$db);
function1($results);
function2($results);
function3($results);Thanks guys I just didn't know if that was a common practice, but it makes sense.

I didn't even think of that Aaron, thanks for the info.
 
Back
Top