NYCPHP Meetup

NYPHP.org

[nycphp-talk] Zend Framework confusion

David Mintz david at davidmintz.org
Fri Dec 14 12:35:05 EST 2007


Try printing that Zend_Db_Select object -- it has a nice __toString(). Then
copy and paste that query into your mysql command line client and see what
happens. It may be that your SQL isn't what you want it to be.

On Dec 14, 2007 10:21 AM, willie klein <willie at pdfsystems.com> wrote:

>  Hi All;
>
>
>
> I've just started using Zend Framework and having a hard time getting used
> to this new way of doing things.
>
>
>
> I'm a bit confused about how to register databases with the registry and
> putting things all together.
>
>
>
> I can query tables fine and put the results into my view if I use the
> table model, that is make the table a class and refer to it as a object
> through Zend_Table_class.  This is fine for querys with one table but I
> think for joins its better to use their SQL builder interface.  So if I put
> in my bootstrap file:
>
> // load configuration
>
> $config = new Zend_Config_Ini('./application/config.ini', 'general');
>
> $registry = Zend_Registry::getInstance();
>
> $registry->set('config', $config);
>
>
>
> // setup database
>
> $db = Zend_Db::factory($config->db->adapter,
> $config->db->config->toArray());
>
> Zend_Db_Table::setDefaultAdapter($db);
>
> Zend_Registry::set('db', $db);
>
> /////
>
> Can I just use in my controller :
>
> $db = Zend_Registry::get('db');
>
>            $select = $db->select();
>
>                         $select->distinct()
>
>                         ->from( 'course')
>
>                         ->join(array( 'user'), 'course.teacherID = user.id')
> ;
>
>             $data = $db->fetchAll($select);
>
>             $this->view->data = $data;//
>
> This doesn't work and I'm not sure why.
>
>
>
> This works with the model:
>
> $dbuser = new User();
>
> $this->view->dbuser = $dbuser->fetchAll();
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
>



-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20071214/2f2b547e/attachment.html>


More information about the talk mailing list