2

I'm trying to access joomla's methods from a php file on the same server.

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

When i try to insert data on the database, nothing happens

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

Thx

Mazeltov
  • 541
  • 5
  • 18

1 Answers1

2

Try this,

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

Hope its works..

Jobin
  • 8,238
  • 1
  • 33
  • 52
  • define('JPATH_BASE', dirname(__FILE__) ); set your path properly – Jobin Jan 09 '14 at 18:29
  • 1
    The path you have to set is Joomla installation, eg: this php page is under root and Joomla installation also in root Then exactly like above code other wise you have to adjust the path according to Joomla installation. It will works – Jobin Jan 10 '14 at 02:50