View on GitHub

latitude

A SQL query builder with zero dependencies

Introduction

Latest Stable Version License Build Status Code Coverage Code Quality

Latitude is a SQL query builder with zero dependencies and a fluent interface. It supports most of SQL-92 as well as database specific functionality:

use Latitude\QueryBuilder\Engine\CommonEngine;
use Latitude\QueryBuilder\QueryFactory;

use function Latitude\QueryBuilder\field;

$factory = new QueryFactory(new CommonEngine());
$query = $factory
    ->select('id', 'username')
    ->from('users')
    ->where(field('id')->eq(5))
    ->compile();

$query->sql(); // SELECT "id" FROM "users" WHERE "id" = ?
$query->params(); // [5]

Documentation

Latitude includes both a query builder and a powerful set of escaping helpers. The query builder allows the fluent generation of SELECT, INSERT, UPDATE, and DELETE statements. The escaping helpers assist in protecting against SQL injection and identifier quoting for MySQL, SQL Server, Postgres, and other databases that follow SQL standards.

Getting Started

Criteria

Query Types

Booleans and Nulls

In INSERT and UPDATE queries, boolean and null values will be added directly the query, rather than as placeholders. This is due to the fact that PDOStatement::execute($params) will attempt to cast all parameters to strings, which does not work correctly with booleans or nulls.

See PDOStatement::execute documentation for more information.