在发布这个问题之前,我已经阅读了所有我可以接受的回复.虽然相似,但没有一个解决我的特定问题(或者我没有意识到他们这样做).
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 type displayOrder description localStartTime events_idEvent
1 个人 1 5k 跑步/步行 2010-02-18 23:59:59 1
2 team 2 5k Team Category 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 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在 'SELECT c
.* FROM categories
AS c
INNER JOIN <附近使用的正确语法code>events AS e
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
我已经检查了我能想到的所有资源.希望 SO 超级专家的结合使我成为最后一站.: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.
这篇关于MySQL Zend 框架 - SQLSTATE[42000]:语法错误或访问冲突:1064的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!