Download the PHP package smalldb/flupdo without Composer

On this page you can find all versions of the php package smalldb/flupdo. 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 flupdo

Flupdo

Flupdo is dumb SQL query builder written in PHP. It is designed to be simple, deterministic, transparent and easy to use. Flupdo contains no smart logic which is usually unpredictable when small mistakes occur.

Flupdo supports (or should support) 100% of MySQL syntax. Sqlite and SphinxQL is also supported, but not well tested. PostgreSQL support is planned, probably only minor tweaks will be required, so it may be usable already.

Flupdo is built on top of PDO. It does not replace fetch methods nor any other PDO API, it only adds few builder methods which create query builder object, so full compatibility with PDO is preserved. When query is executed, ordinary PDOStatement instance is returned.

Flupdo supports both positional and named placeholders, but they cannot be mixed. Positional placeholders are useful when their values are passed to the query builder together with SQL statements (see Basic usage section). Named placeholders are to be used with prepared query, where values are passed all at once (see Prepared query section).

Flupdo is tested using PHPT, the tool used by PHP itself. See test directory.

Flupdo is documented using Doxygen -- make doc will do the trick.

Flupdo does not provide smart constructions and helpers to build common queries. Such features are out of Flupdo's scope. Flupdo is intended to be a basic tool used by such helpers and smart query builders to glue queries together. So if you want something smarter, build it on top of Flupdo. For example, Smalldb is such framework.

For more details see the project website: https://smalldb.org/

Basic usage

All builder methods accept SQL fragment as the first argument and parameters as any additional arguments. For example:

$q->where('id = ?', $id);

It will add condition (id = ?) to WHERE clause and append $id to parameter list. So the whole query will look like this:

SELECT ...
WHERE ... AND (id = ?)

To execute query you can use query() or exec() method. They have same semantics as PDO::query() and PDO::exec(), but they do not accept any arguments since the query is already contained in query builder. For example, to execute the query above use this:

$pdostmt = $q->query();

And then result can be fetched as usual:

print_r($pdostmt->fetchAll(PDO::FETCH_ASSOC));

Prepared query

When query should be prepared for multiple use, it is better to use named placeholders:

$pdostmt = $q->insert()->into('users')
        ->set('name = :name')
        ->set('password = :password')
        ->prepare();

And then it can be easily executed over and over:

$flupdo->beginTransaction();
foreach ($users as $u) {
    $pdostmt->execute(array('name' => $u['name'], 'password' => $u['password']));
}
$flupdo->commit();

Subquery

A short subquery may be passed verbatim to any builder method:

$q->select('(SELECT MAX(`id`) + 1 FROM users) AS `next_id`');

More complex queries should be built by Flupdo and passed to builder method using array as the first argument:

$q2 = $flupdo->select('MAX(`id`) + 1')->from('users');
$q->select(array($q2, 'AS `next_id`'));

Both of these examples will produce the same SELECT statement.

Warning: Positional placeholders must not be used before subquery:

$q->where(array($subquery, ' > ?'), $n); // Good
$q->where(array('n + ? IN ', $subquery), $c); // Bad

Builder methods

Builder methods are of the same name as SQL keywords converted to small camelCase:

There are also commenting methods headerComment() and footerComment() available in all query types. They add simple comment before/after the SQL query. These may be useful to mark position of the query in the code, so the query is easy to find from slow query log:

$q->footerComment(__FILE__.':'.__LINE__);

Complex Joins

Note that joins are considered standalone clauses, not part of FROM clause. This mean that complex joins are not possible, but simple chain of many joins is easy. To build complex FROM clause, specify it verbatim in single from() call:

$q->from('t1, (t2, t3), t4');

This also means, that this code:

$q->from('t1');
$q->join('t2 ...');
$q->from('t3');

... will produce this SQL query:

SELECT ...
FROM t1, t3
JOIN t2 ...

This behavior is intentional, since it simplifies building of complex filtering queries.

Internal Logic

Flupdo's internal logic is very simple, yet powerful. It consists only of few buffers, where builder method calls are stored. Just before query execution, a final query is compiled by arranging content of these buffers in correct order (depending on query), using correct conjunctions and keywords.

The first builder method call (on Flupdo instance) determines type of the query and returns instance of FlupdoBuilder subclass. It is not possible to change type of the query later.

Flupdo does not parse nor understands the SQL fragments. It only uses string-level concatenation. If more complex behavior is needed, feel free to write additional helper methods or higher-level query builder on top of Flupdo.

Examples

These examples are available as tests in test directory.

Initialization:

$flupdo = new Flupdo($dsn, $username, $password); // Same as PDO.

Simple select:

$q = $flupdo->select('n AS TheNumber')
        ->select('n + 1')
        ->distinct()
        ->select('n + 2')
        ->headerComment('Simple select')
        ->from('numbers')
        ->where('n > ?', 5)
        ->where('n < ?', 200)
        ->orderBy('n DESC');

Result query exactly as produced by Flupdo (including whitespace):

    -- Simple select
    SELECT DISTINCT n AS TheNumber,
            n + 1,
            n + 2
    FROM numbers
    WHERE (n > ?)
            AND (n < ?)
    ORDER BY n DESC

More complex example with subselect:

$q = $flupdo->select('n')
        ->from('numbers')
        ->where(array('n >', $flupdo->select('MIN(n) + ?', 2)->from('numbers')))
        ->where('n < ?', 100)
        ->orderBy('n DESC');

Result query exactly as produced by Flupdo (including whitespace):

    SELECT n
    FROM numbers
    WHERE (n > (
                    SELECT MIN(n) + ?
                    FROM numbers
            ))
            AND (n < ?)
    ORDER BY n DESC

Documentation

See https://smalldb.org/doc/flupdo/master/

License

The most of the code is published under Apache 2.0 license. See LICENSE file for details.

Contribution guidelines

Project's primary repository is hosted at https://git.frozen-doe.net/smalldb/flupdo, feel free to submit issues or create merge requests there.


All versions of flupdo with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
ext-pdo Version *
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 smalldb/flupdo contains the following files

Loading the files please wait ....