Joomla 3.5.1 JFactory::getDBO();不工作,不抛出错误

Joomla 3.5.1 JFactory::getDBO(); not working and not throwing error

我是第一次使用 Joomla,我必须编写一些外部 php 代码来更新 joomla 数据库。 这是我的代码

<?php

  define( '_JEXEC', 1 );
  define( 'DS', DIRECTORY_SEPARATOR );
  define( 'JPATH_BASE', $_SERVER[ 'DOCUMENT_ROOT' ] );
   // my project directory name is Joomla
  require_once( JPATH_BASE .DS.'Joomla'.DS . 'libraries' . DS . 'joomla' . DS . 'factory.php' );

  $db = JFactory::getDBO();
  $query = $db->getQuery(true);
  $fields = array(
  $db->quoteName('title') . ' = ' . $db->quote('Menu Updated'));
  $conditions = array(
  $db->quoteName('id') . ' = 103' );
  $query->update($db->quoteName('iqogr_menu'))->set($fields)->where($conditions);
  $db->setQuery($query);
  $result = $db->loadResult();

?>

现在我在 JFactory::getDBO() 中遇到问题;这条线什么也没有,也没有给出任何错误, 该行之后的任何内容都不会执行,甚至不会回显。

要在 Joomla 之外调用 Joomla 类,您可以使用此代码

$dir = '/var/www/Joomla'; // path to your joomla installation directory

define( '_JEXEC', 1 );
define( 'JPATH_BASE', $dir);
define( 'DS', '/' );

require_once ( JPATH_BASE .DS . 'configuration.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );

require_once ( JPATH_BASE .DS.'libraries'.DS.'joomla'.DS.'factory.php' );
//Then you can call the classes this way
$mainframe = JFactory::getApplication('site');
$db = JFactory::getDBO();

这对我有用:

define( '_JEXEC', 1); 

define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', realpath(dirname(__FILE__) .'/' ) );

require_once ( JPATH_BASE . '/includes/defines.php' );
require_once ( JPATH_BASE . '/includes/framework.php' );

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

放在根目录下