不知道是客戶自身數據的問題還是方維程序的問題,今天有客戶反映,在瀏覽別人的 個人中心->寶貝 這個頁面時,點擊右邊分享的寶貝時,如果該寶貝是被喜歡的,就會出現數據庫查詢錯誤:
該訪問鏈接是:
http://www.xxxxxxx.com/note.php?action=g&sid=12645&id=6757
錯誤信息:
sql語句很明顯的錯誤,是在in()括號中最后一個值后面多了一個“,”號,
這條查詢語句的位置在:
core/service/share.service.php文件的 public function getCollectShareByShare($share_id,$num = 20)函數中,
注意下面紅色字體
if(count($uids) > 0)
{
$share_ids = array();
$res = FDB::query(‘SELECT GROUP_CONCAT(DISTINCT sgi.share_id
ORDER BY sgi.share_id DESC SEPARATOR /’,/’) AS share_ids,sgi.uid
FROM ‘.FDB::table(‘user_collect’).’ AS uc
INNER JOIN ‘.FDB::table(‘share_goods_index’).’ AS sgi ON sgi.share_id = uc.share_id AND sgi.share_id <> ‘.$share_id.’
WHERE uc.c_uid IN (‘.implode(‘,’,$uids).’) GROUP BY sgi.uid LIMIT 0,’.$num);
while($data = FDB::fetch($res))
{
$share_ids = explode(‘,’,$data['share_ids']);
$share_ids[] = (int)current($share_ids);
}
$share_ids = array_unique($share_ids); //源代碼中,只是過濾掉了數組中的重復值
$share_ids = array_filter($share_ids); //這句代碼是我后來添加的,過濾掉了數組中的空值,這樣程序就可以正常執行了
if(count($share_ids) > 0)
{
$list = FDB::fetchAll(‘SELECT share_id,uid,content,collect_count,comment_count,create_time,cache_data FROM ‘.FDB::table(‘share’).’ WHERE share_id IN (‘.implode(‘,’,$share_ids).’) LIMIT 0,’.$num);
$list = ShareService::getShareDetailList($list);
}
不管這個問題是不是客戶由于操作數據庫失誤導致的,我想都應該對查詢得到的數據數組,進行空值過濾。
新聞熱點
疑難解答