tags:

views:

28

answers:

1

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!

+2  A: 

What you are looking for is some sort of Active Record system. It is beyond PHP's normal scope, but third party implementations of this kind of functionality exists. Take for example a look at: AdoDB

Rodin
Thanks, after some searching I found MyActiveRecord. It's quite old (I think the last update was somewhere in 2007), and for MySql solely... BUT it's incredibly lightweight (which indeed also means there's no tons of extras in it) and ever so flexible. It's exactly what I was looking for!http://www.phpclasses.org/package/2990-PHP-Map-objects-to-MySQL-database-table-rows.html
Arsenal