Page 1 of 1

Arrays vs. Database for storing cart items

Posted: Sat Nov 30, 2002 3:14 pm
by EricS
I've been debating using using multi-dimensional session arrays or a table in a MySQL database to store items for purchase in a shopping cart.

One question involves SSL. The majority of the cart is run outside of SSL using sessions to track customers as they move around. Now as I understand it the session id gets stored in a cookie (im not inserting the session id in the urls) and that's how the server matches clients with session variables. Once the customer has added all the items they want to the shopping cart, they will get sent to an https url for checkout(same server and same domain, just secure). Will going from a none secure to a secure connection force a new session or will the same variables carry over? In other words will customers lose their session variables when they switch to a secure connection?

Next. If I use a table in a database, I can't think of a fast way to clean the table of customers who chose items but didn't buy. They would quickly clutter up a table if you have people windows shopping but not buying.

I'm leaning toward arrays because they should be faster and they are self cleaning, that is its already handled by the server. I understand that it's more difficult to code item tracking with arrays, but isn't it worth it for the speed and flexibility. All the shopping cart tutorials I see that use a database to store items don't talk about garbage collection. I know I could use crontabs but that wouldn't be easy for other people to set-up and it wouldn't make for a very portable shopping cart.

What is everyone elses feeling on the matter.
Thanks in advance.

Posted: Sat Nov 30, 2002 3:59 pm
by MeOnTheW3
I would strongly suggest that you use a db like mysql or oracle. ( I would also suggest postgreSQL, but I don't have the benchmarks on it).

A database like above will always be faster that a bunch of session arrays if you anticipate any significant useage.

Arrays take up system resources the enitre time they are alive. DB access only takes very little system resources only when called upon.

Note: if you are on a ALL Microsoft software stack, the best dbms will always be MS SQL Server 2000.

=======
As for the destroying of outdated tables:
Build a shopping cart that accomidates this. Design a system that initializes a session, you can still pass the $sid in a cookie. In each page access have a little script that updates a session table with a timestamp. If ever that session runs over 3 hours without an update, kill it by destroying the cart-table record associated with the $sid.