payamsad
سه شنبه 31 تیر 1393, 20:37 عصر
سلام
بعد از آپگرید شدن ورژن php از 5.2 به 5.3 در سروری که از آن استفاده میکنم مشکلات زیادی برای یک سری اسکریپت هایی که از آنها استفاده میکنم برایم پیش آمده به دلیل ساپورت نشدن خیلی کدهایی که در پی اچ پی ۵.۳ به بعد یا کلا حذف شده یا درست کار نمیکنه و warning میده.
یکی از مهمتریناش برای من بخشی از کدی هست که در اسکریپت Open source گالری Plogger (http://www.plogger.org) استفاده شده و خیلی مشکل ساز شده.
لطفا کسی میتونه کد زیر رو بر مبنای php 5.3 برای من اصلاح کنه؟
function plogger_count_collections() {
$numquery = "SELECT COUNT(DISTINCT `parent_collection`) AS `num_collections` FROM `".TABLE_PREFIX."pictures`";
$numresult = run_query($numquery);
$num_albums = mysql_result($numresult, 'num_collections');
return $num_albums;
}
درواقع بعد از آپگرید پی اچ پی به ورژن ۵.۳ سرور این ارور رو میده:
Warning: mysql_result() expects parameter 2 to be long, string
و در جای دیگه همین صفحه از اسکریپت باز اروری داده میشه که دقیقا از همین mysql_result ایراد گرفته شده و به نظر میاد راه حلش با مشکل ذکر شده در بالا یکی باشه اما برای اینکه کامل تر باشه کد نسبتا طولانی تر اون رو هم در زیر مینویسم:
function plogger_init_collections($arr) {
$sql = "SELECT COUNT(DISTINCT `parent_collection`) AS `num_items`
FROM `".TABLE_PREFIX."pictures`";
$result = run_query($sql);
$num_items = mysql_result($result, 'num_items');
$GLOBALS["total_pictures"] = $num_items;
// create a list of all non-empty collections. Could be done with subqueries, but
// MySQL 4.0 does not support those
// -1 is just for the case there are no images within collections or albums at all
$image_collection_count = array(-1 => -1);
$image_album_count = array(-1 => -1);
$album_count = array();
// 1. create a list of all albums with at least one photo
$sql = "SELECT parent_collection,parent_album,COUNT(*) AS imagecount
FROM `".TABLE_PREFIX."pictures` GROUP BY parent_collection,parent_album";
$result = run_query($sql);
while($row = mysql_fetch_assoc($result)) {
$image_collection_count[$row["parent_collection"]] = $row["imagecount"];
$image_album_count[$row["parent_album"]] = $row["imagecount"];
}
$imlist = join(",",array_keys($image_collection_count));
$albumlist = join(",",array_keys($image_album_count));
$cond = '';
if (empty($arr['all_collections'])) {
$cond = " WHERE `parent_id` IN ($imlist) AND `id` IN ($albumlist) ";
}
$sql = "SELECT parent_id,COUNT(*) AS albumcount
FROM `".TABLE_PREFIX."albums`
$cond
GROUP BY parent_id";
$result = run_query($sql);
while($row = mysql_fetch_assoc($result)) {
$album_count[$row["parent_id"]] = $row["albumcount"];
}
$GLOBALS["album_count"] = $album_count;
// I need to determine correct arguments for LIMIT from the given page number
$from = $arr['from'];
$lim = $arr['limit'];
$cond = "";
// by default only collections with pictures are returned
// override that with passing all_collections as an argument to
// this function
if (empty($arr['all_collections'])) {
$cond = " WHERE `id` IN ($imlist) ";
}
$ordering = " ORDER BY $arr[sortby] $arr[sortdir] ";
$sql = "SELECT * FROM `".TABLE_PREFIX."collections`
$cond $ordering LIMIT $from,$lim";
$result = run_query($sql);
$GLOBALS["available_collections"] = mysql_num_rows($result);
$GLOBALS["collection_counter"] = 0;
$GLOBALS["collection_dbh"] = $result;
}
پیشاپیش از کمک بزرگی که به من میکنید واقعا سپاسگزارم
(ضمنا فایل کامل که کد های بالا از اون کپی شده رو ضمیمه این تاپیک کردم هرچند که کل فایل های اسریپت از اینجا (http://www.plogger.org/source/plogger-1.0RC1.zip) قابل دریافت هست و ضمنا این فایل مورد بحث plog-includes/plog-functions.php میباشد)
بعد از آپگرید شدن ورژن php از 5.2 به 5.3 در سروری که از آن استفاده میکنم مشکلات زیادی برای یک سری اسکریپت هایی که از آنها استفاده میکنم برایم پیش آمده به دلیل ساپورت نشدن خیلی کدهایی که در پی اچ پی ۵.۳ به بعد یا کلا حذف شده یا درست کار نمیکنه و warning میده.
یکی از مهمتریناش برای من بخشی از کدی هست که در اسکریپت Open source گالری Plogger (http://www.plogger.org) استفاده شده و خیلی مشکل ساز شده.
لطفا کسی میتونه کد زیر رو بر مبنای php 5.3 برای من اصلاح کنه؟
function plogger_count_collections() {
$numquery = "SELECT COUNT(DISTINCT `parent_collection`) AS `num_collections` FROM `".TABLE_PREFIX."pictures`";
$numresult = run_query($numquery);
$num_albums = mysql_result($numresult, 'num_collections');
return $num_albums;
}
درواقع بعد از آپگرید پی اچ پی به ورژن ۵.۳ سرور این ارور رو میده:
Warning: mysql_result() expects parameter 2 to be long, string
و در جای دیگه همین صفحه از اسکریپت باز اروری داده میشه که دقیقا از همین mysql_result ایراد گرفته شده و به نظر میاد راه حلش با مشکل ذکر شده در بالا یکی باشه اما برای اینکه کامل تر باشه کد نسبتا طولانی تر اون رو هم در زیر مینویسم:
function plogger_init_collections($arr) {
$sql = "SELECT COUNT(DISTINCT `parent_collection`) AS `num_items`
FROM `".TABLE_PREFIX."pictures`";
$result = run_query($sql);
$num_items = mysql_result($result, 'num_items');
$GLOBALS["total_pictures"] = $num_items;
// create a list of all non-empty collections. Could be done with subqueries, but
// MySQL 4.0 does not support those
// -1 is just for the case there are no images within collections or albums at all
$image_collection_count = array(-1 => -1);
$image_album_count = array(-1 => -1);
$album_count = array();
// 1. create a list of all albums with at least one photo
$sql = "SELECT parent_collection,parent_album,COUNT(*) AS imagecount
FROM `".TABLE_PREFIX."pictures` GROUP BY parent_collection,parent_album";
$result = run_query($sql);
while($row = mysql_fetch_assoc($result)) {
$image_collection_count[$row["parent_collection"]] = $row["imagecount"];
$image_album_count[$row["parent_album"]] = $row["imagecount"];
}
$imlist = join(",",array_keys($image_collection_count));
$albumlist = join(",",array_keys($image_album_count));
$cond = '';
if (empty($arr['all_collections'])) {
$cond = " WHERE `parent_id` IN ($imlist) AND `id` IN ($albumlist) ";
}
$sql = "SELECT parent_id,COUNT(*) AS albumcount
FROM `".TABLE_PREFIX."albums`
$cond
GROUP BY parent_id";
$result = run_query($sql);
while($row = mysql_fetch_assoc($result)) {
$album_count[$row["parent_id"]] = $row["albumcount"];
}
$GLOBALS["album_count"] = $album_count;
// I need to determine correct arguments for LIMIT from the given page number
$from = $arr['from'];
$lim = $arr['limit'];
$cond = "";
// by default only collections with pictures are returned
// override that with passing all_collections as an argument to
// this function
if (empty($arr['all_collections'])) {
$cond = " WHERE `id` IN ($imlist) ";
}
$ordering = " ORDER BY $arr[sortby] $arr[sortdir] ";
$sql = "SELECT * FROM `".TABLE_PREFIX."collections`
$cond $ordering LIMIT $from,$lim";
$result = run_query($sql);
$GLOBALS["available_collections"] = mysql_num_rows($result);
$GLOBALS["collection_counter"] = 0;
$GLOBALS["collection_dbh"] = $result;
}
پیشاپیش از کمک بزرگی که به من میکنید واقعا سپاسگزارم
(ضمنا فایل کامل که کد های بالا از اون کپی شده رو ضمیمه این تاپیک کردم هرچند که کل فایل های اسریپت از اینجا (http://www.plogger.org/source/plogger-1.0RC1.zip) قابل دریافت هست و ضمنا این فایل مورد بحث plog-includes/plog-functions.php میباشد)