2015-12-18 41 views
0

我對Magento相當陌生,當我嘗試調試最近安裝的擴展時遇到此錯誤。我試圖理解日誌,但是想知道問題到底是什麼。任何人都可以告訴我應該在哪裏開始根據以下日誌進行調試?在Magento擴展中調試SQL語法錯誤

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AS `query_id`, `s`.`product_id`, MATCH (s.data_index) AGAINST ('' IN BOOLEAN MOD' at line 1 

Trace: 
#0 /var/www/html/springmaternity/lib/Varien/Db/Statement/Pdo/Mysql.php(110): Zend_Db_Statement_Pdo->_execute(Array) 
#1 /var/www/html/springmaternity/app/code/core/Zend/Db/Statement.php(291): Varien_Db_Statement_Pdo_Mysql->_execute(Array) 
#2 /var/www/html/springmaternity/lib/Zend/Db/Adapter/Abstract.php(480): Zend_Db_Statement->execute(Array) 
#3 /var/www/html/springmaternity/lib/Zend/Db/Adapter/Pdo/Abstract.php(238): Zend_Db_Adapter_Abstract->query('INSERT INTO `ca...', Array) 
#4 /var/www/html/springmaternity/lib/Varien/Db/Adapter/Pdo/Mysql.php(428): Zend_Db_Adapter_Pdo_Abstract->query('INSERT INTO `ca...', Array) 
#5 /var/www/html/springmaternity/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext.php(393): Varien_Db_Adapter_Pdo_Mysql->query('INSERT INTO `ca...', Array) 
#6 /var/www/html/springmaternity/app/code/core/Mage/CatalogSearch/Model/Fulltext.php(136): Mage_CatalogSearch_Model_Resource_Fulltext->prepareResult(Object(Mage_CatalogSearch_Model_Fulltext), '', Object(Yireo_DisableLog_Model_Rewrite_Catalogsearch_Query)) 
#7 /var/www/html/springmaternity/app/code/core/Mage/CatalogSearch/Model/Resource/Fulltext/Collection.php(55): Mage_CatalogSearch_Model_Fulltext->prepareResult() 
#8 /var/www/html/springmaternity/app/code/core/Mage/CatalogSearch/Model/Layer.php(58): Mage_CatalogSearch_Model_Resource_Fulltext_Collection->addSearchFilter('') 
#9 /var/www/html/springmaternity/app/code/community/Rayfox/Catalog/Model/Search/Layer.php(18): Mage_CatalogSearch_Model_Layer->prepareProductCollection(Object(Mage_CatalogSearch_Model_Resource_Fulltext_Collection)) 
#10 /var/www/html/springmaternity/app/code/core/Mage/CatalogSearch/Model/Layer.php(42): Rayfox_Catalog_Model_Search_Layer->prepareProductCollection(Object(Mage_CatalogSearch_Model_Resource_Fulltext_Collection)) 
#11 /var/www/html/springmaternity/app/code/core/Mage/Catalog/Model/Layer.php(290): Mage_CatalogSearch_Model_Layer->getProductCollection() 
#12 /var/www/html/springmaternity/app/code/core/Mage/Catalog/Model/Layer.php(220): Mage_Catalog_Model_Layer->_getSetIds() 
#13 /var/www/html/springmaternity/app/code/core/Mage/Catalog/Block/Layer/View.php(163): Mage_Catalog_Model_Layer->getFilterableAttributes() 
#14 /var/www/html/springmaternity/app/code/local/FME/Layerednav/Block/Layer/View.php(85): Mage_Catalog_Block_Layer_View->_getFilterableAttributes() 
#15 /var/www/html/springmaternity/app/code/core/Mage/Core/Block/Abstract.php(293): FME_Layerednav_Block_Layer_View->_prepareLayout() 
#16 /var/www/html/springmaternity/app/code/core/Mage/Core/Model/Layout.php(456): Mage_Core_Block_Abstract->setLayout(Object(Mage_Core_Model_Layout)) 
#17 /var/www/html/springmaternity/app/code/core/Mage/Core/Model/Layout.php(472): Mage_Core_Model_Layout->createBlock('layerednav/sear...', 'layer') 
#18 /var/www/html/springmaternity/app/code/core/Mage/Core/Model/Layout.php(239): Mage_Core_Model_Layout->addBlock('layerednav/sear...', 'layer') 
#19 /var/www/html/springmaternity/app/code/core/Mage/Core/Model/Layout.php(205): Mage_Core_Model_Layout->_generateBlock(Object(Mage_Core_Model_Layout_Element), Object(Mage_Core_Model_Layout_Element)) 
#20 /var/www/html/springmaternity/app/code/core/Mage/Core/Controller/Varien/Action.php(344): Mage_Core_Model_Layout->generateBlocks() 
#21 /var/www/html/springmaternity/app/code/core/Mage/Core/Controller/Varien/Action.php(269): Mage_Core_Controller_Varien_Action->generateLayoutBlocks() 
#22 /var/www/html/springmaternity/app/code/local/FME/Layerednav/controllers/FrontController.php(54): Mage_Core_Controller_Varien_Action->loadLayout() 
#23 /var/www/html/springmaternity/app/code/core/Mage/Core/Controller/Varien/Action.php(418): FME_Layerednav_FrontController->searchAction() 
#24 /var/www/html/springmaternity/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('search') 
#25 /var/www/html/springmaternity/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http)) 
#26 /var/www/html/springmaternity/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch() 
#27 /var/www/html/springmaternity/app/Mage.php(684): Mage_Core_Model_App->run(Array) 
#28 /var/www/html/springmaternity/sg/index.php(90): Mage::run('sg', 'website') 
#29 {main} 
+0

只看到此[鏈接](http://magento.stackexchange.com/questions/67249/ce-1-9-1-syntax-error-or-access-violation-1064)。 –

回答

0

如果你有一個模式,即做查詢和你是好奇將生成你有幾個選擇的SQL, 我最喜歡的是使用下面的

$collection = Mage::getModel('customcodes/code')->getCollection() 
->addFieldToSelect('code') 
->addFieldToFilter('order_id',array('eq'=>247938)) 
->addFieldToFilter('code_type',array('eq'=>'CODESQAC')); 

$什麼sql = $ collection-> getSelect() - > __ toString();

然後$ sql中會有

SELECT `main_table`.`code` FROM `custom_codes` AS `main_table` WHERE (`order_id` = 247938) AND (`code_type` = 'CODESQAC') 

現在,你可以通過磁語法工作弄清楚爲什麼它不拉的結果或引發錯誤就像你所看到的。 這聽起來像你知道Magento代碼來自哪裏,所以使用這種方法將幫助你弄清楚它們使用的語法是不正確的。

此外,請檢查硬編碼表名稱的代碼,而不是使用Magento工廠方法和/或調用特定的表名稱,而不是使用類似以下的內容來獲取實際的表名稱(您可以使用表名稱前綴和原來的代碼可能只是被硬編碼)

$resource = Mage::getSingleton('core/resource');  
$customer_table = $resource->getTableName('customer/entity'); 

下面是使用硬編碼表的名稱,而不是使用配置,從而取得表的表名,表名的情況下的一個例子前綴

$collection->getSelect()->joinLeft(array('sfoa'=>'sales_flat_order_address'), 'main_table.entity_id = sfoa.parent_id and sfoa.address_type = \'billing\'', array('sfoa.company')); 

正確的w AY會是這樣的

$resource = Mage::getSingleton('core/resource'); 
$sales_table = $resource->getTableName('sales/order_address'); 

$collection->getSelect()->joinLeft(array('sfoa'=>$sales_table), 'main_table.entity_id = sfoa.parent_id and sfoa.address_type = \'billing\'', array('sfoa.company')); 

希望這將有助於您檢查語法錯誤,並最終如何以及什麼實際的SQL正在創建。