MySQL Zend Framework-SQLSTATE [42000]:语法错误或访问冲突:1064
在发布此问题之前,我已经阅读了我可能会做的所有答复.尽管类似,但是没有一个解决我的特定问题(或者我没有意识到他们这样做).
I've read every response I could fine on SO before posting this question. Although similar, none addressed my particular problem (or I didn't recognize them doing so).
我有一个扩展Zend_Db_Table_Abstract的表类.在模型中,我试图使用join()方法并基于如下表ID返回单行:
I have a table class that extends Zend_Db_Table_Abstract. In the model, I'm trying to return a single row using a join() method and based on the table ID like this:
$getCategoryResults = $this->select();
$getCategoryResults->setIntegrityCheck(false)
->from(array('c'=> 'categories', '*'))
->join(array('e' => 'events'),'c.events_idEvent = e.idEvent', array())
->where("e.idEvent = ?", $idEvent);
当我回显sql对象时,我得到了:
when I echo the sql object, I get this:
SELECT `c`.* FROM `categories` AS `c`
INNER JOIN `events` AS `e` ON c.events_idEvent = e.idEvent
WHERE (e.idEvent = '1')
奇怪的是,如果我使用这种格式,
Oddly enough, if I use this format,
->where("e.idEvent = $idEvent");
我的输出是"WHERE(e.idEvent = 1)".该值不是用记号括起来的,但是两者似乎都适用于MySQL.当我在phpMyAdmin中运行查询时,得到以下信息:
my output is "WHERE (e.idEvent = 1)". The value is not enclosed in ticks, but either seems to work for MySQL. When I run the query in phpMyAdmin, I get this:
idCategory类型displayOrder描述localStartTime events_idEvent
1个人1 5k跑步/步行2010-02-18 23:59:59 1
2团队2 5k团队类别2010-02-18 23:59:591 1
idCategory type displayOrder description localStartTime events_idEvent
1 individual 1 5k Run / Walk 2010-02-18 23:59:59 1
2 team 2 5k Team Category 2010-02-18 23:59:591 1
这是我期望看到的.但是,当我在浏览器中运行我的应用程序时,我会感到很丑陋:
which is what I expected to see. But when I run my app in a browser, I get this ugliness:
SQLSTATE [42000]:语法错误或访问冲突:1064您的SQL语法有一个错误;请参阅第1914页的"SQLSTATE错误".请检查与您的MySQL服务器版本相对应的手册,以在'SELECT
c
附近使用正确的语法.* FROMcategories
ASc
INNER JOINevents
ASe
ON c.events_id'在第1行
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 'SELECT
c
.* FROMcategories
ASc
INNER JOINevents
ASe
ON c.events_id' at line 1
我检查了我能想到的所有资源.希望,超级专家的出色表现将使这成为我的最后一站. :D
I've checked every resource that I can think of. Hopefully, the combined awesomeness of SO uber-experts will make this my last stop. :D
检出错误语句的第二部分.如果mysql在其他地方,则很可能与访问冲突有关.
Check out the second part of the error statement. Most likely it is regarding an access violation if the mysql elsewhere.