MySQL Zend Framework - SQLSTATE[42000]: Syntax error or access violation: 1064

本秂侑毒 提交于 2019-12-24 08:18:36

问题


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).

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);

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");

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 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]: 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.* FROM categories AS c INNER JOIN events AS e ON c.events_id' at line 1

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


回答1:


Check out the second part of the error statement. Most likely it is regarding an access violation if the mysql elsewhere.




回答2:


For reasons unknown to me, the app believed my $pageResult variable wasn't set. I discovered this after adding an isset() to the code like this:

        try {
        $getCategoryResults = $this->select();
        $getCategoryResults->setIntegrityCheck(false)
                           ->from(array('c'=> 'categories', '*'))
                           ->join(array('e' => 'events'),'c.events_idEvent = e.idEvent', array())
                            ->where("e.idEvent = ?", $idEvent);

          if (isset($pageResult)) {
            $pageResult .= $getCategoryResults;
          }
          else {
            $pageResult = $getCategoryResults;
          }

    } catch (Exception $e) {
        echo ( "Could not find matching categories for event id = $idEvent");
    }

Problem went away which, of course, revealed the next problem lurking behind it. :D



来源:https://stackoverflow.com/questions/2204571/mysql-zend-framework-sqlstate42000-syntax-error-or-access-violation-1064

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!