Question

Hi i have my wamp server on my computer PHP 5.4.12 Apache 2.4.4 MYSQL 5.6.12

And my server PHP 5.5.3 Apache 2.4.6 MYSQL 5.5.37

and when i'm doing this function on my server i have this error : SQLSTATE[HY000]: General error but in my localhost i don't have any error

function getinformationpublic($nocate)
{
    try
    {
        $public = array();
        global $Cnn;
        $reponse = $Cnn->prepare("CALL GetInfoPublicCible(:nocategorie)");
        $reponse->bindParam('nocategorie',$nocate,PDO::PARAM_INT);
        $reponse->execute();
        do {
            $rowset = $reponse->fetchAll(PDO::FETCH_ASSOC);
            $public[] = $rowset; 

        } while ($reponse->nextRowset());

        $reponse->closeCursor();
        return $public;
    }
    catch (PDOException $erreur)
    {
        $msg[]=$erreur->getMessage();
        $_SESSION["message"]["d"]=$msg;
    }

}

but when i'm doing this one on my server i don't have error

function getinformationpublic($nocate)
{
    try
    {
        $public = array();
        global $Cnn;
        $reponse = $Cnn->prepare("CALL GetInfoPublicCible(:nocategorie)");
        $reponse->bindParam('nocategorie',$nocate,PDO::PARAM_INT);
        $reponse->execute();
            $rowset = $reponse->fetchAll(PDO::FETCH_ASSOC);
            $public[] = $rowset; 
                        $reponse->nextRowset();
                        $rowset = $reponse->fetchAll(PDO::FETCH_ASSOC);
            $public[] = $rowset; 
                        $reponse->nextRowset();
                        $rowset = $reponse->fetchAll(PDO::FETCH_ASSOC);
            $public[] = $rowset; 
                $reponse->nextRowset();
                         $rowset = $reponse->fetchAll(PDO::FETCH_ASSOC);
            $public[] = $rowset; 
        $reponse->closeCursor();
        return $public;
    }
    catch (PDOException $erreur)
    {
        $msg[]=$erreur->getMessage();
        $_SESSION["message"]["d"]=$msg;
    }

}
Was it helpful?

Solution

I had same problem with PDO::nextRowset(), as it returns true even there is no more rowsets available, therefore when calling fetchAll(), it raises exception HY000. (tested on PHP 5.5.12 windows, Mysql 5.5.17 linux)

A workaround for this problem is to check number of columns with method PDO::columnCount() before fetching rowset. If it is non-zero, you have a valid rowset, and thus you could call PDO::fetchAll().

Even if PDO::nextRowset() reports true, columnCount() will report number of columns before moving to next rowset.

Example:

while ($objQuery->columnCount()) {
    $tab[] = $objQuery->fetchAll(\PDO::FETCH_ASSOC);
    $objQuery->nextRowset();
}

OTHER TIPS

The problem is you are using the do...while form, which will execute the code in the do part before verifying the while condition. This means on the last iteration, even if nextRowset() just returned false, the do part will be executed one last time.

just remove the do part, and put everything in a while. It is not true that nextRowset returns true even if there is no rowset. have a read on do...while and on nextRowset()

$public[] = $reponse->fetchAll(PDO::FETCH_ASSOC);
// so that the first rowset gets into your array
while ($reponse->nextRowset()) {
    $public[] = $reponse->fetchAll(PDO::FETCH_ASSOC);
}

also you need a double dot with your bindParam, like the param it is binded to

$reponse->bindParam(':nocategorie',$nocate,PDO::PARAM_INT);
while($rowset = $reponse->fetchAll(PDO::FETCH_ASSOC))
{
    $public[] = $rowset;
    $reponse->nextRowset();
}

This should work. A bit of change. We check if there is a rowset then goes to next one. And then if it is we do that once more. Try it now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top