views:

1267

answers:

2

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

A: 

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

Joe
A: 

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

Mike
You didn't mention the pageresult variable in your original question. Glad it worked out for you, because I've spent a good 15 minutes trying to see why you were experiencing the error, and couldn't see anything wrong with it.I usually miss things like this when I get tired. Maybe it's time to get some rest? :)
rvdavid