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

I read every answer I could rely on before posting this question. Despite the similarities, none of them addressed my specific problem (or I did not admit that they were doing this).

I have a table class that extends Zend_Db_Table_Abstract. In the model, I am trying to return a single row using the join () method and based on the table identifier, for example:

        $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 repeat the sql object, I get the following:

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 result: "WHERE (e.idEvent = 1)". The value is not enclosed in ticks, but it seems to work for MySQL. When I run the request in phpMyAdmin, I get the following:

id localStartTime events_idEvent
1 1 5k Run/Walk 2010-02-18 23:59:59 1
2 team 2 5k Team Category 2010-02-18 23: 59: 591 1

. , :

SQLSTATE [42000]: : 1064 SQL; , MySQL, "SELECT c. * FROM categories AS c INNER JOIN events AS e ON c.events_id ' 1

, . , SO uber- .: D

+1
2

. , , mysql .

+1

, $pageResult . isset() :

        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");
    }
, , , , .: D
+1

Source: https://habr.com/ru/post/1749487/


All Articles