Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Good day,

We have some Java programmers in our software dev, and they are
pressuring us to use Sessions to store data and use that Session to get
query data. They say that it is ok since it is like Entities in Java. I
am baffled as a .NET programmer, we tend to avoid using sessions and
instead use DataSet, is there any equivalent of dataset in PHP?

Re: SESSIONS wrote:

Quoted text here. Click to load it


I would NOT advise storing a complete resultset in your session.
If you store it simply in your session, you store a resourceID, which is  
unusable next invocation of any script using the same session.

You can however store an array-representation of the resultset in your  

If you use ADODB as a databaseabstractionlayer, you can do the following:
$res = $conn->Execute($SQL)->GetArray();

Beware however that big resultsets stored in session is asking for  

Also, if you want to see your session:
 <? print_r($_SESSION); ?>

Erwin Moller

Re: SESSIONS wrote:
Quoted text here. Click to load it

One thing to remember is with PHP information does not survive the page unless  
it is stored externally.

Sessions are a very convenient and safe way to store the data.  Data is stored  
locally on the server and only the session ID is stored in the client's browser.  
  PHP handles the sessions quite well; all you need to do is place  
session_start() at the beginning of each page where you wish to use sessions.  
If no session has been previously started, a new one is created.  Otherwise the  
existing session is used.

Then you can set and retrieve data from the $_SESSION superglobal array, just  
like any other superglobal, i.e.

   $_SESSION['counter'] = 1;

   $myvar = $_SESSION['counter'];

Quick, easy and convenient.

Now - I wouldn't use sessions to store a megabyte of data or more, because the  
entire array would be read into memory.  This could cause performance problems.  
  But if you need to store that much perhaps you need to rethink your structure  
a little more.  A database might be more reasonable, depending on your needs.

Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.


A session is like a shopping cart or a theater's wardrobe. It is a piece  
of storage assigned to a visitor.
What you put in a session are mostly things that should remain on the  
server, because you do not want the visitor to be able to mess with it.  
For instance, a login function can return a role, that determines access  
rights. You can store this role in the session, but you do not want to  
store it in a hidden form variable in HTML.
Sessions in PHP are not fundamentally different from those in .NET.  
There is a session array that can be filled with anything serializable  
and in some cases more.

So you do not have to store every query result, but a session can be a  
good place to store intermediate results that are needed later. Sessions  
are the "trick" that make a bunch of stateless http-calls look like a  
continuously running web application.

Best regards wrote:
Quoted text here. Click to load it

Site Timeline