从外部php文件访问joomla的助手

时间:2014-01-09 14:48:32

标签: php joomla libraries helpers dbo

我正在尝试从同一服务器上的php文件访问joomla的方法。

$shop_directory = '/var/www/components/com_shop';
$base_directory = '/var/www';

define( '_JEXEC', 1 );
define( 'JPATH_BASE', $base_directory);
define( 'JPATH_COMPONENT', $shop_directory);
define( 'DS', '/' );
require_once(JPATH_COMPONENT.DS.'helpers'.DS.'helpers.php');
require_once(JPATH_COMPONENT.DS.'helpers'.DS.'dbo.php');
require_once(JPATH_BASE.DS.'libraries'.DS.'joomla'.DS.'factory.php');

当我尝试在数据库中插入数据时,没有任何反应

$db = JFactory::getDbo('database_name');
$query = "INSERT INTO `payment_info` VALUES ( 
                    '',
                    '".$order_id."',
                    '".$customer_id."');";
$db->setQuery($query);
$db->query();

THX

1 个答案:

答案 0 :(得分:2)

试试这个,

define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );//this is when we are in the root
define( 'DS', DIRECTORY_SEPARATOR );

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

$mainframe =& JFactory::getApplication('site');
$mainframe->initialise();

$db = JFactory::getDbo();//Db object do not require database name
$query = "INSERT INTO `payment_info` VALUES ( 

                    '".$order_id."',
                    '".$customer_id."')";
$db->setQuery($query);
$db->query();

希望它的作品......