Connect to the DB second time with different rights - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Connect to the DB second time with different rights (/showthread.php?tid=23592) |
Connect to the DB second time with different rights - El Forum - 10-15-2009 [eluser]Volder[/eluser] I have a site where I have the following logic: if the user is authorized - I connect to DB with 'logged_user' profile, otherwise I connect as 'guest'. Of course, the difference is in rights, e.g. 'guest' can not delete records from tables etc. I was using Native session library and I was deciding which user to connect depending on session variable 'logged_in'. Then I have updated to using codeigniters session library with database usage. So now I have the problem that before I could understand with which role to connect to database - I need to know whether user is logged in or on. And this could be understood from session variables. But for retrieving them I need to establish a connection first. So it looks like a circle. Is it possible to connect to DB with simple role which may only erase records from ci_sessions table. And then reconnect with another user role? In the docs there is a reconnect() method - but it is not used with a parameter. What would you suggest in my case? thanks. Connect to the DB second time with different rights - El Forum - 10-15-2009 [eluser]CroNiX[/eluser] The first thing that popped into my head was to create additional connections in the database. Then just check the user permissions and use the appropriate db connection. Code: <?php Connect to the DB second time with different rights - El Forum - 10-15-2009 [eluser]Volder[/eluser] I do have several connection types parametrized in DB config file. The problem is that before I reach my controller - I am already connected to database by Session library. And when I try to connect to DB with needed user - the statement is just ignored, because I am already connected. |