PostreSQL: passing a connection resource

Do you have questions regarding other database enginges (not MySQL) -- ask here!

Moderators: egami, macek, gesf

Post Reply
Monty51
New php-forum User
New php-forum User
Posts: 7
Joined: Mon Mar 12, 2018 9:26 am

Mon Apr 09, 2018 5:51 pm

Thanks for taking the time to read this.

I'm new to PHP, PostgreSQL, and a host of other things as I try to convert an MS Access DB into a web-based application.

While working with PHP, I'm wondering if a connection resource, as is generated by pg_connect(), can be passed through structures like $_SESSION or maybe $_POST. I've not found information on this in the various books I'm reading. I'm trying to eliminate the need for another login when calling a new web page (and there are many that will be called).

Any thoughts or advice on the matter is appreciated.

Monty51

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 719
Joined: Mon Feb 22, 2016 5:52 pm

Tue Apr 10, 2018 6:49 am

I'm wondering if a connection resource, as is generated by pg_connect(), can be passed through structures like $_SESSION or maybe $_POST
No you can't, PHP loads up, executes your script then closes. This means that your pg_connect() closes and becomes redundant.

When a request comes from a users browser, a token is used to populate the $_SESSION variable, so whilst the information is stored on the server, you cannot easily access it without the correct token which is stored on the users browser either as a cookie or in the URL if cookies are disallowed by them. $_POST is sent from the browser and contains any information stored in a form, providing the user submits the form.

In other words, you will need to create a secure connection to your database on each and every visit from a user.

Monty51
New php-forum User
New php-forum User
Posts: 7
Joined: Mon Mar 12, 2018 9:26 am

Wed Apr 11, 2018 6:07 am

Thanks

User avatar
hyper
php-forum Fan User
php-forum Fan User
Posts: 719
Joined: Mon Feb 22, 2016 5:52 pm

Wed Apr 11, 2018 10:27 am

You're welcome :)

Post Reply