With persistent connections, you actually have to have the mysql_pconnect statement in each script you want to use the connection in. The function will use an already-existing connection if one is available. If no existing connection could be found, it will initiate the link.

The manual at php.net says this as well: "First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection."

Joachim

Rich wrote:
How can I establish a connection with a MySQL database and have it persist
accross multiple script files?

I've found the mysql_pconnect() function but this doesn't seem to do the job
- which is fairly logical actually because the connection is stored in a
variable:

$connect = mysql_pconnect();

and that variable $connection won't be available in another script.

I would have thought there would be a straightforward answer to this as it
seems that its someting which must be done fairly regularly.

The only workaround I can think of is sending the username, password and
database name to every script.  But how would you do this securely?

When establishing the initial connection I got the username and password
from a form which used the method="POST" method.

But if I want to have a link to a script, say 'add_item.php', how can I do
it securely?

<a href="add_item.php?username=<? echo($_POST['username']): ?>&password=<?
echo($_POST['password']): ?>&..."></a>

would not use the POST method.

I could use forms for every link but this seems ridiculously
over-complicated!

Thanks in advance for any pointers!

Richard.

-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to