php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29019 Database not closing
Submitted: 2004-07-05 19:39 UTC Modified: 2004-07-05 21:36 UTC
From: cyberlot at cyberlot dot net Assigned: helly (profile)
Status: Closed Package: MySQL related
PHP Version: 5.0.0RC3 OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cyberlot at cyberlot dot net
New email:
PHP Version: OS:

 

 [2004-07-05 19:39 UTC] cyberlot at cyberlot dot net
Description:
------------
mysqli, using class interface not not closing connection at end of script unless you specificly call $mysqli->close

This is a change of behavior from the normal mysql extension which does not "require" you to close connection.

Reproduce code:
---------------
<?
$mysqli = new extend_mysqli('localhost','billing','billing','billing');
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
?>

Expected result:
----------------
Every time its run it should release the database connection

Actual result:
--------------
Each time you run it a new db connection is done until you max out the mysql server.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-07-05 19:51 UTC] cyberlot at cyberlot dot net
narrowed the problem down further, Its directly related to me trying to extend the mysqli class. If I take out the extend it closes properly, If I put in the extend with no functions at all it does not close properly

So
<?
$mysqli = new extend_mysqli('localhost','billing','billing','billing');
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
?>
Connection does not close properly
<?
$mysqli = new mysqli('localhost','billing','billing','billing');
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}
?>
Connection does close properly.
 [2004-07-05 20:24 UTC] cyberlot at cyberlot dot net
My C more then sucks so excuse me for even trying..

in mysqli.c intern->zo.ce = class_type;

intern->zo.ce is only used 4 places in mysqli.c
1. When you assign it
2. stmt and result entrys, not changed my extending the class
3. line 135, when closing the object, In this same statement you also run mysql_close.

This if statement is returning false because
intern->zo.ce == mysqli_link_class_entry is wrong, by extending the class I have changed the class type therefore breaking the closing of the object.

I hope this helps fix the problem
 [2004-07-05 20:49 UTC] helly@php.net
No your analysis looks correct.
Try the following patch:
diff -u -p -d -r1.41 mysqli.c
--- ext/mysqli/mysqli.c 23 Jun 2004 16:47:25 -0000      1.41
+++ ext/mysqli/mysqli.c 5 Jul 2004 18:48:51 -0000
@@ -132,7 +132,7 @@ static void mysqli_objects_free_storage(
        FREE_HASHTABLE(intern->zo.properties);

        /* link object */
-       if (intern->zo.ce == mysqli_link_class_entry) {
+       if (instanceof_function(intern->zo.ce, mysqli_link_class_entry TSRMLS_CC)) {
                if (my_res && my_res->ptr) {
                        MY_MYSQL *mysql = (MY_MYSQL *)my_res->ptr;

 [2004-07-05 21:06 UTC] cyberlot at cyberlot dot net
Thanks, maybe I should pull out some C books and try to help out more...

Anyway that patch worked, sprinkle some pixie dust on it or what ever you do and send it on its way.
 [2004-07-05 21:14 UTC] cyberlot at cyberlot dot net
Not the right place for this but thought I would mention it so you could pass it on.

If class_type changes when you extend then using that in a class at all might cause a problem??

Did a quick scan and found the following extensions use class_type.

xsl
spl
sqlite
dom
simplexml
mysqli
 [2004-07-05 21:36 UTC] helly@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 17:01:58 2024 UTC