首页 文章

在Magento中加载日志访问者集合时收到“查询为空”错误

提问于
浏览
1

如何使用Log / Visitor模型检索访问者集合?我尝试使用以下代码....

<?php 
error_reporting(E_ALL);
ini_set('display_errors',TRUE);
$root = $_SERVER['DOCUMENT_ROOT'];
require_once $root.'/app/Mage.php';
Mage::app('default');

$visitors = Mage::getModel('log/visitor')->getCollection()->load();
?>

但它返回一个错误,摘录是......

SQLSTATE[42000]: Syntax error or access violation: 1065 Query was empty

查询没有't throw any errors until I add the ' load()'方法到链 . 我的问题类似于magento visitor logs,但该代码示例缺少load(),并且唯一的答案是直接使用资源模型,我认为这不应该是必要的 .

更新:

正在使用的Magento版本是1.4.1.1 . 完整异常跟踪:

致命错误:未捕获的异常'Zend_Db_Statement_Exception',消息'SQLSTATE [42000]:语法错误或访问冲突:1065查询为空'在/home/dev_fluid/public_html/lib/Zend/Db/Statement/Pdo.php:234堆栈跟踪:#0 /home/dev_fluid/public_html/lib/Zend/Db/Statement.php(300):Zend_Db_Statement_Pdo - > _ execute(Array)#1 /home/dev_fluid/public_html/lib/Zend/Db/Adapter/Abstract.php (468):Zend_Db_Statement-> execute(Array)#2 /home/dev_fluid/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238):Zend_Db_Adapter_Abstract-> query('',Array)#3 / home / dev_fluid / public_html / lib / Varien / Db / Adapter / Pdo / Mysql.php(333):Zend_Db_Adapter_Pdo_Abstract-> query('',Array)#4 / home / dev_fluid / public_html / lib / Zend / Db / Adapter / Abstract.php(706):Varien_Db_Adapter_Pdo_Mysql-> query(Object(Varien_Db_Select),Array)#5 /home/dev_fluid/public_html/lib/Varien/Data/Collection/Db.php(707):Zend_Db_Adapter_Abstract-> fetchAll(Object( Varien_Db_Select),数组)#6 / home / dev_fluid / public_html / lib / Varien / Data / Collec / / Db.php(620):第234行的/home/dev_fluid/public_html/lib/Zend/Db/Statement/Pdo.php中的Varien_Data_Collect

新的跟踪,使用Jurgen的getTraceAsString()方法:

#0 /home/dev_fluid/public_html/lib/Zend/Db/Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array) 
#1 /home/dev_fluid/public_html/lib/Zend/Db/Adapter/Abstract.php(468): Zend_Db_Statement->execute(Array) 
#2 /home/dev_fluid/public_html/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('', Array) 
#3 /home/dev_fluid/public_html/lib/Varien/Db/Adapter/Pdo/Mysql.php(333): Zend_Db_Adapter_Pdo_Abstract->query('', Array) 
#4 /home/dev_fluid/public_html/lib/Zend/Db/Adapter/Abstract.php(706): Varien_Db_Adapter_Pdo_Mysql->query(Object(Varien_Db_Select), Array) 
#5 /home/dev_fluid/public_html/lib/Varien/Data/Collection/Db.php(707): Zend_Db_Adapter_Abstract->fetchAll(Object(Varien_Db_Select), Array) 
#6 /home/dev_fluid/public_html/lib/Varien/Data/Collection/Db.php(620): Varien_Data_Collection_Db->_fetchAll(Object(Varien_Db_Select)) 
#7 /home/dev_fluid/public_html/lib/Varien/Data/Collection/Db.php(590): Varien_Data_Collection_Db->getData() 
#8 /home/dev_fluid/public_html/app/code/core/Mage/Log/Model/Mysql4/Visitor/Collection.php(300): Varien_Data_Collection_Db->load(false, false) 
#9 /home/dev_fluid/public_html/andy/visitor.php(11): Mage_Log_Model_Mysql4_Visitor_Collection->load() 
#10 {main}

1 回答

  • 0

    请将您的代码更改为:

    <?php 
    error_reporting(E_ALL);
    ini_set('display_errors',TRUE);
    $root = $_SERVER['DOCUMENT_ROOT'];
    require_once $root.'/app/Mage.php';
    Mage::app('default');
    
    $visitors = Mage::getModel('log/visitor')->getCollection();
    try {
        $x = $visitors->load();
        die('no exception');
    }
    catch (Exception $e) {
        var_dump($e->getTraceAsString());
    }
    

    如果在 load() 方法中发生异常,则应该为您提供完整的跟踪 .

    如果该跟踪无法帮助您解决问题,我建议使用PHP调试器,如xdebug,Zend Debug或DBG等(取决于您的IDE支持的调试器) .

    load() 方法之前设置断点并通过代码单步执行应该显示给出一个线索,为什么查询为空 .

相关问题