SQL Builder for PHP, with JOIN support?

后端 未结 10 1887
-上瘾入骨i
-上瘾入骨i 2020-12-19 15:29

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

相关标签:
10条回答
  • 2020-12-19 15:47

    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"

    0 讨论(0)
  • 2020-12-19 15:48

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

    0 讨论(0)
  • 2020-12-19 15:49

    FluentPDO looks nice if you're already using PDO: https://github.com/envms/fluentpdo

    0 讨论(0)
  • 2020-12-19 15:49

    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.

    0 讨论(0)
  • 2020-12-19 15:49

    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

    0 讨论(0)
  • 2020-12-19 15:52

    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.

    0 讨论(0)
提交回复
热议问题