Are any of you aware of a library that helps you build/manipulate SQL queries, that supports JOIN\'s?
It would give a lot of flexibility i\'d think if you have somet
Try magsql https://github.com/maghead/magsql, a SQL builder designed for performance written in PHP, comes with join support and cross-platform SQL generation.
It's currently used in the fastest pure PHP orm "maghead"
Maybe you can try an ORM, like Propel or Doctrine, they have a nice programmatic query language, and they return you arrays of objects that represent rows in your database...
For example with Doctrine you can do joins like this:
$q = Doctrine_Query::create();
$q->from('User u')
->leftJoin('u.Group g')
->innerJoin('u.Phonenumber p WITH u.id > 3')
->leftJoin('u.Email e');
$users = $q->execute();
And with Propel:
$c = new Criteria(AuthorPeer::DATABASE_NAME);
$c->addJoin(AuthorPeer::ID, BookPeer::AUTHOR_ID, Criteria::INNER_JOIN);
$c->addJoin(BookPeer::PUBLISHER_ID, PublisherPeer::ID, Criteria::INNER_JOIN);
$c->add(PublisherPeer::NAME, 'Some Name');
$authors = AuthorPeer::doSelect($c);
and you can do a lot more with both...
FluentPDO looks nice if you're already using PDO: https://github.com/envms/fluentpdo
I would advise using a PHP framework such as Symfony which uses Propel by default and can use Doctrine if you wish.
CakePHP also uses an ORM, but I don't know which one.
You can use lenkorm it's very easy:
select('contents)->left('categories ON categories.category.id = contents.category_id)->where('content_id = 1')->result();
or you can use as:
select('contents)->left('categories->using(categoru_id)->where('content_id = 1')->result();
Download it from github
I use the query builder from the phptoolcase library, it uses pdo connector, has join support.
http://phptoolcase.com/guides/ptc-qb-guide.html
You can use it with the connection manager fro the library to setup multiple database connection very quickly.