0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

良い感じのphpのクエリビルダを探して

Posted at

さくっとphpを書く時に、フレームワークを導入するまでも・・・。な時に一番困るのがmysql用のライブラリ。直書きはちょっとめんどい。と言うわけで良い感じのクエリビルダを今のうちに探してメモしておくまん。

シンプル。グループの記法が個人的に結構好み。

QB::table('my_table')
            ->where('my_table.age', 10)
            ->where(function($q)
                {
                    $q->where('name', 'LIKE', '%usman%');
                    // You can provide a closure on these wheres too, to nest further.
                    $q->orWhere('description', 'LIKE', '%usman%');
                });

複数joinもグループと同じ感じでいけるのが良い。扱いやすそう。

->join('another_table', function($table)
    {
        $table->on('another_table.person_id', '=', 'my_table.id');
        $table->on('another_table.person_id2', '=', 'my_table.id2');
        $table->orOn('another_table.age', '>', QB::raw(1));
    })

他にも色々探しているけれど、joinまで出来てわかりやすいのがなかなかないのがねぇ。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?