Check to see if connect already open
Moderator: General Moderators
Check to see if connect already open
Hey,
can anyone tell me how i can do a check to see if there is already a active connection to the mysql database?
Thx
can anyone tell me how i can do a check to see if there is already a active connection to the mysql database?
Thx
-
prasadharischandra
- Forum Commoner
- Posts: 57
- Joined: Thu May 09, 2002 2:19 am
- Location: sri lanka
- Contact:
uhh sorta..
Well that didnt reall work.
the mysql connect var is in a function in a file i include.
I have lots of mysql stuff through my site.
But dont want to use pconnect.
If anyway can advise me on a way of checking to see if connection is open would be great.
the mysql connect var is in a function in a file i include.
I have lots of mysql stuff through my site.
But dont want to use pconnect.
If anyway can advise me on a way of checking to see if connection is open would be great.
You could set a global variable to the result from the connect function, but this would be error prone. As far as I am aware a connection usually terminates as soon as the script has finished running, so using the same connection in another script could potentially fail.
The pconnect is probably your safest option if you really want to do this, why do you need to do this?
Mike
The pconnect is probably your safest option if you really want to do this, why do you need to do this?
Mike
Thx mikeq
it seems i my best answer will be persistent connections.
My site works like so
i have index.php
and it has my design layout
basically consists of 3 columns in a html table.
the left navigation (left col) is included and same with right,
For mine middle section (main content)
i use this
so all links are like so index.php?id=filename.
So in conclusion
All other the place i have mysql queries pulling data and displaying it in html from the database.
If i just add a line to index.php to connect and use pconnect it should be fine for the whole site?
it seems i my best answer will be persistent connections.
My site works like so
i have index.php
and it has my design layout
basically consists of 3 columns in a html table.
the left navigation (left col) is included and same with right,
For mine middle section (main content)
i use this
Code: Select all
if ($id == true)
{
include ("$id.php");
}
else
{
include ("main.php");
}So in conclusion
All other the place i have mysql queries pulling data and displaying it in html from the database.
If i just add a line to index.php to connect and use pconnect it should be fine for the whole site?
just test the resource variable name, like the first post suggested.
If you named them all the same, you shouldn't have a problem.
You can always just make the connection in the included file and, then, when it's included, you'll always have that connection.
If you open a connection in a PHP script, that only stays open as long as that script runs. Once it finishes, the connection is closed...
(Also, be careful with the include($file); line. Wouldn't want someone doing an index.php?id=/etc/passwd or something....)
If you named them all the same, you shouldn't have a problem.
You can always just make the connection in the included file and, then, when it's included, you'll always have that connection.
If you open a connection in a PHP script, that only stays open as long as that script runs. Once it finishes, the connection is closed...
(Also, be careful with the include($file); line. Wouldn't want someone doing an index.php?id=/etc/passwd or something....)
thx enygma
Yes,
I have sorted all the connection related problems.
But it seems i have just realised a new problem.
Just $id=filename
No ../bla/bla ...etc?
Any ideas
I have sorted all the connection related problems.
But it seems i have just realised a new problem.
Could there be a way of limiting the files it includes to say.(Also, be careful with the include($file); line. Wouldn't want someone doing an index.php?id=/etc/passwd or something....)
Just $id=filename
No ../bla/bla ...etc?
Any ideas
I think pHaZed was trying to open a connection on say his first script and still use the same resource id say 4 scripts later, which probably wouldn't work.enygma wrote:just test the resource variable name, like the first post suggested.
If you named them all the same, you shouldn't have a problem.
You can always just make the connection in the included file and, then, when it's included, you'll always have that connection.
If you open a connection in a PHP script, that only stays open as long as that script runs. Once it finishes, the connection is closed...
(Also, be careful with the include($file); line. Wouldn't want someone doing an index.php?id=/etc/passwd or something....)
Re: thx enygma
Did you say you keep your list of valid pages in your MySQL table, if so just do a check against your table to make sure it is a valid page.pHaZed wrote:Could there be a way of limiting the files it includes to say.
Just $id=filename
No ../bla/bla ...etc?
Any ideas
Mike