用于PHP的SQL Builder,是否具有JOIN支持? [英] SQL Builder for PHP, with JOIN support?

查看:119
本文介绍了用于PHP的SQL Builder,是否具有JOIN支持?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您有没有人知道一个可以帮助您构建/处理SQL查询的库,该库支持JOIN?

Are any of you aware of a library that helps you build/manipulate SQL queries, that supports JOIN's?

如果您有可以返回对象的对象,该对象具有一些查询集,并且仍然能够将JOIN的对象,子查询等应用到该对象,那么它将给您带来很大的灵活性.

It would give a lot of flexibility i'd think if you have something where you could return an object, that has some query set, and still be able to apply JOIN's to it, subqueries and such.

我到处搜索,只发现了SQL Builder,这看起来非常基础,并且不支持联接.这将是一个真正使它有用的主要功能.

I've search around, and have only found SQL Builder, which seems very basic, and doesn't support joins. Which would be a major feature that would really make it useful.

推荐答案

也许您可以尝试 ORM ,例如 Propel

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...

例如,使用Doctrine可以进行如下连接:

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();

使用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...

这篇关于用于PHP的SQL Builder,是否具有JOIN支持?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆