• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Active Record, DB Forge, and Database Session Data ... Oh My

Alright, the basics. I'm building an application that's supposed to be database agnostic, which means that the AR and DB Forge stuff is absolutely invaluable. I'm also going to be storing session data in the database through NGSession. However, today I've been working on taking my schema from paper to the application and I've run into an interesting issue.

When storing session data in the database, you've gotta create a table called ci_sessions. Excellent. Only problem is that my installation is running entirely through DB Forge, meaning that it appends the database prefix to all of the queries. That's no problem at all either, until you get to the config file and setting the table that session data is stored in. It's hard-coded as ci_sessions, but by going through DB Forge, the actual table created is dbprefix_ci_sessions. Since the config file is pulled before the database config file, I have no way of manually setting the prefix for the sessions table in config.php. On top of that, I wouldn't even know where to begin in hand-coding queries for anything besides MySQL. (Not to mention that it'd require some major refactoring of the install process, so I'd like to avoid that if at all possible.)

So, to all the CI experts out there, any ideas about getting around this little problem?

Have you considered setting an empty dbprefix?

$db['default']['dbprefix'] = "";

Unfortunately, the application needs the prefix because it needs the ability for multiple copies of it to be installed side-by-side and still maintain some independence in terms of the data its storing.

I guess that I could create some kind of DB prefix variable in the config file, but I'm not sure I like the idea of having to set that twice in two different files. Does it make sense to have a separate sessions config file with all those types of things or does the session stuff have to be done where it is for a reason?

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.