Sessions seems to kill db connection

Sessions seems to kill db connection

am 22.10.2009 17:51:56 von Kim Madsen

Hi PHPeople

I have an odd problem at my new work and wonder if it's some sort of odd
setup that is causing this problem when using sessions:

if($test) {
$query = "SELECT count(*) FROM articles WHERE group1 = 'fp'";# AND
group2 = 'login'";
$r = mysql_query($query) or die('Db error: ' . mysql_error() .
'

'.$SQL);
print "There´s " . mysql_num_rows($r) . " rows"; // 3 rows
print "session: " . $_SESSION['login']['uid']; // 1234
exit;
}
else {
if($_SESSION['login']['uid']) {
$query = "SELECT count(*) FROM articles WHERE group1 = 'fp'";# AND
group2 = 'login'";
$r = mysql_query($query) or die('Db error: ' . mysql_error() .
'

'.$SQL);
print "There´s " . mysql_num_rows($r) . " rows";
}
}

if $test is true it´s okay, if it´s false, this error occurs:

Db error: Access denied for user 'www-data'@'localhost' (using password: NO)

WTF? I´m not using a user called www-data for MySQL connections, but
apache runs as this user.

I've outcommented and login = to exclude a collision in variables (if
register globals is on, haven't checked that yet)

Anyone seen this wierd behaviour and know a solution or someway to
test/debug this?

--
Kind regards
Kim Emax



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

Re: Sessions seems to kill db connection

am 23.10.2009 21:00:45 von Kim Madsen

Kim Madsen wrote on 2009-10-22 17:51:
> Hi PHPeople
>
> I have an odd problem at my new work and wonder if it's some sort of odd
> setup that is causing this problem when using sessions:

Like I said, my new work and odd setup, an include file had a
mysql_close() in the bottom

Speaking of mysql_close(), I think I've read somewhere that in PHP6 a db
connection will not be closed, when the script is done. Is this true?
Cause then it would definetly be best practice to to _always_ have a
mysql_close() in the end for the main file.

--
Kind regards
Kim Emax - masterminds.dk

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

Re: Sessions seems to kill db connection

am 24.10.2009 07:27:40 von kranthi

>> Db error: Access denied for user 'www-data'@'localhost' (using password:=
NO)

>> WTF? I=B4m not using a user called www-data for MySQL connections, but a=
pache runs as this user

in the case where $test is true there is an open mysql connection, but
when $test is false there is no open connection is available. may be
you have opened a connection when $test is true or used a
mysql_close() when $test is false or when $_SESSION['login']['uid'] is
set.

regarding www-data, when mysql_query() fails to find a valid MySql
connection, it tries to open a new connection with mysql.default_user
and mysql.default_password (u can see these values trough phpinfo());
http://php.net/manual/en/function.mysql-connect.php

this used to be the behavior earlier, seems it was changed from PHP > 5.3.0

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

Re: Sessions seems to kill db connection

am 24.10.2009 10:28:27 von Kim Madsen

Hi Kranthi

kranthi wrote on 2009-10-24 07:27:
>>> Db error: Access denied for user 'www-data'@'localhost' (using password: NO)
>
>>> WTF? I´m not using a user called www-data for MySQL connections, but apache runs as this user
>
> in the case where $test is true there is an open mysql connection, but
> when $test is false there is no open connection is available. may be
> you have opened a connection when $test is true or used a
> mysql_close() when $test is false or when $_SESSION['login']['uid'] is
> set.

I think you missed my words about resolving the matter, when you were
cutting the quoted text :-)

> regarding www-data, when mysql_query() fails to find a valid MySql
> connection, it tries to open a new connection with mysql.default_user
> and mysql.default_password (u can see these values trough phpinfo());
> http://php.net/manual/en/function.mysql-connect.php

Thanks, that explained the www-data user

--
Kind regards
Kim Emax - masterminds.dk

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