php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #29645 How can we test mysql connection is already established or not?
Submitted: 2004-08-13 09:26 UTC Modified: 2004-08-24 14:32 UTC
From: sivalsm at yahoo dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.0.1 OS: Linux
Private report: No CVE-ID: None
 [2004-08-13 09:26 UTC] sivalsm at yahoo dot com
Description:
------------
I think it will be great, if we had a database function to check whether database connection is already exist or not for a particular session.

Naturally we are using a common php file to connect to database and we are inclusing the file in every script.Anyway database connection will lost after completing the execution of the script.But we need to connect database again and again.

If there is a database function like mysql_isconnected, to check whether database connection  is already established or not...that will be helpful.

Expected result:
----------------
We can use mysql_pconnect to maintain persistancy in database connections.But it will take server resources to maintain persistancy.So if there is a seperate mechanism to check the database connection it will be better.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-17 12:50 UTC] tony2001@php.net
Could you please explain what and why do you need?
mysql_connect & friends doesn't establish new connection, if a connection with the same parameters was established before in this script.

 [2004-08-24 14:15 UTC] sivalsm at yahoo dot com
Thank you for your reply.At this point of time no new connection will be established in the same script.But while i'm using mysql_connect in every script , then new connection will be established for every occurrance of mysql_connect.

What i'm thinking is by taking session_id and other database information ..the function should not prepare a new connection for the same parameters.So that only one connection will be available for a single session.

We need to check whether database connection is established or not?
 [2004-08-24 14:32 UTC] tony2001@php.net
No, it's impossible by design. You can't use the same connection in different requests unless you're using *_pconnect(). Read here: http://www.php.net/manual/en/features.persistent-connections.php about it.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 09:01:26 2024 UTC