[PHP] mysql_close() and mysql_free_result() don't seem to work in PHP 4.3.4 or 5.0.1. A bug?

2004-08-29 Thread William
Since posting the original copy of this message -- which, in 10 hours, never appeared 
on this newsgroup -- I upgraded
from PHP version 4.3.4 to 5.0.1.  Unfortunately, the same exact problem persists.  I'm 
starting to believe this is a bug
in PHP's MySQL memory management functions.

Original Post:
-
I've set up several tests to try to find some way to get the mysql_close() function to 
work without throwing warning:

 Warning: mysql_close(): ## is not a valid MySQL-Link resource
(where ## is some number like 18 or 39)

The most robust form of these tests involves a database connection management class.  
The entirety of the class code is
too large to post here, but these two methods should illustrate the management of the 
MySQL connection handle (there is a
class property called hndConnection):

===CODE===
 function openDatabase() {
  $bvStatus = false;

  // Close any open connection.
  $this-closeDatabase();

  // Attempt to establish a connection to the target database host.
  $this-hndConnection = mysql_connect($this-DATA_HOSTNAME, $this-DATA_USER, 
$this-DATA_PASSWORD);
  if (0  $this-hndConnection) {
   // Connection succeeded; access the target database;
   if (mysql_select_db($this-DATA_DATABASE, $this-hndConnection)) {
$this-bConnected = true;
$bvStatus = true;
   } else {
// Database selection failed; purge the database host connection.
$this-closeDatabase();
   }
  } else {
   // Connection failed; purge the handle.
   $this-hndConnection = NULL;
  }

  return ($bvStatus);
 }

 function closeDatabase() {
  $bvStatus = false;

  if ($this-isConnected()) {
   // Connected; try to close the connection.
   if (mysql_close($this-hndConnection)) {
// Close attempt succeeded.
$this-bConnected = false;
$this-hndConnection = NULL;
$bvStatus = true;
   } else {
// Close attempt failed.
$bvStatus = false;
   }
  } else {
   // No open connection; close was successful.  Be sure the connection handle is 
purged.
   $bvStatus = true;
   $this-hndConnection = NULL;
  }

  return ($bvStatus);
 }
===/CODE===

As you can imagine, openDatabase() works just fine.  I am able to use the open MySQL 
connection in all its facets.
However, when it comes time to close the connection, closeDatabase() fails with the 
above-stated PHP Warning.

As for mysql_free_result(), I get the same type of PHP Warning when I try to run a 
query and dump the results.  For
example, I get another PHP Warning complaining about not a valid MySQL-Link resource 
when I try to ($hndResult brings
the same Warning from mysql_free_result(), even though -- as you can see -- it is 
clearly being used just like the PHP
documentation advises):

===CODE===
 function runQuery($szQuery) {
  $ivRecordCount = -1;
  $bvSelectQuery = false;
  $hndResult = 0;

  // Identify whether the current query is a SELECT statement (or empty).
  if (0  strlen($szQuery)) {
$bvSelectQuery = stristr(substr(ltrim($szQuery), 0, 6), SELECT);

   // Open the database connection if it is closed; proceed only with a valid 
connection.
   if ($this-ensureConnection()) {
// Run the query.
$hndResult = mysql_query($szQuery, $this-getConnectionHandle());

// Check to see whether the query succeeded.
if ($hndResult) {
 if ($bvSelectQuery) {
  $ivRecordCount = mysql_num_rows($hndResult);
 } else {
  $ivRecordCount = mysql_affected_rows($this-getConnectionHandle());
 }

 // Purge memory used by this query.
 mysql_free_result($hndResult);
}
   }
  }

  return ($ivRecordCount);
 }

===/CODE===

As you can see in this later method, the result handle is created and used only within 
several lines of code of each
other, yet, the resource is already invalid by the time I try to use it.  What's up?  
Naturally, the concept of these
code samples came right out of PHP's documentation, yet they don't work.  Can anyone 
illustrate a workaround to use these
two mysql_* functions successfully?

Incidentally, please don't waste time preaching about these functions not needed 
because all resources are closed at the
end of the script's life.  My programming philosophy differs from such a lazy 
approach, and I will not humor it.  Please
limit replies to constructive workarounds.

Thanks!

-- 
William Kimball, Jr.
Programming is an art-form that fights back!

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



Re: [PHP] mysql_close() and mysql_free_result() don't seem to work in PHP 4.3.4 or 5.0.1. A bug?

2004-08-29 Thread John Nichel
William wrote:
Since posting the original copy of this message -- which, in 10 hours, never appeared 
on this newsgroup -- I upgraded
from PHP version 4.3.4 to 5.0.1.  Unfortunately, the same exact problem persists.  I'm 
starting to believe this is a bug
in PHP's MySQL memory management functions.
Original Post:
-
I've set up several tests to try to find some way to get the mysql_close() function to 
work without throwing warning:
 Warning: mysql_close(): ## is not a valid MySQL-Link resource
(where ## is some number like 18 or 39)
snip
@mysql_close();
--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] mysql_close() and mysql_free_result() don't seem to work in PHP 4.3.4 or 5.0.1. A bug?

2004-08-29 Thread William
I can accept that as a workaround, but I was hoping to do more than merely mute the 
warnings.  Is there a way to truly
use the connection and result set handles?  Can PHP truly utilize it's own connection 
resource handles in code?

Bottom Line:  This is going to make a real mess when multiple database connections 
need to be used and when multiple
query results need to be managed simultaneously.

-- 

-- 
William Kimball, Jr.
Programming is an art-form that fights back!

John Nichel [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
: William wrote:
:
:  Since posting the original copy of this message -- which, in 10 hours, never 
appeared on this newsgroup -- I upgraded
:  from PHP version 4.3.4 to 5.0.1.  Unfortunately, the same exact problem persists.  
I'm starting to believe this is a
bug
:  in PHP's MySQL memory management functions.
: 
:  Original Post:
:  -
:  I've set up several tests to try to find some way to get the mysql_close() 
function to work without throwing warning:
: 
:   Warning: mysql_close(): ## is not a valid MySQL-Link resource
:  (where ## is some number like 18 or 39)
: snip
:
: @mysql_close();
:
: -- 
: By-Tor.com
: It's all about the Rush
: http://www.by-tor.com

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



Re: [PHP] mysql_close() and mysql_free_result() don't seem to work in PHP 4.3.4 or 5.0.1. A bug?

2004-08-29 Thread John Nichel
William wrote:
I can accept that as a workaround, but I was hoping to do more than merely mute the 
warnings.  Is there a way to truly
use the connection and result set handles?  Can PHP truly utilize it's own connection 
resource handles in code?
Bottom Line:  This is going to make a real mess when multiple database connections 
need to be used and when multiple
query results need to be managed simultaneously.
mysql_close and mysql_free_result work fine for me in 4.3.4 and higher 
as long as you pass it a valid resource, using multiple connections, and 
multiple result sets.  Well, you don't have to pass mysql_close a 
resource at all, but if you do, it *has* to be valid.  The only time I 
see the error you described in the original message was when I don't 
pass a valid resource.

--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] mysql_close() and mysql_free_result() don't seem to work in PHP 4.3.4 or 5.0.1. A bug?

2004-08-29 Thread William
If you read the code I posted, you'd see that I am sending valid resources.  :)  As I 
explained, I lifted the technique
directly from the PHP documentation.  Now, if you can see a bug in my implementation 
of this technique, by all means,
please point it out.

-- 

-- 
William Kimball, Jr.
Programming is an art-form that fights back!

John Nichel [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
: William wrote:
:
:  I can accept that as a workaround, but I was hoping to do more than merely mute 
the warnings.  Is there a way to
truly
:  use the connection and result set handles?  Can PHP truly utilize it's own 
connection resource handles in code?
: 
:  Bottom Line:  This is going to make a real mess when multiple database connections 
need to be used and when multiple
:  query results need to be managed simultaneously.
: 
:
: mysql_close and mysql_free_result work fine for me in 4.3.4 and higher
: as long as you pass it a valid resource, using multiple connections, and
: multiple result sets.  Well, you don't have to pass mysql_close a
: resource at all, but if you do, it *has* to be valid.  The only time I
: see the error you described in the original message was when I don't
: pass a valid resource.
:
: -- 
: By-Tor.com
: It's all about the Rush
: http://www.by-tor.com

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



Re: [PHP] mysql_close() and mysql_free_result() don't seem to work in PHP 4.3.4 or 5.0.1. A bug?

2004-08-29 Thread John Nichel
William wrote:
If you read the code I posted, you'd see that I am sending valid resources.  :)  As I 
explained, I lifted the technique
directly from the PHP documentation.  Now, if you can see a bug in my implementation 
of this technique, by all means,
please point it out.
Please limit replies to constructive workarounds.
Well, since you *know* that all your resources are valid, why don't you 
echo out mysql_error() after you make a mysql function call. 
Constructive enough for you?

--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] mysql_close() and mysql_free_result() don't seem to work in PHP 4.3.4 or 5.0.1. A bug?

2004-08-29 Thread William
Why waste time by turning this into an attack?  (A rhetorical question, please don't 
bother addressing it.)

I'm pressing for a better answer now because the workaround you posted simply ignores 
the problem and because you implied
that you got these functions to work -- presumably without having to mute warnings 
(otherwise, your solution is faulted).
Just take a few minutes of your valuable time to read the code I posted.  I challenge 
you to find fault with my
management of the resource handles.  In the end, we may both be better programmers.

-- 
William Kimball, Jr.
Programming is an art-form that fights back!

John Nichel [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
: William wrote:
:
:  If you read the code I posted, you'd see that I am sending valid resources.  :)  
As I explained, I lifted the
technique
:  directly from the PHP documentation.  Now, if you can see a bug in my 
implementation of this technique, by all means,
:  please point it out.
: 
:
: Please limit replies to constructive workarounds.
:
: Well, since you *know* that all your resources are valid, why don't you
: echo out mysql_error() after you make a mysql function call.
: Constructive enough for you?
:
: -- 
: By-Tor.com
: It's all about the Rush
: http://www.by-tor.com

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



Re: [PHP] mysql_close() and mysql_free_result() don't seem to work in PHP 4.3.4 or 5.0.1. A bug?

2004-08-29 Thread John Holmes
William wrote:
Why waste time by turning this into an attack?  (A rhetorical question, please don't 
bother addressing it.)
I'm pressing for a better answer now because the workaround you posted simply ignores 
the problem and because you implied
that you got these functions to work -- presumably without having to mute warnings 
(otherwise, your solution is faulted).
Just take a few minutes of your valuable time to read the code I posted.  I challenge 
you to find fault with my
management of the resource handles.  In the end, we may both be better programmers.
Programming languages do not make things up. If you say 
mysql_close($anyvariable) and PHP says that $anyvariable is not a MySQL 
connection resource, then it's not.

No, it's not. Shh. It's not.
If you can reduce what you're seeing to the smallest amount of code 
possible and still reproduce this problem, then maybe it's a bug. I have 
5.0.0 installed and will install 5.0.1 just for you if you can give me 
the smallest amount of code that reproduces this problem to help you 
test. Otherwise, use @ and turn a blind eye... ;)

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
php|architect: The Magazine for PHP Professionals  www.phparch.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] mysql_close() and mysql_free_result() don't seem to work in PHP 4.3.4 or 5.0.1. A bug?

2004-08-29 Thread John Nichel
William wrote:
Why waste time by turning this into an attack?  (A rhetorical question, please don't 
bother addressing it.)
I'm pressing for a better answer now because the workaround you posted simply ignores 
the problem and because you implied
that you got these functions to work -- presumably without having to mute warnings 
(otherwise, your solution is faulted).
Just take a few minutes of your valuable time to read the code I posted.  I challenge 
you to find fault with my
management of the resource handles.  In the end, we may both be better programmers.
Go 'challenge' someone else.  I gave you a 'constructive workaround', 
you didn't like it.  I gave you the non-'lazy approach' to help you find 
your problem, but you want to take the 'lazy approach' and 'challenge' 
us to find it for you.

It's really simple.  If the php mysql functions tell you it's not a 
valid link, then it isn't; no matter what you think it is or isn't.  Use 
mysql_error, break down sections of your code, ensure that you're 
getting back/passing data that you think you are, and track the problem 
down.  That's how to become a better programmer.

--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] mysql_close() and mysql_free_result() don't seem to work in PHP 4.3.4 or 5.0.1. A bug?

2004-08-29 Thread John Nichel
John Holmes wrote:
Programming languages do not make things up. If you say 
mysql_close($anyvariable) and PHP says that $anyvariable is not a MySQL 
connection resource, then it's not.

No, it's not. Shh. It's not.
If you can reduce what you're seeing to the smallest amount of code 
possible and still reproduce this problem, then maybe it's a bug. I have 
5.0.0 installed and will install 5.0.1 just for you if you can give me 
the smallest amount of code that reproduces this problem to help you 
test. Otherwise, use @ and turn a blind eye... ;)

...and what the hell is up with the clock on your computer, John?!?!  ;)
--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] mysql_close() and mysql_free_result() don't seem to work in PHP 4.3.4 or 5.0.1. A bug?

2004-08-29 Thread William
The problem turned out to be a run-time bug with object instances (of the same class) 
stepping on each other.  More
specifically, PHP doesn't seem to differentiate between a flat script-level $ovConn 
object and a new instance of $ovConn
that gets fired up in an unrelated object's method at run-time.  When the latter 
object unloads, both instances of
$ovConn lose their database connection resource handles.  I have determined this 
through extensive debug logging through
tracing all method calls.  I will troubleshoot this further and try to find a way to 
get PHP to separate the two
instances of $ovConn so one doesn't kill the other's resource handle.

Please keep your responses professional; this newsgroup/list is the first contact for 
people needing help with PHP -- 
even if it's their own fault.  Your enflamed, emotionally charged reactions help no 
one and seem only to serve your own
ego.  This matter is closed.  Good day.

-- 

-- 
William Kimball, Jr.
Programming is an art-form that fights back!

John Nichel [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED]
: William wrote:
:
:  Why waste time by turning this into an attack?  (A rhetorical question, please 
don't bother addressing it.)
: 
:  I'm pressing for a better answer now because the workaround you posted simply 
ignores the problem and because you
implied
:  that you got these functions to work -- presumably without having to mute warnings 
(otherwise, your solution is
faulted).
:  Just take a few minutes of your valuable time to read the code I posted.  I 
challenge you to find fault with my
:  management of the resource handles.  In the end, we may both be better programmers.
: 
:
: Go 'challenge' someone else.  I gave you a 'constructive workaround',
: you didn't like it.  I gave you the non-'lazy approach' to help you find
: your problem, but you want to take the 'lazy approach' and 'challenge'
: us to find it for you.
:
: It's really simple.  If the php mysql functions tell you it's not a
: valid link, then it isn't; no matter what you think it is or isn't.  Use
: mysql_error, break down sections of your code, ensure that you're
: getting back/passing data that you think you are, and track the problem
: down.  That's how to become a better programmer.
:
: -- 
: By-Tor.com
: It's all about the Rush
: http://www.by-tor.com

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



Re: [PHP] mysql_close() and mysql_free_result() don't seem to work in PHP 4.3.4 or 5.0.1. A bug?

2004-08-29 Thread John Nichel
William wrote:
snip
Please keep your responses professional; this newsgroup/list is the first contact for people needing help with PHP -- 
even if it's their own fault.  Your enflamed, emotionally charged reactions help no one and seem only to serve your own
ego.  This matter is closed.  Good day.
When you ask a question of this list, or any list for that matter, and 
end it with...

Incidentally, please don't waste time preaching about 'these functions 
not needed because all resources are closed at the end of the script's 
life'.  My programming philosophy differs from such a lazy approach, and 
I will not humor it.  Please limit replies to constructive workarounds.

...calling those who differ from you lazy, and assuming that there are 
some on here who aren't going to be constructive...you get what you get.

http://www.catb.org/~esr/faqs/smart-questions.html
--
By-Tor.com
It's all about the Rush
http://www.by-tor.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php