473,394 Members | 1,932 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

save resources *sql_query and array size

Hello,

i could not find information about extracting data by using
*sql_query (for me mssql_query) and do that in a way that saves server
memory.

I usually use:

$sql = "exec sp_get_GremiumsMitglieder
@foo = 'myFoo',
@bar = 42";

$rsResult = mssql_query($sql);
$i=0;
while($data = mssql_fetch_array($rsResult))
{
extract($data);
$mitglieder[$i] = array("id" => $id, "displayName" => $displayName,
"eMail" => $eMail, "authuser" =>
$authuser);
$i+=1;
}

So the result is an array half the size; instead of $mitglieder[0] and
$mitglieder[id] there is just $mitglieder[id].

Is there a better way. How can i free memory for Variables that are no
longer used (sql, rsResult, i). I sometimes read something about die()
/ exit() but the online documentation on php.net did not say anything
that would led to belive that memory is freed.

Is there a necessity / advantage to close the connection to
sql-server?
Thanks a lot

Tom Asken
Jul 17 '05 #1
2 1636
*** Tom Asken wrote/escribió (27 Apr 2004 03:48:42 -0700):
while($data = mssql_fetch_array($rsResult))
{
extract($data);
$mitglieder[$i] = array("id" => $id, "displayName" => $displayName,
"eMail" => $eMail, "authuser" =>
$authuser);
$i+=1;
}

So the result is an array half the size; instead of $mitglieder[0] and
$mitglieder[id] there is just $mitglieder[id].
You have just reinvented mysql_fetch_assoc(), haven't you?

I guess the best way to save memory is using data while reading it and
afterwards unsetting results. Your code makes a copy of the complete
results so you actually get data twice in memory.
Is there a better way. How can i free memory for Variables that are no
longer used (sql, rsResult, i).
Maybe unset()
I sometimes read something about die()
/ exit() but the online documentation on php.net did not say anything
that would led to belive that memory is freed.


With die and exit the execution of the script is terminated. If that
doesn't release memory then I don't think you could blame your script.

--
--
-- Álvaro G. Vicario - Burgos, Spain
--
Jul 17 '05 #2
Alvaro G Vicario wrote:
*** Tom Asken wrote/escribió (27 Apr 2004 03:48:42 -0700):
while($data = mssql_fetch_array($rsResult))
{
extract($data);
$mitglieder[$i]*=*array("id"*=>*$id,*"displayName"*=>*$displayNam e,
"eMail"*=>*$eMail,*"authuser"*=>
$authuser);
$i+=1;
}

So the result is an array half the size; instead of $mitglieder[0] and
$mitglieder[id] there is just $mitglieder[id].


You have just reinvented mysql_fetch_assoc(), haven't you?


That would be mssql_fetch_assoc() for mssql :)

Reimplementing your code using this function would look like so:

while($data = mssql_fetch_assoc($rsResult))
{
$mitglieder[$i] = $data;
$i++;
}

and the net result is the same as your original code but quite a lot
cleaner, and using less resources.

--
Chris Hope
The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Pavan Arise | last post by:
Dear all.. I have a picturebox filled on a form. The picturebox has some graphics displayed on it.I was trying to save the picturebox, but continuesly failed to do so. I am clueless of why it is...
3
by: PWalker | last post by:
Hi, I have written code that I would like to optimize. I need to push it to the limit interms of speed as the accuracy of results are proportional to runtime. First off, would anyone know any...
9
by: Mark Johnson | last post by:
How can you save all or a portion of the Grafics object to a Image/Bitmap ? I am try to save the Images from Cards.dll to a BitMap file. I can read in the Images to the Grafics, but when I try this...
3
by: sakurasyi | last post by:
hi there... can anyone help me? i'm trying to create a program that will save the information that i insert into xml files using asp. but, there is an error occur when i'm trying to save the...
6
by: AAOMTim | last post by:
I have a large ViewState and I've heard I can save the ViewState in a sesison object. What are the advantages of doing so and how do I do it? I've been told that I am gettign DNS timeouts because...
3
by: fiefie.niles | last post by:
I would like to save a web page to a file. When I do that, sometimes the saved web page does not look like the original web page. For example, when I save www.msn.com, it looks very different the...
3
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of...
3
by: =?Utf-8?B?Um9nZWxpbw==?= | last post by:
I'm having the wierdest problem. I'm trying to save images into a SQL 2005 database. the field is just called "IMAGES" and hte data type is "image". here is my code to save //following code...
1
by: chennaibala | last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading. i develop...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.