You're not the first person to worry about this, and it can be a serious problem.
But fortunately the database and PHP designers also saw this problem and they tackled it.
There are a few things you need to have
clear in your mind.
- Each script that runs requires it's own database connection. Two scripts that run at the same time cannot use the same connection at the same time.
If you run 100 scripts at the same time, you will need 100 connections. Those connections may use the same credentials to login, but they are seperate connections.
If you try to open two connections with the same credentials inside one script, then PHP will simply return a pointer to the first connection without actually creating a new databse connection. (sad but true).
Pconnect simply doesn't close the connections after the script ends. So if you run two scripts after eachother, the second script will get to use the exact same connection that the first script was using.
This is where a transaction problem could arise, if it weren't for the fact that the people who designed PHP and the database API thought of this. At least for postgreSQL, you cannot open a transaction in one script, exit the script, open the same connection in the next script, and commit or rollback. The PHP/the API should prevent this by 'resetting' (or whatever) the connection when your script exits. ANy open transactions are rolled back. But this is what you should test with a real script.
MySQL has a small 'problem' with persistant connections, in that you can insert a record in one script, and retreive the mysql_insert_id() in another. Not a big deal, but still...
"the only problem i need to solve is to make sure that every user accessing my www has a new, its own connection... (because of transactions)."
This is true. Scipts can only re-use connections once they are free. Once a script decides to use a connection, that connection is reserved for that script untill the script exits.
One connection can be used by one script at a time.
And remember, you cannot tell PHP which database connection to use, you can only request 'a' connection. So you cannot open a persistant connection called 'X', open a transaction, close the script, start a new script, use the same 'X' connection (which should be open because of pconnect) and commit. PHP simply does not let you choose the exact same connection, only 'a' connection with the same credentials.
few... so much typing so early in the morning...
A forum, a FAQ, what else do you need?