Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error' dans

J'ai cette fonction et il ne cesse de donner le message d'erreur "Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error'..." L'erreur est de m'intimant de la ligne "$row = $t2->fetchAll(PDO::FETCH_OBJ);". J'ai cherché tonnes pour une solution mais en vain. Mon code semble être le même format que les exemples donnés dans le php docs...

Voici la fonction de mise à jour comme par TML suggestions:

//gets a record by id and sets object properties to it's values
function getById($sid) {
    global $conf, $pdo;
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    //checks to see if a record exists for the given id
    try {
        $stmt  = $pdo->prepare('Use ' . $conf['database'] . '; select mem_id as "_id", mem_name as "_name", mem_info as "_info",
                                mem_password as "_password", mem_email as "_email", mem_image as "_image",
                                mem_group as "_group"
                                from ' . $conf['prefix'] . 'members
                                where mem_id = ?;');
        echo"85 <br />";
        $stmt->execute(array($sid));
        echo"86 <br />";
        $rows = $stmt->fetchAll(PDO::FETCH_OBJ);
        echo"90 <br />";
        print_r($rows);
        if (count($rows) !== 1) {
            throw new Exception("Some exception here");
        }
        foreach($rows[0] as $field=>$value) {
            $this->$field = $value;
            echo"97 <br />";
        }
    } catch (PDOException $e) {
        echo"something went wrong! " . var_dump($e);
    }
}

var_dump de sortie:

object(PDOException)[4]
protected 'message' => string 'SQLSTATE[HY000]: General error' (length=30)
private 'string' (Exception) => string '' (length=0)
protected 'code' => string 'HY000' (length=5)
protected 'file' => string 'D:\wamp\www\testing\scripts\Kantan\classes\Member.php' (length=53)
protected 'line' => int 86
private 'trace' (Exception) => 
array (size=2)
0 => 
array (size=6)
'file' => string 'D:\wamp\www\testing\scripts\Kantan\classes\Member.php' (length=53)
'line' => int 86
'function' => string 'fetchAll' (length=8)
'class' => string 'PDOStatement' (length=12)
'type' => string '->' (length=2)
'args' => 
array (size=1)
...
1 => 
array (size=6)
'file' => string 'D:\wamp\www\testing\scripts\Kantan\test.php' (length=43)
'line' => int 5
'function' => string 'getById' (length=7)
'class' => string 'Member' (length=6)
'type' => string '->' (length=2)
'args' => 
array (size=1)
...
private 'previous' (Exception) => null
public 'errorInfo' => 
array (size=1)
0 => string 'HY000' (length=5)
public 'xdebug_message' => string '<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> PDOException: SQLSTATE[HY000]: General error in D:\wamp\www\testing\scripts\Kantan\classes\Member.php on line <i>86</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeee'... (length=1472)

Merci d'avance pour toute aide.

Où est $q2->fetchAll dans votre code?

OriginalL'auteur Jamal | 2013-02-11