2011-05-09 134 views
0

我收到此錯誤Zend Framework:消息:SQLSTATE [42000]:語法錯誤或訪問衝突:1064您的SQL語法錯誤;

Message: 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 '' at line 1 
Stack trace: 
#0 H:\Documents\IIS_Server_Root\zendframework\Zend\Db\Statement.php(300): Zend_Db_Statement_Pdo->_execute(Array) 
#1 H:\Documents\IIS_Server_Root\zendframework\Zend\Db\Adapter\Abstract.php(479): Zend_Db_Statement->execute(Array) 
#2 H:\Documents\IIS_Server_Root\zendframework\Zend\Db\Adapter\Pdo\Abstract.php(238): Zend_Db_Adapter_Abstract->query(Object(Zend_Db_Table_Select), Array) 
#3 H:\Documents\IIS_Server_Root\zendframework\Zend\Db\Table\Abstract.php(1526): Zend_Db_Adapter_Pdo_Abstract->query(Object(Zend_Db_Table_Select)) 
#4 H:\Documents\IIS_Server_Root\zendframework\Zend\Db\Table\Abstract.php(1342): Zend_Db_Table_Abstract->_fetch(Object(Zend_Db_Table_Select)) 
#5 H:\Documents\IIS_Server_Root\my.localhost\ahaweb\application\models\Tagjoin.php(28): Zend_Db_Table_Abstract->fetchAll(Object(Zend_Db_Statement_Pdo)) 
#6 H:\Documents\IIS_Server_Root\my.localhost\ahaweb\application\models\Tag.php(44): Model_Tagjoin->getTags('12') 
#7 H:\Documents\IIS_Server_Root\my.localhost\ahaweb\application\models\Bookmark.php(30): Model_Tag->getTags('12') 
#8 H:\Documents\IIS_Server_Root\my.localhost\ahaweb\application\controllers\UserController.php(69): Model_Bookmark->getUserBookmark(1, '12') 
#9 H:\Documents\IIS_Server_Root\zendframework\Zend\Controller\Action.php(513): UserController->editAction() 
#10 H:\Documents\IIS_Server_Root\zendframework\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('editAction') 
#11 H:\Documents\IIS_Server_Root\zendframework\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) 
#12 H:\Documents\IIS_Server_Root\zendframework\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch() 
#13 H:\Documents\IIS_Server_Root\zendframework\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run() 
#14 H:\Documents\IIS_Server_Root\my.localhost\ahaweb\public\index.php(26): Zend_Application->run() 

在這段代碼

$tj = new Model_Tagjoin();     
    $stmt = $tj->select('*')->setIntegrityCheck(false) 
      ->joinInner("tags", "tags.tag_id = ".$this->_name.".tag_id",array("tag_name")) 
      ->where($this->_name.".bmk_id = ?", $bmk_id)->query();     
    $r = $tj->fetchAll($stmt); 

當我print_f$stmt值我得到

SELECT `tagjoins`.*, `tags`.`tag_name` FROM `tagjoins` 
INNER JOIN `tags` ON tags.tag_id = tagjoins.tag_id WHERE (tagjoins.bmk_id = '12') 

,如果我直接與MySQL使用它工作正常。

請幫忙。我的代碼有什麼問題?

+0

檢查您的Zend數據庫配置用戶的授權? – 2011-05-09 19:36:04

+0

如何檢查Zend Db Configuration用戶的「授權」?我正在使用mysql root密碼連接到mysql。 – 2011-05-09 19:43:17

+0

運行'SHOW GRANTS FOR'user'@'hostname';'在您的Zend db config中爲用戶指定的值以及您的應用程序所連接的主機名。 – 2011-05-09 19:52:04

回答

0

我不知道如何使用printf,但正如我在手冊中讀過的那樣,您應該使用assemble()方法來查看您的最終sql查詢。

這樣的事情。

$tj = new Model_Tagjoin();     
$stmt = $tj->select('*')->setIntegrityCheck(false) 
     ->joinInner("tags", "tags.tag_id = ".$this->_name.".tag_id",array("tag_name")) 
     ->where($this->_name.".bmk_id = ?", $bmk_id)->query()->assemble(); 
exit($stmt);     
$r = $tj->fetchAll($stmt); 

然後嘗試在phpMyAdmin之類的查詢。 請注意,如果此通話失敗,您可能要刪除該行的​​部分。

+0

我認爲他的意思是'print_r' ... – 2011-05-09 19:52:34

+0

assemble()給了我這個:SELECT'tagjoins'。*,'tags'.'tag_name' FROM'tagjoins' INNER JOIN' tags' ON tags。 tag_id = tagjoins.tag_id WHERE(tagjoins.bmk_id ='12') – 2011-05-09 19:53:57

+0

這是完美的工作,如果我直接使用它與mysql – 2011-05-09 19:54:19

相關問題