开发者

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

开发者 https://www.devze.com 2022-12-19 11:15 出处:网络
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'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 / Wa开发者_开发问答lk 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


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消