I have tried this and it's working:
<?php
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', dirname(__FILE__).DS."../apitest/");
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' );
$conn = JDatabase::getConnectors();
print_r($conn);
?>
However, when I tried this:
<?php
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', dirname(__FILE__).DS."../apitest/");
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' );
$conn = JDatabase::$connection;
print_r($conn);
?>
It returns:
Fatal error: Cannot access protected property JDatabase::$connection in C:\xampp\htdocs\apitest1\index.php on line 10
How can access $connection variable?
This is protected so you need to use a getter to read from, and a setter to write to this property.
Googling for the Joomla API showed up this:
http://docs.joomla.org/API16:JDatabase/getConnection
Example usage
You also might want to have a look at this article
Try this
Hope this may help you..
You have to use reflection using-php-reflection-to-read-a-protected-property! Read this to learn more about access modifiers stackoverflow or PHP.net