an error in your SQL syntax"-6ren"> an error in your SQL syntax"-我正在使用 Joomla 模块 (ArogaRousel),该模块是用来显示另一个模块 (AdsManager) 的图像,并且该模块显示以下错误: No valid database connecti-6ren">
gpt4 book ai didi

mysql - 使用 Joomla 模块并收到错误 "No valid database connection You have > an error in your SQL syntax"

转载 作者:行者123 更新时间:2023-11-29 09:14:56 25 4
gpt4 key购买 nike

我正在使用 Joomla 模块 (ArogaRousel),该模块是用来显示另一个模块 (AdsManager) 的图像,并且该模块显示以下错误:

No valid database connection You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')) ORDER BY views DESC, id LIMIT 0, 9' at line 1 SQL=SELECT *,concat('/images/com_adsmanager/ads/',id,'a.jpg') as imgUrl FROM root_adsmanager_ads , root_adsmanager_adcat as ac WHERE published=1 AND (ac.adid=id and ac.catid IN ()) ORDER BY views DESC, id LIMIT 0, 9

我不精通mysql,但是我找到了进行查询的文件。

这是进行查询的代码

$query = "SELECT *,concat('/images/com_adsmanager/ads/',id,'a.jpg') as imgUrl FROM #__adsmanager_ads "
. $table
. " WHERE published=1 "
. $where
. $ordering
. $limit;

各位有识之士能否指出错误和解决方案?

为了回应 Bemace,我在这里添加了整个函数

// Get list of banners
function getAds(&$paramslist){

$where = array();
if ($paramslist['ads'] != '') $where[] = 'id IN (' . modArogarouselAdsmanagerHelper::cleanIds($paramslist['ads']) . ')';

if ($paramslist['categories'] != '') {
$where[] = 'ac.adid=id and ac.catid IN (' . modArogarouselAdsmanagerHelper::cleanIds($paramslist['categories']) . ')';
$table = ' , #__adsmanager_adcat as ac';
}


$where = (count($where) > 0) ? ' AND (' . implode(' OR ', $where) . ')' : '';

if ($paramslist['ordering'] == 1) {
$ordering = ' ORDER BY views DESC, id';
} else if ($paramslist['ordering'] == 2) {
$ordering = ' ORDER BY views ASC';
} else if ($paramslist['ordering'] == 3) {
$ordering = ' ORDER BY id';
} else if ($paramslist['ordering'] == 4) {
$ordering = ' ORDER BY RAND()';
}

$limit = ($paramslist['limit'] != '') ? ' LIMIT 0, ' . ($paramslist['limit']) : '';

$query = "SELECT *,concat('/images/com_adsmanager/ads/',id,'a.jpg') as imgUrl FROM #__adsmanager_ads "
. $table
. " WHERE published=1 "
. $where
. $ordering
. $limit;
$db = &JFactory::getDBO();
$db->setQuery($query);
$adslist = $db->loadObjectList();
$adslist = ($paramslist['mode_dir'] == 'bottom') ? array_reverse($adslist, true) : $adslist;
//print_r($adslist);
return $adslist;
}

最佳答案

ORDER BY 之前的空 IN () 就是问题所在。您需要检查设置 $where 变量的代码。它似乎期望至少选择一个类别,但似乎没有选择。

关于mysql - 使用 Joomla 模块并收到错误 "No valid database connection You have > an error in your SQL syntax",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4446512/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com