Re: [PHP-DB] connection id mystery
Charles Whitaker wrote: Using persistant connections simply means that you will be given a connection from a pool of open connections rather than creating a new one each time. There is no guarantee you'll get the same connection from request to request. Right. I had assumed that I would get a connection previously initiated by me, and that there would therefore be only one, so I would always get the same connection. So much for assumptions. I would suggest you add another field to the table you are trying to lock. Put an ID in there that you can pass from request to request. Use the locking feature to lock the table, read that value for a record, if it's not set to something write your ID to it then unlock it. If it does already contain an ID you treat it as locked. you just need to make sure you unlock the row when you're done (probably by setting that value to NULL. If you're already using sessions I would strongly recommend using the session ID as the lock ID. If not you can easily generate one but you'll need to pass it manually from request to request. I did as you suggest, and it seems to work fine. I surrounded the lock code with get_lock() and release_lock(), to make it quasi-atomic. Thanks for the suggestion, and thanks to Charles Morris as well for his response. No problem, but please include the list when replying in future. -Stut -- http://stut.net/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] connection id mystery
Charles Whitaker wrote: Since I'm requesting persistent connections, why don't I get the same connection each time? Or, to ask it another way: I notice that the number of threads slowly increases as I continue to access records -- why would this happen if I'm using persistent connections? I assumed that the first time I did 'new PDO' I'd create a connection, and each time after that I'd get the same connection. At least that's how I read the documentation. Using persistant connections simply means that you will be given a connection from a pool of open connections rather than creating a new one each time. There is no guarantee you'll get the same connection from request to request. Can anyone point me in the right direction? Thanks. I would suggest you add another field to the table you are trying to lock. Put an ID in there that you can pass from request to request. Use the locking feature to lock the table, read that value for a record, if it's not set to something write your ID to it then unlock it. If it does already contain an ID you treat it as locked. you just need to make sure you unlock the row when you're done (probably by setting that value to NULL. If you're already using sessions I would strongly recommend using the session ID as the lock ID. If not you can easily generate one but you'll need to pass it manually from request to request. That may not be as clean as a pure SQL solution, but it will work. You may also want to add a timestamp row to allow for a timeout on the lock. -Stut -- http://stut.net/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] connection id
Use persistent connections it's a matter of performance of your script. When you use persistent connections the next call to mysql_pconnect will catch a opened connection if available. The mysql_connect command always open a new connection which slower than get an opened one. Anyway you can't use the connection_id in other page. May be using PHP4 Sessions. HTH. Jayme. -Mensagem Original- De: andrie [EMAIL PROTECTED] Para: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Enviada em: sexta-feira, 23 de maro de 2001 20:38 Assunto: [PHP-DB] connection id Hello php mania, i was connecting into mysql using mysql_connect, and i just saved the return value from this funtion. now i want to use this connection id in the other page so i dont have to connect into mysql again. is it possible for me to do that ? anybody could tell me the different between persistence connection or not ? and how the implementation ? TIA -- Best regards, andrie mailto:[EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]