dongxie1907 2016-04-09 16:47
浏览 63

从外部数据库Joomla中提取数据

I used this tutorial to connect to a external database in my Joomla website.

I think that I managed to connect successfully to the database, but when I tried to use the data it returns an empty white page.

This is the code which I am using if the Table was in the joomla database:

$db = JFactory::getDbo();
$query = $db->getQuery(true); 

$query->select(array('*'))
->from($db->quoteName('orders'))
->where($db->quoteName('manufacturer') . ' IS NOT NULL')
$db->setQuery($query);

$results = $db->loadObjectList();

echo '<table class="table table-striped">';

foreach ($results as $row)
{

echo '<tr>';
echo '<td class="first">'. $row->manufacturer .'</td>';
echo '<td>' . $row->type. '.</td>';
echo '<td>' . ($row->power+0) . ' kW</td>';
echo '<td>' . $row->rpm. ' мин.<sup>-1</sup></td>';
echo '</tr>';

}

echo '</table>';

How should I modify it, so I can have this simple table but from an external database?

  • 写回答

3条回答 默认 最新

  • doulupian8725 2016-04-10 10:06
    关注

    The following in your code...

    $db = JFactory::getDbo();
    

    ...will connect to the Joomla database, and not to the external database. Check the guide again and see how the external connection is made.

    In any case, a white page is a sign of a fatal error somewhere. Check your logs or enable error reporting to see where the error comes from.

    Also, make sure that you are actually in the Joomla context (e.g. the Joomla environment has loaded) if you want to use Joomla's functions.

    评论

报告相同问题?

悬赏问题

  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常
  • ¥15 关于风控系统,如何去选择