Giter Club home page Giter Club logo

querybuilder's Introduction

QueryBuilder

A dead simple PHP 5 OO interface for building SQL queries. No manual string concatenation necessary.

Developed by Justin Stayton while at Monk Development.

Requirements

  • PHP 5.1.0 or newer.

Getting Started

To start, make sure to add the class to your autoloader or require it directly:

require "QueryBuilder.php";

Composing a query with QueryBuilder is very similar to writing the SQL by hand, as many of the directives map directly to methods:

$QueryBuilder = new QueryBuilder();
$QueryBuilder->select('*')
             ->from('shows')
             ->innerJoin('episodes', 'show_id')
             ->where('shows.network_id', $networkId)
             ->orderBy('episodes.aired_on', QueryBuilder::ORDER_BY_DESC)
             ->limit(20);

Now that the query is built,

$QueryBuilder->getQueryString();

returns the full SQL query string with placeholders (?), and

$QueryBuilder->getPlaceholderValues();

returns the array of placeholder values that can then be passed to your database connection or abstraction layer of choice. Or, if you'd prefer it all at once, you can get the query string with values already safely quoted:

$QueryBuilder->getQueryString(false);

If you're using PDO, however, QueryBuilder makes executing the query even easier:

$PDOStatement = $QueryBuilder->query();

QueryBuilder works directly with your PDO connection, which can be passed during creation of the QueryBuilder object

$QueryBuilder = new QueryBuilder($PDO);

or after

$QueryBuilder->setPdoConnection($PDO);

Methods

SELECT

FROM

WHERE

GROUP BY

HAVING

ORDER BY

LIMIT

Query

Utility

Feedback

Please open an issue to request a feature or submit a bug report. Or even if you just want to provide some feedback, I'd love to hear. I'm also available on Twitter as @jstayton.

querybuilder's People

Contributors

charud avatar jstayton avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.