ID:               35910
 Updated by:       [EMAIL PROTECTED]
 Reported By:      Ryan dot Melena at gmail dot com
-Status:           Open
+Status:           Verified
 Bug Type:         PDO related
 Operating System: Windows XP
 PHP Version:      5.1CVS-2006-01-05 (snap)
 Assigned To:      wez
 New Comment:

I can reproduce this on linux.

It appears to be less of a problem if you avoid binding to variables
that are members of an object.

I haven't been able to pinpoint exactly what the cause is, as it
appears to change subtly as the script is modified.

I remember that once-upon-a-time, referencing $this inside a
constructor would lead to problems, perhaps this is a manifestation of
that issue.


Previous Comments:
------------------------------------------------------------------------

[2006-04-09 14:53:55] Ryan dot Melena at gmail dot com

<?php

/* SQL

CREATE TABLE IF NOT EXISTS `section` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `parentSectionID` int(10) unsigned NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=8 ;

INSERT INTO `section` VALUES (1, 1);
INSERT INTO `section` VALUES (2, 1);
INSERT INTO `section` VALUES (3, 2);
INSERT INTO `section` VALUES (4, 1);
INSERT INTO `section` VALUES (5, 5);
INSERT INTO `section` VALUES (6, 6);
INSERT INTO `section` VALUES (7, 6);

*/

?>

<?php

global $db_host, $db_name, $db_username, $db_password;

$db_host = 'localhost';
$db_name = 'test';
$db_username = 'root';
$db_password = 'superw00t';

class section
{
    private $id = null;
    
    private $parentSectionID = null;
    
    private $childSections = array();
    
    private $status = array('consistentWithDb' => false,
'childSectionsLoaded' => false);
    
    function __construct($id)
    {
        $db = resourceHelper::getDbConn();
        
        // Validate $id and load section data
        if(!is_int($id))
        {
            throw new Exception('Invalid argument for
section::loadFromDb(), $id must be an int.  Value sent was [' . $id .
'] of type [' . gettype($id) . '].');
        }
        
        $this->id = $id;
        
        $query =    'SELECT parentSectionID FROM section WHERE id =
:id';

        $stmt = $db->prepare($query);
        
        $stmt->bindValue(':id', $this->id , PDO::PARAM_INT);
        
        $stmt->execute();
        
        $stmt->bindColumn('parentSectionID',    $this->parentSectionID,
   PDO::PARAM_INT);
        
        $stmt->fetch(PDO::FETCH_BOUND);

        $stmt = null;
        $db = null;
    }
    
     function __get($varName)
    {
        switch($varName)
        {
            case 'id':
                return (int)$this->id;
            case 'childSections':
                if(!$this->status['childSectionsLoaded'])
                {
                    $this->loadChildSections();
                }
                return $this->childSections;
            default:
                throw new Exception('Variable [' . $varName . '] is not
a public member of section.');
                break;
        }
    }
        
    private function loadChildSections()
    {
        $sectionID = null;
        
        $db = resourceHelper::getDbConn();
        
        $query = 'SELECT id FROM section WHERE parentSectionID = :id
AND parentSectionID != id';
        
        $stmt = $db->prepare($query);
        
        $stmt->bindValue(':id',    $this->id,    PDO::PARAM_INT);
        
        $stmt->execute();
        
        $stmt->bindColumn('id',    $sectionID,    PDO::PARAM_INT);
        
        while($stmt->fetch(PDO::FETCH_BOUND))
        {
            $this->childSections[] = new section($sectionID);
        }
        
        $this->status['childSectionsLoaded'] = true;
    }
}


class resourceHelper
{
    public static function getDbConn()
    {
        global $db_host, $db_name, $db_username, $db_password;
    
        // Create and Validate database connection
        try
        {
            $db = new PDO('mysql:host=' . $db_host . ';dbname=' .
$db_name, $db_username, $db_password);
            $db->setAttribute(PDO::ATTR_ERRMODE,
PDO::ERRMODE_EXCEPTION);
        }
        catch(Exception $e)
        {
            throw new Exception('Unable to connect to database [' .
$config['db']['name'] . '] using configuration file values.' .
$e->getMessage());
        }
        
        return $db;
    }
}


$db = resourceHelper::getDbConn();
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sectionID = null;

$query = 'SELECT id FROM section WHERE id = parentSectionID';

$stmt = $db->prepare($query);

$stmt->execute();

$stmt->bindColumn('id',    $sectionID,    PDO::PARAM_INT);

while($stmt->fetch(PDO::FETCH_BOUND))
{
    $section = new section($sectionID);
    buildSectionRow($section);
}

$stmt = null;
$db = null;




function buildSectionRow(section $section, $indent = 0)
{

    echo $section->id . '<br />';

    $indent++;
    
    /*
    To reproduce error, comment out $test definition then 
    replace $test in foreach loop with $section->childSections
    */

    $test = $section->childSections;

    foreach($test as $childSection)
    {
        buildSectionRow($childSection, $indent);
    }
}
?>

------------------------------------------------------------------------

[2006-04-09 07:44:21] [EMAIL PROTECTED]

Please paste the script into the bug report.
I can't reach the URL you posted.


------------------------------------------------------------------------

[2006-01-05 22:24:45] [EMAIL PROTECTED]

Yes, this is right, but it doesn't add any understanding.
Assigned to the PDO maintainer.

------------------------------------------------------------------------

[2006-01-05 22:18:47] Ryan dot Melena at gmail dot com

Hope this is right... From Visual Studio:

>       php5ts.dll!_efree(void * ptr=0x00ed982c)  Line 303 + 0x1a bytes C
        php5ts.dll!zend_hash_del_key_or_index(_hashtable * ht=0x00eb4fe0,
char * arKey=0x00ed9840, unsigned int nKeyLength=15, unsigned long h=0,
int flag=0)  Line 490 + 0x6 bytes       C
        php5ts.dll!zend_hash_reverse_apply(_hashtable * ht=0x00eb4fe0, int
(void *, void * * *)* apply_func=0x10096c10, void * * *
tsrm_ls=0x003225b8)  Line 738 + 0xf bytes       C
        php5ts.dll!shutdown_executor(void * * * tsrm_ls=0x003225b8)  Line
268     C
        php5ts.dll!zend_deactivate(void * * * tsrm_ls=0x003225b8)  Line
848     C
        php5ts.dll!php_request_shutdown(void * dummy=0x00000000)  Line
1287    C
        php.exe!main(int argc=2, char * * argv=0x00323f90)  Line 1231   C
        php.exe!_mainCRTStartup()  + 0xe3 bytes 
        kernel32.dll!7c816d4f()         
        [Frames below may be incorrect and/or missing, no symbols loaded for
kernel32.dll]   
        kernel32.dll!7c8399f3()

------------------------------------------------------------------------

[2006-01-05 22:07:15] [EMAIL PROTECTED]

Yeah, that's what I think is causing it.
Could you try to install MySQL 4.x and see if you can reproduce the
problem?
Also read this:
http://bugs.php.net/bugs-generating-backtrace-win32.php
http://bugs.php.net/bugs-generating-backtrace.php

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/35910

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

Reply via email to