我已经尝试过了,它正在工作:
<?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);
?>
但是,当我尝试这样做时:
<?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);
?>
它返回:
Fatal error: Cannot access protected property JDatabase::$connection in C:\xampp\htdocs\apitest1\index.php on line 10
如何访问 $connection 变量?