Using sessions with MSSQL resultsets

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Silo
Forum Newbie
Posts: 4
Joined: Thu Apr 19, 2007 1:06 pm

Using sessions with MSSQL resultsets

Post by Silo »

Hi all. This is my first post here, and I've been working with PHP for a very short period of time. I appreciate any help.

My problem most likely stems from me not understanding how to properly work with MSSQL result sets and arrays, but here goes. I've got a form that compiles a query based on the information provided. I've written a function that executes the query and spews out the data in a table.

At the end of the page, I want to have an option to send that data to a spreadsheet. I've gotten that to work just fine by sending the query to my create_spreadsheet.php page, but I'm trying to avoid hitting the database twice for the same amount of information.

If I understand correctly, I should be able to use the result set from the function that creates the table and send that over to my create_spreadsheet.php page and skip hitting the database again. $rs is the variable that contains the result set. Now, I may not properly understand variable scope either, but I declared $rs as global before the function as well as within the function so that I may use it elsewhere. I did some googling after realizing POST won't handle sending a big result set like that, so I decided to try using sessions.

This is on the primary page:

Code: Select all

session_start();
$_SESSION['resultset'] = $rs;


echo "<TD>";
echo "</FORM><form action=\"create_spreadsheet.php\" method=\"POST\">";
echo "<INPUT TYPE=\"SUBMIT\" NAME=\"action\" value=\"Create Spreadsheet\">";
echo "</TD></FORM>";
The problem is when my spreadsheet function tries to use $rs, I get this:

Code: Select all

Warning: mssql_num_fields(): supplied argument is not a valid MS SQL-result resource in /var/www/html/reports/8-function.inc on line 255

Warning: mssql_fetch_row(): supplied argument is not a valid MS SQL-result resource in /var/www/html/reports/8-function.inc on line 262
Shouldn't this be working? What am I missing? The function that first uses $rs to create the table works just fine.


Thanks ahead of time for any help!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

http://de2.php.net/session wrote:Warning

Some types of data can not be serialized thus stored in sessions. It includes resource variables or objects with circular references (i.e. objects which passes a reference to itself to another object).
mssql connection resources cannot be restored from session data.
You might store the actual data fetched via mssql_fetch_[array/assoc/field/object/row]
Silo
Forum Newbie
Posts: 4
Joined: Thu Apr 19, 2007 1:06 pm

Post by Silo »

Ahhhh, now I see.

Next question: Is it possible to pass an sql resource like that between pages some way other than using sessions?
Post Reply