简体   繁体   中英

Zf2 Using Zend\Db\Sql\Select

Need help using Zend\\Db\\Sql\\Select. Can't figure out what I'm doing wrong, it outputs nothing and no errors displayed.

namespace Album\Model;
use Zend\Db\Adapter\Adapter,
    Zend\Db\Sql\Select;

class AlbumTable
{
    public function getAll()
    {
        $select = new Select('album'); 
        return $select->from();
    }
}

namespace Album\Controller;

class AlbumController extends AbstractActionController
{
    public function indexAction()
    {
        return new Viewmodel(array(
            'rows' => $this->albumTable->useSelect()
        ));
    }
}

// index.phtml
foreach ($this->rows as $row) { echo $row->artist . '<br />'; }

Thanks

Figured I didn't query the string I built.

Zend\Db\Sql\Sql; 

class AlbumTable
{
    public function getAll()
    {
        $sql = new Sql($this->adapter);
        $select = new Select('album');

        $selectString = $sql->getSqlStringForSqlObject($select);
        return $this->adapter->query($selectString, Adapter::QUERY_MODE_EXECUTE);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM