Git Product home page Git Product logo

php-helpers's Introduction

PHP-Helpers

Standalone PHP7 helpers for sql parametrization and safe condition composition, also redis and sqlserver sane interfaces.

All code requires utils.php containing generic utility functions, other files can be used independently.

Sql block definitions and parser (sql.php)

ISqlBlock

Generic interface for everything producing a parametrized statement (has SQL and Params).

SqlBlock

Simple text and array block implementation.

SqlOrder

Order by block, parse can read objects in format:

["Field1", "Field2 asc", "Field3 desc"]

asc is implied if missing.

SqlWhere

Where block, parse can read objects in format:

whereBin: {
    field: string,
    op: '=' | '>' | '<' | '<>' | '>=' | '<=' | 'like' | 'is',
    val: string|number|bool
};
whereLogic: {
    op: 'AND' | 'OR',
    blocks: [whereOp]
};
whereOp: whereBin | whereLogic;

Block with op == '' is considered TRUE.

Param

This object represents a named parameter, in case of blocks rapresents a named bind, in case of templates it is a parametrized block (so parameter of a sql query, not to be used for unsanitized user input).

Use toBlock to convert to sql parameter when used in templates.

SqlTemplate

Sql factory with parameters.

Query construction is deferred to allow block parameter binding, so this is not an instance of ISqlBlock, but it returns one when calling generate().

Use mergeBlockParams and mergeParams to bind parameters.

There are useful static functions for select, insert, delete, and update.

SqlSrv (sqlsrv.php)

\SqlSrv\Connection mimics mysqli object oriented connection and statement.

Requires mssql plugin

RedisScript (redis.php)

Class to wrap long REDIS scripts (LUA) to avoid resending to server (tryes to use sha and sends script if it fails).

Requires redis plugin

php-helpers's People

Contributors

dariodaf 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.