Arrays as Session Variables?

This is a discussion on Arrays as Session Variables? within the PHP Language forums, part of the PHP Programming Forums category; To avoid repeated hits on my database, I'd like to use a single access, from which I can create ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-08-2008
Alan M Dunsmuir
 
Posts: n/a
Default Arrays as Session Variables?

To avoid repeated hits on my database, I'd like to use a single access,
from which I can create a list of all the records of a particular type
which already exist.

I'd then have to store the identifiers of all these existing records as
the members of an associative array, but I'd have to be able to copy
this array's members to a Session Variable.

Is this possible?

Can I do

rec['A']['B'] = true;
rec['C']['D'] = true;
Reply With Quote
  #2 (permalink)  
Old 03-08-2008
Michael Fesser
 
Posts: n/a
Default Re: Arrays as Session Variables?

..oO(Alan M Dunsmuir)

>To avoid repeated hits on my database, I'd like to use a single access,
>from which I can create a list of all the records of a particular type
>which already exist.
>
>I'd then have to store the identifiers of all these existing records as
>the members of an associative array, but I'd have to be able to copy
>this array's members to a Session Variable.
>
>Is this possible?


Yes.

Micha
Reply With Quote
  #3 (permalink)  
Old 03-08-2008
Jerry Stuckle
 
Posts: n/a
Default Re: Arrays as Session Variables?

Alan M Dunsmuir wrote:
> To avoid repeated hits on my database, I'd like to use a single access,
> from which I can create a list of all the records of a particular type
> which already exist.
>
> I'd then have to store the identifiers of all these existing records as
> the members of an associative array, but I'd have to be able to copy
> this array's members to a Session Variable.
>
> Is this possible?
>
> Can I do
>
> rec['A']['B'] = true;
> rec['C']['D'] = true;
> .
> etc.
> .
> .
> $_SESSION['recs'] = rec;
>


It's possible, but why would you want to? Databases are made for
retrieving data.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
  #4 (permalink)  
Old 03-08-2008
Alan M Dunsmuir
 
Posts: n/a
Default Re: Arrays as Session Variables?

Jerry Stuckle wrote:
>>

>
> It's possible, but why would you want to? Databases are made for
> retrieving data.
>

I believe that that very question is at the centre of the "Web 2"
revolution, which has the emphasise switching to asynchronous database
access, so as not to slow down too far database Web applications.
Reply With Quote
  #5 (permalink)  
Old 03-08-2008
Jerry Stuckle
 
Posts: n/a
Default Re: Arrays as Session Variables?

Alan M Dunsmuir wrote:
> Jerry Stuckle wrote:
>>>

>>
>> It's possible, but why would you want to? Databases are made for
>> retrieving data.
>>

> I believe that that very question is at the centre of the "Web 2"
> revolution, which has the emphasise switching to asynchronous database
> access, so as not to slow down too far database Web applications.
>


Not at all.

First of all, you are prematurely optimizing. Secondly, your premature
optimization may slow down the system. And finally, you're creating
more code, which has to be debugged and maintained.

But then why not just store everything in a flat file? Then you don't
even need a database.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Reply With Quote
  #6 (permalink)  
Old 03-09-2008
Tim Roberts
 
Posts: n/a
Default Re: Arrays as Session Variables?

Alan M Dunsmuir <alan@moonrake.demon.co.uk> wrote:
>
>To avoid repeated hits on my database, I'd like to use a single access,
>from which I can create a list of all the records of a particular type
>which already exist.
>
>I'd then have to store the identifiers of all these existing records as
>the members of an associative array, but I'd have to be able to copy
>this array's members to a Session Variable.


....which is then stored in a flat file on your server's hard disk (by
default), and which gets re-read and re-parsed for every PHP request. Are
you sure that's an improvement?
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
Reply With Quote
  #7 (permalink)  
Old 03-09-2008
Michael Fesser
 
Posts: n/a
Default Re: Arrays as Session Variables?

..oO(Tim Roberts)

>Alan M Dunsmuir <alan@moonrake.demon.co.uk> wrote:
>>
>>To avoid repeated hits on my database, I'd like to use a single access,
>>from which I can create a list of all the records of a particular type
>>which already exist.
>>
>>I'd then have to store the identifiers of all these existing records as
>>the members of an associative array, but I'd have to be able to copy
>>this array's members to a Session Variable.

>
>...which is then stored in a flat file on your server's hard disk (by
>default), and which gets re-read and re-parsed for every PHP request. Are
>you sure that's an improvement?


Impossible to say without more details. In some cases caching the result
can be an improvement, for example if the query is complex or the DB is
not MySQL where connections are cheap.

Micha
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:44 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0