omg
omg

Reputation: 139842

What's the correct way to reuse connections in case of PHP and MySQL?

I've tried restoring connections in $_SESSION,

but can only reuse for one user.

Any better solutions?

Upvotes: 0

Views: 1602

Answers (3)

Havenard
Havenard

Reputation: 27854

Read about mysql_pconnect().

Unfortunately, persistent connection is not stable in PDO and not supported by MySQLi.

Persistent connections save time when the database server is not in the localhost, but if it is, use of persistent connections is practically irrelevant.

Upvotes: 5

nont
nont

Reputation: 9519

use mysql_pconnect rather than mysql_connect

Upvotes: 1

ryeguy
ryeguy

Reputation: 66851

What do you mean be "reuse connections"? A connection is a socket being opened to the server..of course you can't store it in $_SESSION. It still would have to reconnect, so it would be pointless anyways. The closest you can come to it is persistent connections.

Upvotes: 5

Related Questions