1

I have a model that contains several types of products that are all stored in different MySQL databases, but all have one "parent" product that is stored in another table. The parent table is called "products" and contains amongst others the variables:

id
type
price
name

An example of "children" would be "books" which would contain amongst others:

id
meta_id
pages

Another "child" could be "dvds":

id
meta_id
tracks

where the meta_id of the child is equal to the id of the parent.

In old fashioned MySQL I would get all books by using:

SELECT 
  p.id, p.type, p.price, p.name, b.pages 
FROM 
  products p 
LEFT JOIN 
  books b
ON
  p.id=o.meta_id

I know how to read & write data to & from one database table using Zend, extending the Zend_Db_Table_Abstract, and using a Mapper & a Model. I'm just not sure how to do this if I have to read/write objects that are stored in multiple database tables. How do I set this up? What model/pattern should I use? I'm sure this is pretty standard stuff, but I been searchjing for days for clear examples, and I just can't seem to figure it out.

2
  • you can use the old fashioned way too. $oDb->fetchAll(/*string mysql*/); $oDb is Zend_Db::factory function (with arguments) Commented Nov 30, 2011 at 14:34
  • Thanks but I prefer not to use the old method of writing out full queries. Commented Nov 30, 2011 at 15:33

1 Answer 1

1

I had exactly the same confusion as you, and there is a great page here - Zend Framework Data Models - which explains how to solve this exact problem. You'll see ZF has excellent facilities to handle this sort of thing (short of using an ORM like Doctrine).

Also, when you're querying multiple tables, it is useful to be aware of the integrity check, as mentioned here Zend Framework Db Select Join table help

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! That page looks like it might have the solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.