-1

I've been looking for the answer for an hour or two and can't find it. I have this class that extends Zend_Db_Table_Abstract where I fill the table name and its primary key. Here it is:

<?php

class Produit_Model_DbTable_Fiche extends Zend_Db_Table_Abstract
{
    /**
     * @var string
     */
    protected $_name = 'table_name';

    /**
     * @var string
     */
    protected $_primary = 'primary';

    public function getName()
    {
        return $this->_name;
    }

    public function getPrimary()
    {
        return $this->_primary;
    }
}

As you can see, the protected attribute _primary is a string. However, when I retrieve this info via $db->getPrimary() in the following code, it is returned as an array which has only one entry [1] => 'id'.

// $db is an instance of Produit_Model_DbTable_Fiche
$select = $db->select();
$select->from($db, $columns)
       ->where($db->info('primary').' = ?', $id);
$row = $db->fetchRow($select);

The error message states that Column not found: 1054 Unknown column 'Array' in 'where clause' because, as I said, I'm trying to echo an array with $db->info('primary') whereas I expect it to be a string.

PS: I've seen this question/answer but I'm still in the blur : Zend_Db_Table_Abstract::_primary returns array?

Community
  • 1
  • 1
D4V1D
  • 5,805
  • 3
  • 30
  • 65

1 Answers1

0

There is answer in question you linked - "Zend_Db_Table stores primary keys as an array in case a compound key is used". What this mean is that SQL tables can have more than one column set as PRIMARY KEY creating something called 'compound key'. Such key could not be stored in single variable, thats why its stored in array. Most tables use single key so Zend could return string or array depending on key, but they preferred to remain consistent and return always array.

Volvox
  • 1,639
  • 1
  • 12
  • 10