Re: Questions from a ColdFusion Developer

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



CF has an application scope - PHP does not.
the strength and simplicity of PHP stem from the decision to make/keep
PHP a "share nothing" architecture.

with regard to shoving stuff in the SESSION superglobal:

1. it not shared between requests by different users - meaning
that the SQL query you gave as an exmaple would still be run once
by every visitor and each visitor would have a copy of the
result set object.

2. performance-wise sticking objects in the session is possibly
something to be avoided is possible - storage and retrieval of 'complex'
structure (i.e. objects in this case) comes with a certain performance
penalty (you might want to consider using an array to store the query results)

3. you MUST load the class definitions of ALL the objects that are in your session
BEFORE you start the session.

Christopher Jordan wrote:
Hi folks,
I'm a ColdFusion developer, but I'm branching out into PHP because alot of my smaller clients don't want to pay for CF. Anyway, a bit of background: I've got a page that does a search on one of my tables. I'm using Justin Vincent's ezSQL (http://php.justinvincent.com) to fetch the result set into an object that can be referenced nicely. Here's what his example code looks like: // Select multiple records from the database and print them out..
          $users = $db->get_results("SELECT name, email FROM users");
          foreach ( $users as $user ){
                       //  Access data using object syntax
                      echo $user->name;
                      echo $user->email;
          }
So far so good. So I've got an iframe on the page which (I hope) will eventually display the results of the search. The user will then click on the search result for which they want to view the details, and the information from that row will be populated inside the main page (the one that houses the iframe). Hope that makes sense. Okay, so my trouble is that I don't know how to enable the page inside the iframe to have access to the result object created by Justin Vincent's nifty little class. In CF I can just say: session.oResults = queryname CF automatically returns any query as an object with the name of the query as the object name (i.e. queryname.MyIdField, or queryname.EmployeeNumber, etc.) Using a line like the one above (assigning the query object to a session variable) all of my subsequent requests would have access to that result set simply by using the object. I'm *sure* there's a way to do this in PHP. I'm just falling short of finding the answer. I've tried: $_SESSION["SearchResult"] = $db->get_results($query); But it doesn't seem to work. I may have some other problem using the object. I just re-read my error and it says: Fatal error: Call to a member function get_results() on a non-object in inventorymanager.php on line 93 hmm... I sure would appreciate a little guidence here. Even if my problem is with the way I'm using the object, is the idea of assigning that object to the session scope the right way to do this or is there a better approach. To that end, I suppose I'm looking for an idea of the best practice. Thanks!
  Christopher Jordan
  Planet Access
  Arlington, TX
			
---------------------------------
Yahoo! Shopping
Find Great Deals on Holiday Gifts at Yahoo! Shopping

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux