2

I never used the persistent mysql_pconnect function only mysql_connect() but now I want to put the DB on its own server but was wondering if its safe for production or any issues/backups I should be aware of?

To clarify is there some failsafe/auto reconnect when the mysterious MySQL server gone away or other connection errors come up? or do I have to implement this myself?

Is last_insert_id() reliable for the correct connection? I read that it is (after some bug fixes) and there is no race condition but can someone who uses it for production verify?

Any other connection issues I should be aware of before I switch over in a production environment?

Do I need to implement some backup mysql_connect code? I do not want to 'discover' some server crashing bugs so any/all tips and info from experienced users is much appreciated

Filip Roséen - refp
  • 62,493
  • 20
  • 150
  • 196
  • 2
    Welcome to Stack Overflow! [Please, don't use `mysql_*` functions in new code](http://stackoverflow.com/q/12859942). They are no longer maintained and the deprecation process has begun, see the [red box](http://php.net/mysql-connect). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli); [this article](http://php.net/mysqlinfo.api.choosing) will help you decide which. If you choose PDO, [here is a good tutorial](http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers). – vascowhite Nov 04 '12 at 08:33
  • why you're not using `mysqli`? I guess you don't need persistent connection anymore with mysqli ... – Mahdi Nov 04 '12 at 08:59
  • Thanks for your recommendation but I am interested in mysql_pconnect() functions, as long as my version includes a stable version of mysql_connect() / mysql_pconnect() I will use that. I do not like beta testing new functions and telling me to use another compatible framework is like recommending a 64bit system when 32 is sufficient for my needs. – user1797719 Nov 04 '12 at 10:48

1 Answers1

0

pconnect is a risky tool, mainly as it can be easy to run out of db connections. Using the mysql_connect function will take slightly longer, but since it drops the connection at the end of the script it is much safer. Using pconnect drops the connections into a pool for reuse which is fine, but as soon as you raise the number of workers (for example, due to a larger number of requests to your site) then you're better off switching to mysql_connect() to prevent hitting the max_connection limit on your db server.

Andrew McGrath
  • 106
  • 1
  • 5