ID:               34270
 Updated by:       [EMAIL PROTECTED]
 Reported By:      nmariz at estadias dot com
-Status:           Open
+Status:           Feedback
 Bug Type:         PDO related
 Operating System: Debian GNU/Linux 3.1 (Apache 2)
 PHP Version:      5.1.0RC1
 New Comment:

Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc.

If possible, make the script source available online and provide
an URL to it here. Try to avoid embedding huge scripts into the report.




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

[2005-08-29 18:07:30] nmariz at estadias dot com

Ok,

<?php
class Modules {
    public function __construct() {
        $this->dbconn = DatabaseFactory::getInstance();
    }
    public function getModules() {
        $query = 'SELECT id name,text FROM modules';
        $stmt = $this->dbconn->query($query);
        $result = $stmt->fetchAll();
        $stmt = null;
        return $result;
    }
    (...)
}
?>

<?php

abstract class DatabaseFactory {
    private static $instancePool;
    
    private function __construct() {
        // Instanciation not allowed
    }

    // Prevent users to clone the instance
    public function __clone() {
        trigger_error('Clone is not allowed.', E_USER_ERROR);
    }    

    // The singleton method
    public static function &getInstance($instanceIndex = 'default',
$options = null) {
        try {
            if (isset(self::$instancePool[$instanceIndex]))
                return self::$instancePool[$instanceIndex];
            elseif (is_array($options))
                self::factory($instanceIndex, $options);
            else                    
                throw new Exception('The instance with index
<b>'.$instanceIndex.'</b> does not exists');
        } catch (Exception $e) {
            exit('<pre><b>Caught DatabaseFactory exception: </b><br
/>'.$e->getMessage().' on line <b>'.$e->getLine().'</b></pre>');
        }            
        
        return self::$instancePool[$instanceIndex];
    }

    // The factory method    
    public static function factory($instanceIndex, $options) {
        try {
            $dsn =
$options['driver'].':host='.$options['hostname'].';dbname='.$options['database'];
            if ($options['persistent'] == 1)
                self::$instancePool[$instanceIndex] = new PDO($dsn,
$options['username'], $options['password'], array(PDO_ATTR_PERSISTENT
=> true));
            else
                self::$instancePool[$instanceIndex] = new PDO($dsn,
$options['username'], $options['password']);
            
            if ($options['pdo_error_mode'] == 'exception')
               
self::$instancePool[$instanceIndex]->setAttribute(PDO_ATTR_ERRMODE,
PDO_ERRMODE_EXCEPTION);
            elseif ($options['pdo_error_mode'] == 'warning')
               
self::$instancePool[$instanceIndex]->setAttribute(PDO_ATTR_ERRMODE,
PDO_ERRMODE_WARNING);
            else // silent
               
self::$instancePool[$instanceIndex]->setAttribute(PDO_ATTR_ERRMODE,
PDO_ERRMODE_SILENT);
            
        } catch (PDOException $e) {
            exit('<pre><b>Database connection failed: </b><br
/>'.$e->getMessage().' on line <b>'.$e->getLine().'</b></pre>');
        }
    }
    
    // Returns the total of instances
    public static function getTotalInstances() {
        return count(self::$instancePool);
    }

    // Returns the index of the last instance created
    public static function getLastInstanceIndex() {
        return self::$instancePoll[(count(self::$instancePool) - 1)];
    }
}

?>

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

[2005-08-29 17:44:34] [EMAIL PROTECTED]

No, I don't trust anyone, not even myself when dealing with bugs. Is it
so hard to give the 2-3 lines before this that do the connection/etc? 


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

[2005-08-29 17:39:49] nmariz at estadias dot com

Man,
Is in the query part, this happens in several queries on my app.
I am not a beginner in PHP, so trust me...
Whatever, forget... this is a waste of time.

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

[2005-08-29 17:07:13] [EMAIL PROTECTED]

I think you don't understand that I am very very lazy.
And that your problem _might_ be somewhere ELSE than in the query part.
So either give the full code or go away.

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

[2005-08-29 17:00:45] nmariz at estadias dot com

What part in "Segmentation fault when executing an invalid
SQL(_____ANY_____) statement" did you not understand?
I think that you don't need more code to understand what i mean.

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

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/34270

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

Reply via email to