PDA

View Full Version : سوال: اصلاح نا همخوانی کد های قدیمی php 5.2 در php5.3 به بالا (mysql_result)



payamsad
سه شنبه 31 تیر 1393, 19: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 میباشد)

مهرداد سیف زاده
سه شنبه 31 تیر 1393, 20:43 عصر
بصورت زیر ویرایش کنید

$num_albums = mysql_result($numresult,0);

http://www.sitepoint.com/forums/showthread.php?817256-Database-Query-Error-(Parameter-1-resource-boolean)
http://stackoverflow.com/questions/14968847/warning-mysql-result-expects-parameter-1-to-be-resource-boolean-given-in-ho
http://stackoverflow.com/questions/11995952/mysql-result-resulting-error-in-php

payamsad
چهارشنبه 01 مرداد 1393, 05:08 صبح
مهرداد عزیز٬
از لطف شما بینهایت سپاسگزارم. در تمام بخش های اسکریت این تغییر را انجام دادم و مشکل Front end سایت برطرف شد. اما راستش بعد از این اصلاح وقتی به بخش Admin هم سری زدم که تستش کنم متوجه شدم اونجا هم یک سری ارور داده شده. اگر براتون امکان داشت در این مورد هم منو راهنمایی کنین واقعا ممنون میشم.


Deprecated: Function eregi() is deprecated in /plog-includes/lib/phpthumb/phpthumb.functions.php on line 362


function gd_version($fullstring=false) {
static $cache_gd_version = array();
if (empty($cache_gd_version)) {
$gd_info = phpthumb_functions::gd_info();
if (eregi('bundled \((.+)\)$', $gd_info['GD Version'], $matches)) {
$cache_gd_version[1] = $gd_info['GD Version']; // e.g. "bundled (2.0.15 compatible)"
$cache_gd_version[0] = (float) $matches[1]; // e.g. "2.0" (not "bundled (2.0.15 compatible)")
} else {
$cache_gd_version[1] = $gd_info['GD Version']; // e.g. "1.6.2 or higher"
$cache_gd_version[0] = (float) substr($gd_info['GD Version'], 0, 3); // e.g. "1.6" (not "1.6.2 or higher")
}
}
return $cache_gd_version[intval($fullstring)];
}

در واقع از eregi در خیلی بخشهای ادمین ایراد گرفته شده. آیا برای این مورد هم جایگزینی وجود داره؟



و همینطور در قسمتی دیگه ارور زیر داده شده:


Deprecated: Function split() is deprecated in /plog-admin/plog-rpc.php on line 20


مربوط به:



// Now we parse the field to be updated and the id number from the field variable
$var = split("-", $field);
$type = $var[0];
$field = $var[1];
$id = $var[2];


باز هم از لطفی که میکنید بسیار ممنونم و امیدوارم با راهنمایی های شما مشکلم حل بشه و دیگه مزاحمت ایجاد نکنم
ضمنا فایل های مربوطه در صورت نیاز آپلود شدند

مهرداد سیف زاده
چهارشنبه 01 مرداد 1393, 06:31 صبح
بجای eregi بزارید preg_match
بجای split بزارید explode

payamsad
چهارشنبه 01 مرداد 1393, 20:02 عصر
سلام
باز هم از لطف شما بسیار ممنونم. همه مشکلات من در این پکیج با کمک شما کاملا حل شد