嗨,我的计算机PHP 5.4.12 Apache 2.4.4 MYSQL 5.6.12
而我的服务器PHP 5.5.3 Apache 2.4.6 MYSQL 5.5.37
当我在我的服务器上执行此功能时,我有这样的错误:SQLSTATE [HY000]:一般错误,但在我的localhost我没有任何错误
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;
}
}
Run Code Online (Sandbox Code Playgroud)
但是当我在我的服务器上执行此操作时,我没有错误
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;
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
我与PDO :: nextRowset()有同样的问题,因为它返回true,即使没有更多的行集可用,因此在调用fetchAll()时,它会引发异常HY000.(在PHP 5.5.12 windows上测试,Mysql 5.5.17 linux)
此问题的解决方法是在获取行集之前使用方法PDO :: columnCount()检查列数.如果它不为零,则您有一个有效的行集,因此您可以调用PDO :: fetchAll().
即使PDO :: nextRowset()报告为true,columnCount()也会在移动到下一个rowset之前报告列数.
例:
while ($objQuery->columnCount()) {
$tab[] = $objQuery->fetchAll(\PDO::FETCH_ASSOC);
$objQuery->nextRowset();
}
Run Code Online (Sandbox Code Playgroud)