Insurance Quote System

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Sjwdavies
Forum Commoner
Posts: 25
Joined: Mon Nov 17, 2008 10:18 am

Insurance Quote System

Post by Sjwdavies »

Hi guys.

I'm building an insurance quote system.

It's going to be object orientated but don't want to store the object in the session. So what do you think is the best way to store my information in the database?

Say for example, I store all data when you submit each page - so 4 database inserts. What happens if the user gives up at page 2? I'd have 'incomplete' data in my database? (I could just setup a cron job to clear quotes that have been created but not completed)

What are your thoughts/design approaches?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Insurance Quote System

Post by Jonah Bron »

Why don't you want to store it in the session? Yes, you're correct: if you store it in the database you'll need to add a timestamp column, and run over the database regularly with a cron job to clear out old stuff.
Sjwdavies
Forum Commoner
Posts: 25
Joined: Mon Nov 17, 2008 10:18 am

Re: Insurance Quote System

Post by Sjwdavies »

Jonah Bron wrote:Why don't you want to store it in the session? Yes, you're correct: if you store it in the database you'll need to add a timestamp column, and run over the database regularly with a cron job to clear out old stuff.
I've used and abused sessions before so I suppose the question is really, what should you store in a session?

A pro of non-session based quoting (maybe storing it as an encrypted string in the URL) means a) The quote wouldn't time out and b) You could use the systems to do multiple quotes at the same time (no session variables would get overwritten)

The idea for this project was to store say the quote id in the URL, then make a call to the database when I need to either get info or add it. On the top of page two for example, instantiate my object, recall insert data, populate what I need, then destroy the object.

I could store the object in a session, so I only need create it once, and have done this before. Only thing is the size of te object and it can become large and messy.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Insurance Quote System

Post by Jonah Bron »

Sjwdavies wrote:a) The quote wouldn't time out and
True. If that's a feature you want, then store it in a database.
Sjwdavies wrote:b) You could use the systems to do multiple quotes at the same time (no session variables would get overwritten)
Actually, no. You would have to somehow identify which quote goes with which window the user has up. It wouldn't work.
Sjwdavies wrote:I could store the object in a session, so I only need create it once, and have done this before. Only thing is the size of te object and it can become large and messy.
I'm pretty sure size doesn't matter with sessions, as it's not being stored on the client.
Sjwdavies
Forum Commoner
Posts: 25
Joined: Mon Nov 17, 2008 10:18 am

Re: Insurance Quote System

Post by Sjwdavies »

Jonah Bron wrote:
Sjwdavies wrote:b) You could use the systems to do multiple quotes at the same time (no session variables would get overwritten)
Actually, no. You would have to somehow identify which quote goes with which window the user has up. It wouldn't work.
I'd encrypt the quote id and include it in the $_GET variable.
Jonah Bron wrote:
Sjwdavies wrote:I could store the object in a session, so I only need create it once, and have done this before. Only thing is the size of te object and it can become large and messy.
I'm pretty sure size doesn't matter with sessions, as it's not being stored on the client.
I know that but it's the size of space on the server I'm thinking of here. It's not going to be basics but I want to demonstrate awareness and the implications of my coding on the server resources.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Insurance Quote System

Post by Jonah Bron »

Sjwdavies wrote:I'd encrypt the quote id and include it in the $_GET variable.
That would work, but the user wouldn't be able to refresh or anything...
Sjwdavies wrote:I know that but it's the size of space on the server I'm thinking of here. It's not going to be basics but I want to demonstrate awareness and the implications of my coding on the server resources.
If it can fit in the database, it can fit in the session. How big are we talking here?
Sjwdavies
Forum Commoner
Posts: 25
Joined: Mon Nov 17, 2008 10:18 am

Re: Insurance Quote System

Post by Sjwdavies »

Jonah Bron wrote:
Sjwdavies wrote:I'd encrypt the quote id and include it in the $_GET variable.
That would work, but the user wouldn't be able to refresh or anything...
Ofcourse you can, you don't lose $_GET variables when you refresh a page. It'd look something like 'quote.php?id=gdjskcjhsbdujjfbsvhcofbe
Jonah Bron wrote:
Sjwdavies wrote:I know that but it's the size of space on the server I'm thinking of here. It's not going to be basics but I want to demonstrate awareness and the implications of my coding on the server resources.
If it can fit in the database, it can fit in the session. How big are we talking here?
We are just talkin small values, but when you store an object as a session variable doesn't it store all the methods in the session object too?
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Insurance Quote System

Post by Jonah Bron »

Sjwdavies wrote:Ofcourse you can, you don't lose $_GET variables when you refresh a page. It'd look something like 'quote.php?id=gdjskcjhsbdujjfbsvhcofbe
Oh yeah, duh. I was thinking post. :roll:
Sjwdavies wrote:We are just talkin small values, but when you store an object as a session variable doesn't it store all the methods in the session object too?
Um, I don't think so, but I really don't know for sure. You could transfer them over to associative arrays for storage anyway though... just create a method for your class called "serialize", and have it return an array containing all of it's properties. And of course one called "deserialize" to do the opposite.
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: Insurance Quote System

Post by Jonah Bron »

This Stackoverflow answer here implies that it doesn't store the class, just it's data.

http://stackoverflow.com/questions/132197

That means you don't need the serialize/deserialize methods.
Post Reply