joomla: make database connections outside joomla, using the joomla db functions

this situation i have: joomla with joomlaxy/JSPT/Payplans installed and working good.

now, i have done a little php script inside the /pages folder, to use inside a template of a specific user type, which call a javascript passing a couple of variables (myID,followID)

http_request.open('POST', '/test/update.php', true);
    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    postvar="myID="+myID+"&followID="+followID;
    http_request.send(postvar); 

well, now, i have done the update.php, inside the root of the site and atm it is something like this:

$myID=$_POST['myID'];
$followID=$_POST['followID'];

$query="INSERT INTO '#__community_follow' (myID,followID) VALUES ($myID,$followID)";

$op_ok=1;

if($op_ok==1){
    echo "QUERY:$query";
}else{
    echo "Error";
}

I have done the table using the "joomla" name format, i would like to include the servers functions of joomla to make him execute the query...

can someone help me? ha have try to put:

require_once ('libraries/joomla/factory.php');
$db =& JFactory::getDBO();

and the use :

$db->setQuery($query);
$db->query();

but without any luck... any advice?

Upvotes: 1

Views: 2847

Answers (1)

Trev
Trev

Reputation: 851

On 1.5 I use something like this to get access to the joomla objects from external files.

$directory = '/var/www/myfolder'; // path to joomla installation

define( '_JEXEC', 1 );
define( 'JPATH_BASE', $directory);
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' );
$mainframe =& JFactory::getApplication('site');

Upvotes: 2

Related Questions