Page 1 of 1
Insurance Quote System
Posted: Tue Jan 18, 2011 11:49 am
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?
Re: Insurance Quote System
Posted: Tue Jan 18, 2011 11:59 am
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.
Re: Insurance Quote System
Posted: Tue Jan 18, 2011 1:51 pm
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.
Re: Insurance Quote System
Posted: Tue Jan 18, 2011 3:16 pm
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.
Re: Insurance Quote System
Posted: Tue Jan 18, 2011 4:22 pm
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.
Re: Insurance Quote System
Posted: Tue Jan 18, 2011 4:33 pm
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?
Re: Insurance Quote System
Posted: Tue Jan 18, 2011 4:37 pm
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?
Re: Insurance Quote System
Posted: Tue Jan 18, 2011 5:00 pm
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.
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.
Re: Insurance Quote System
Posted: Tue Jan 18, 2011 5:06 pm
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.