Zend Framework:消息:SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法错误;
我收到此错误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使用它工作正常。
请帮忙。我的代码有什么问题?
我不知道如何使用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之类的查询。 请注意,如果此通话失败,您可能要删除该行的部分。
我认为他的意思是'print_r' ... – 2011-05-09 19:52:34
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
这是完美的工作,如果我直接使用它与mysql – 2011-05-09 19:54:19
检查您的Zend数据库配置用户的授权? – 2011-05-09 19:36:04
如何检查Zend Db Configuration用户的“授权”?我正在使用mysql root密码连接到mysql。 – 2011-05-09 19:43:17
运行'SHOW GRANTS FOR'user'@'hostname';'在您的Zend db config中为用户指定的值以及您的应用程序所连接的主机名。 – 2011-05-09 19:52:04