我正在尝试使用ajax检索一些信息。但是,当我调用select()方法时,系统返回一个致命错误。这是什么原因呢?
下面是我的代码:
define( '_JEXEC', 1 );
define( 'DS', DIRECTORY_SEPARATOR );
define( 'JPATH_BASE', realpath(dirname(__FILE__).DS.'..' ));
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('id', 'product_id')));
$query->from($db->quoteName('sample_table'));
// ->where('application_id = 11');
$db->setQuery($query);
$results = $db->loadObjectList();我已经在其他版本中多次使用了这个代码,并且它起作用了。我想这可能和版本有关..
提前谢谢。
发布于 2015-06-30 21:00:50
根据您的代码,我认为您正在尝试在外部函数中使用Joomla函数。该错误指示您正在使用工厂对象,而不包括工厂类。尝试包含所有这些文件:
define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
define('JPATH_BASE', $_SERVER['DOCUMENT_ROOT'] . DS . '');
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');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName(array('id', 'product_id')));
$query->from($db->quoteName('sample_table'));
// ->where('application_id = 11');
$db->setQuery($query);
$results = $db->loadObjectList();发布于 2015-07-01 19:56:51
这是你所有的代码吗?在我看来,您还没有创建数据库连接。你需要像这样的东西
jimport('joomla.database.database');
// System configuration.
$config = JFactory::getConfig();
// Note, this will throw an exception if there is an error
// Creating the database connection.
$this->dbo = JDatabase::getInstance(
array(
'driver' => $config->get('dbtype'),
'host' => $config->get('host'),
'user' => $config->get('user'),
'password' => $config->get('password'),
'database' => $config->get('db'),
'prefix' => $config->get('dbprefix'),
)
);总体而言,对于独立的应用程序,第一次需要多花几分钟的时间,但我认为使用API并将其放在构造函数中会更好。下面是一个https://github.com/elinw/AssetFix/blob/j3/assetfix.php#L65示例
https://stackoverflow.com/questions/31135600
复制相似问题