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

时间:2016-05-18 12:35:03

标签: php joomla joomla3.0

我第一次使用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()中遇到问题;这条线什么都没有,没有任何错误, 在该行之后的任何事情都没有执行甚至不回应。

2 个答案:

答案 0 :(得分:1)

要在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();

答案 1 :(得分:0)

这对我有用:

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);

放在根目录中。

相关问题