Download the PHP package romainbessugesmeusy/php-sql-query without Composer

On this page you can find all versions of the php package romainbessugesmeusy/php-sql-query. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package php-sql-query

SQL Query Abstraction Layer

The php-sql-query package aims to provide a consistent abstraction layer for SQL query construction. It's divided in two parts:

  1. abstract query components (columns, tables, limit, groups)
  2. renderers (MySQL, PgSql, Sql Server)

Creating a select is really straightforward:

To output the correct query according to the database system in use, you'll have to instanciate the renderer, and call its render method:

This will print the following string:

Hopefully, you don't have to be that verbose to get the job done.

Filtering

In this API there's no ->where() method, instead, there's ->filter() which returns a \RBM\SqlQuery\Filter object. This object provides some basic methods :

There are also less basic methods such as :

All of these are chainable for readability and effortless development sake.

Of course, you can determine which operator you want, and nest clauses:

Result:

SELECT & JOINS

A JOIN is a SELECT. In fact, there is no \RBM\SqlQuery\Join class and there won't be.

$select = new Select('project', ['project_id', 'name']);
$owner = $select->join('user', 'owner_id', 'user_id');
print_r($owner);

Gives us

RBM\SqlQuery\Select Object
(
    [_table:protected] => RBM\SqlQuery\Table Object
        (
            [_name:protected] => user
…

The most effective advantage of considering J0IN as SELECT is reusability. Let say you have an entity that provides some selects.

class UserEntity 
{

    public function getSelectForActiveUsers()
    {
        $select = new Select('user');
        $select->filter()->equals('active', 1);
        return $select;
    }

}   

class ProjectEntity 
{

    public function getSelectForProjectsOfActiveUsers()
    {
        $userEntity = new UserEntity();
        $select = new Select('project');
        $select->addJoin($userEntity->getSelectForActiveUsers(), 'owner_id', 'user_id');
    }   
}

Overloading and inheritance

One intersting feature of this package is that it can be extended to customize the query and filter layer. The finality of inheritance is to objectify the query construction, by making it fluent and business oriented.

Select

While extending selects, you'll discover that the first obvious usage is to define shortcuts for joins:

class ProjectSelect extends \RBM\SqlQuery\Select
{
    // overloading the table (simple way)
    protected $_table = 'project';

    public function owner()
    {
        return $this->join('user', 'owner_id', 'user_id');
    }
}

Usage:

$projects = new ProjectSelect();
$projects->owner()->filter()->equals('user_id', 1);

Filter

Creating a filter for our project table is straightforward:

class ProjectFilter extends \RBM\SqlQuery\Filter
{
    public function deleted($deleted)
    {
        return ($deleted) ? $this->isNull('date_deleted') : $this->isNotNull('date_deleted');
    }
}

To use this filter, you'll have to modified the filterClass property from the select:

$projects = new ProjectSelect();
$projects->filter()->deleted(true);

All versions of php-sql-query with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package romainbessugesmeusy/php-sql-query contains the following files

Loading the files please wait ....