PDO: Switch database user without reopening connection



I want to add a feature to a project I'm working on where i have
multiple users set up on my Postgres database with varying levels of
access. At the bare minimum there will be a login user who only has
read access to the users table so that users can log in. Once a user
has been logged in successfully I want to escalate that user's access
level to one appropriate to their role, which will include switching
the postgres user they are logged in as to one that can make
modifications to the database as well (editors get update permission,
supereditors get insert/delete permission for articles, admin get
insert/delete access on the user database etc).

The problem is the only way I can find of doing this is to close the
open PDO and create a new one, in other words disconnect from the
database and reconnect. As database connections are expensive to
initialize I really want to avoid this and do the postgres of an su
instead.

Back when I was doing this the old fashioned way (php 4, MySQL, MySQL
extension, no OOP) I could use mysql_change_user () to switch DB users
once a logging in user's credentials had been validated. PDO is a
great new addition to PHP and has so many excellent new features that
there's really little excuse not to use it, but one thing it
apparently lacks is a PDO equivalent to the old mysql_change_user
command.

I'm pretty sure that user switching is supported in Postgres, but with
no change_user function how do I go about doing it?
.



Relevant Pages

  • Re: PDO: Switch database user without reopening connection
    ... multiple users set up on my Postgres database with varying levels of ... level to one appropriate to their role, which will include switching ... the postgres user they are logged in as to one that can make ... modifications to the database as well (editors get update permission, ...
    (comp.lang.php)
  • Re: PostgreSQL setup and use
    ... So now I have it installed and I try to create a database using ... I'm logged in as bpepers and just do "createdb foo" on the ... The pg_hba.conf is using "ident ... run createuser as postgres. ...
    (Fedora)
  • Re: Postgres PL/Python
    ... > I wonder if anyone on this list is using Python as Postgres ... It sounds like I have the whole Python ... code between database and clients when the clients are written in Python ...
    (comp.lang.python)
  • Re: Postrgres data restoration problem (which NG to post to?)
    ... I could not find a postgres group, nor a linux database group. ... what format is the backup in: is it a copy of the database ... Then, use psql to connect to template1, then restore the backup as ...
    (comp.os.linux.development.apps)
  • Re: PDO: Switch database user without reopening connection
    ... multiple users set up on my Postgres database with varying levels of ... the postgres user they are logged in as to one that can make ... modifications to the database as well (editors get update permission, ... Unless you are using persistent connections, there is not much use in changing. ...
    (comp.lang.php)