在我自己的机器上运行良好的东西在生产服务器上失败了。
下面的代码输出“ 24 ”和“ Begin try branch ”,就是这样。之后就停止了。在我自己的机器上,变量是绑定的,我可以继续使用$recPhotos->fetch()
等。
问题出现在这里:
$recPhotos = GetPhotos($_SESSION['album_uid'], $getVipImages, $arrPaginationParams["currentPage"], $arrPaginationParams["photosPerPage"]);
try
{
echo($recPhotos->affected_rows); // Outputs '24'
echo("Begin try branch");
$recPhotos->bind_result($file_name, $is_vip);
echo("End try branch");
}
catch (Exception $e)
{
echo 'Exception caught: ', $e->getMessage(), "\n";
}
echo("Continue");
调用的函数如下:
// Get photos from database
function GetPhotos($album_uid, $getVipImages,$page, $rows)
{
$objMySqli = GetDbConnection();
$page = ($page - 1) * 24;
if ($objMySqliQuery = $objMySqli->prepare("SELECT file_name, is_vip from album_pic where album_uid = ? AND is_vip = ? OR is_vip = 'N' order by is_vip DESC, file_name ASC LIMIT ?,? ;"))
{
$objMySqliQuery->bind_param('ssss', $album_uid, $getVipImages, $page, $rows);
$objMySqliQuery->execute();
$objMySqliQuery->store_result();
return $objMySqliQuery;
}
else
{
// Error
printf("Prepared Statement Error: %s\n", $objMySqli->error);
return false;
}
}
奇怪的是,如果我尝试在函数内部输出一些行,它可以工作(我得到 24 行,正如预期的那样)
// Get photos from database
function GetPhotos($album_uid, $getVipImages,$page, $rows)
{
$objMySqli = GetDbConnection();
$page = ($page - 1) * 24;
if ($objMySqliQuery = $objMySqli->prepare("SELECT file_name, is_vip from album_pic where album_uid = ? AND is_vip = ? OR is_vip = 'N' order by is_vip DESC, file_name ASC LIMIT ?,? ;"))
{
$objMySqliQuery->bind_param('ssss', $album_uid, $getVipImages, $page, $rows);
$objMySqliQuery->execute();
$objMySqliQuery->bind_result($col1, $col2);
while ($objMySqliQuery->fetch())
{
printf("%s %s\n", $col1, $col2); // This will be executed 24 times
}
}
else
{
// Error
printf("Prepared Statement Error: %s\n", $objMySqli->error);
return false;
}
}
任何想法将不胜感激。谢谢!