mysql_fetch_object on complex objects

Posted by Arsenal on Stack Overflow See other posts from Stack Overflow or by Arsenal
Published on 2010-05-06T14:53:55Z Indexed on 2010/05/06 14:58 UTC
Read the original article Hit count: 190

Filed under:
|

Say for example I have the follwoing DB structure

Table book

  • id
  • title
  • ...

Table Author

  • id
  • name
  • ...

Table BookAuthor

  • id
  • bookid
  • authorid

And in PHP I have the following object

class Book {
  var $id;
  var $title;
  var $authors = array();

  function Book() {}
}

class Author {
  var $id;
  var $name;

  function Author(){}
}

Now, would it be possible using mysql_fetch_object to retrieve the bookobject including the authors as an array of author objects?

If it's possible I'm pretty sure you'll need the basic inner join query

SELECT * FROM tblbook INNER JOIN tblbookauthor on ... (wel you get the point)

Is it possible?

thanks!

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql