DEV Community

Robin  Dev
Robin Dev

Posted on • Originally published at larachamp.com on

Simple Query Builder

Maybe you know that in Laravel Framework we build queries by using a very convenient approach to build queries. Which is called query builder. Yes, so the same I am trying to do with simple-query-builder in PHP. If you have a core php application then easily you can install the library and use it in your project.

This provides a simple interface to build select, insert, update, or delete queries. You can also use it for queries where we require you to use Joins.

Repository Url: simple-query-builder

Installation

 composer require robinksp/simple-query-builder 
Enter fullscreen mode Exit fullscreen mode

How to Get Connection

It’s simple to build a connection in simple-query-builder

// file: app/connection.php

<?php

use robinksp\querybuilder\Connection;

require 'vendor/autoload.php';

$config = [
    'hostname' => 'localhost',
    'username' => 'root',
    'password' => 'password',
    'database' => 'test'
];
$connection = (new Connection($config))::connect();

Enter fullscreen mode Exit fullscreen mode

How to build a basic query

$selectQuery = (new Query($connection))
    ->table('award_icons')
    ->select('*')
    ->where('id', '=', 33)
    ->get();
Enter fullscreen mode Exit fullscreen mode

The post Simple Query Builder appeared first on Larachamp.

Top comments (0)