在我制作的 joomla 程序中,我使用以下代码从数据库表中请求两列:
$db=JFactory::getDbo();
$query=$db->getQuery(true);
$query->select($db->quoteName(array('keywords','en_GB_tips')))
->from('#__tooltip_explain');
$db->setQuery($query);
$keywords=$db->loadColumn(0);
$tips=$db->loadColumn(1);
此代码曾经有效,但最近最后一个命令:loadColumn(1) 返回为空。我尝试了多个版本,但基本上如果我请求超过 1 列/行,则只有第一个包含数据。我的服务器是运行最新的 php 和 mysql 5.6 的 apache2 实例。我还尝试在另一台服务器上也运行 apache2,但使用 mariadb 作为数据库,但它在那里也不起作用。但是,我确实在装有 mysql 5.5 的旧服务器上运行。
有人知道为什么这适用于 mysql 5.5 而不是其他数据库吗? (我没有使用 mysql 5.6 的服务器,所以我不能确定它最近是否从 5.5 更新到 5.6)
最佳答案
试试这个,
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('keywords','en_GB_tips')))
->from('#__tooltip_explain');
$db->setQuery($query);
$results = $db->loadObject();//if more than one row then loadObjectList()
$keywords = $results->keywords;
$tips = $results->en_GB_tips;
可以找到 Joomla 文档 here
关于mysql - 在 joomla 中选择多个 mysql 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33899112/