From:             [EMAIL PROTECTED]
Operating system: Debian 2.19
PHP version:      4.0.4pl1
PHP Bug Type:     MySQL related
Bug description:  mysql_close closes incorrect db handler

debian 2.19 / mysql 3.23.37 / php 4.0.4pl1

configure section of phpinfo():
'./configure' '--with-gd' '--with-jpeg-dir' '--with-png-dir'
'--with-tiff-dir' '--disable-posix' '--enable-ftp' '--enable-calendar'
'--with-imap' '--with-mcrypt' '--with-swf=/usr/local/swf'
'--with-apache=/home/atiware/apache_1.3.14' '--enable-track-vars'
'--with-mysql=/usr/local'


the sript that reproduces the problem:
--cut here--
<?php
        define("DEEPLIMIT",10); //maximal deep of recursive calls
/*
        !! please edit this settings !!
*/
        define("MYHOST","localhost");
        define("MYPORT","3306");
        define("MYUSER","YOUR_USERNAME");
        define("MYPWD","YOUR_PASSWORD");


        /* this function reproduces the error */
        function recursive($deep,$persistent=false) {
                if ($deep<=DEEPLIMIT) {
                        //down side
                        if ($persistent)
                                $db=mysql_pconnect(MYHOST.":".MYPORT,MYUSER,MYPWD); 
//creating
persistent mysql connection and storing in a local variable
                        else
                                $db=mysql_connect(MYHOST.":".MYPORT,MYUSER,MYPWD); 
//creating mysql
connection and storing in a local variable

                        $res=@mysql_query("select 1 as ONE",$db); //some dummy query
                        $mr=null;
                        if (@mysql_num_rows($res)) {
                                $mr=@mysql_fetch_array($res);
                        }
                        //and now write the result
                        printf("%sRecursive: Deep: %s, DownSideQuery:
%s<br>\n",str_repeat(">",$deep),$deep,(int)$mr["ONE"]);

                        recursive($deep+1,$persistent);

                        //up side
                        $res=@mysql_query("select 1 as ONE",$db); //using previously 
created
connection ($db), if exists ;)
                        $mr=null;
                        if (@mysql_num_rows($res)) {
                                $mr=@mysql_fetch_array($res);
                        }
                        //write result again
                        printf("%sRecursive: Deep: %s, UpSideQuery:
%s",str_repeat(">",$deep),$deep,(int)$mr["ONE"]);
                        //error check
                        if (!(int)$mr["ONE"])
                                printf("&nbsp;&nbsp;<b>!?ERROR!? why 0?</b>");
                        printf("<br>\n");
                        @mysql_close($db); //closing mysql connection
                }
                else {
                        printf("Limit occured (%s). Turning back...<br>\n",DEEPLIMIT);
                }
        }

        echo "Trying with <b>mysql_connect()</b><br>\n";
        recursive(1);

        echo "<br><br>\n\n";
        echo "Trying with <b>mysql_pconnect()</b><br>\n";
        recursive(1,true);

?>
--cut here--

the output of the script:

Trying with mysql_connect()
>Recursive: Deep: 1, DownSideQuery: 1
>>Recursive: Deep: 2, DownSideQuery: 1
>>>Recursive: Deep: 3, DownSideQuery: 1
>>>>Recursive: Deep: 4, DownSideQuery: 1
>>>>>Recursive: Deep: 5, DownSideQuery: 1
>>>>>>Recursive: Deep: 6, DownSideQuery: 1
>>>>>>>Recursive: Deep: 7, DownSideQuery: 1
>>>>>>>>Recursive: Deep: 8, DownSideQuery: 1
>>>>>>>>>Recursive: Deep: 9, DownSideQuery: 1
>>>>>>>>>>Recursive: Deep: 10, DownSideQuery: 1
Limit occured (10). Turning back...
>>>>>>>>>>Recursive: Deep: 10, UpSideQuery: 1
>>>>>>>>>Recursive: Deep: 9, UpSideQuery: 1
>>>>>>>>Recursive: Deep: 8, UpSideQuery: 1
>>>>>>>Recursive: Deep: 7, UpSideQuery: 1
>>>>>>Recursive: Deep: 6, UpSideQuery: 1
>>>>>Recursive: Deep: 5, UpSideQuery: 0  !?ERROR!? why 0?
>>>>Recursive: Deep: 4, UpSideQuery: 0  !?ERROR!? why 0?
>>>Recursive: Deep: 3, UpSideQuery: 0  !?ERROR!? why 0?
>>Recursive: Deep: 2, UpSideQuery: 0  !?ERROR!? why 0?
>Recursive: Deep: 1, UpSideQuery: 0  !?ERROR!? why 0?


Trying with mysql_pconnect()
>Recursive: Deep: 1, DownSideQuery: 1
>>Recursive: Deep: 2, DownSideQuery: 1
>>>Recursive: Deep: 3, DownSideQuery: 1
>>>>Recursive: Deep: 4, DownSideQuery: 1
>>>>>Recursive: Deep: 5, DownSideQuery: 1
>>>>>>Recursive: Deep: 6, DownSideQuery: 1
>>>>>>>Recursive: Deep: 7, DownSideQuery: 1
>>>>>>>>Recursive: Deep: 8, DownSideQuery: 1
>>>>>>>>>Recursive: Deep: 9, DownSideQuery: 1
>>>>>>>>>>Recursive: Deep: 10, DownSideQuery: 1
Limit occured (10). Turning back...
>>>>>>>>>>Recursive: Deep: 10, UpSideQuery: 1
>>>>>>>>>Recursive: Deep: 9, UpSideQuery: 1
>>>>>>>>Recursive: Deep: 8, UpSideQuery: 1
>>>>>>>Recursive: Deep: 7, UpSideQuery: 1
>>>>>>Recursive: Deep: 6, UpSideQuery: 1
>>>>>Recursive: Deep: 5, UpSideQuery: 1
>>>>Recursive: Deep: 4, UpSideQuery: 1
>>>Recursive: Deep: 3, UpSideQuery: 1
>>Recursive: Deep: 2, UpSideQuery: 1
>Recursive: Deep: 1, UpSideQuery: 1

-- 
Edit bug report at: http://bugs.php.net/?id=11993&edit=1


-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to