2017 © Pedro Peláez
 

library dbescaper

Database wrapper to escape properly, allowing meaningful queries with parametrized values

image

neoparla/dbescaper

Database wrapper to escape properly, allowing meaningful queries with parametrized values

  • Saturday, November 25, 2017
  • by htw
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

DbEscaper

Build Status, (*1)

Database wrapper to escape properly, allowing meaningful queries with parametrized values, (*2)

Getting started

Install it through composer with, (*3)

composer require neoparla/dbescaper

First step: connect

To create an instance just initialize it with connection data., (*4)

$db_escaper = DbEscaper::init(
    array(
        'host' => 'host',
        'user'  => 'user',
        'pass'  => 'pass',
        'schema'    => 'schema',
        // 'port' => 3306
    )
);

By default it will connect through port 3306., (*5)

Basic queries

To run a basic query, just DbEscaper::query., (*6)

$db_escaper->query('show tables');

Statements

To avouid unwanted queries to be executed (aka SQLInjection) use DbEscaper::prepare()., (*7)

$statement = $db_escaper->prepare($sql, $query_label);

You can bind following types of data. * Double No transform * Integer No transform * String * Field * Tuple, (*8)

Binding::String

It'll escape strings (such as quotes) and wrapp it with quotes, (*9)

$value = "string with quotes (') and slashes (\)";
DbStatement->bindParam(':binding', $value, Binding::String);
// Real query: 'string with quotes (\') and slashes (\\)'

Binding::Field

It'll ensure valid MySQL field name and wrap it with backtips, (*10)

$value = "field_name";
DbStatement->bindParam(':binding', $value, Binding::Field);
// Real query: `field_name`

Binding::Tuple

It'll ensure all values are valid and will transform them if needed., (*11)

$value = new DbTuple(Binding::PARAM_STRING, array('string 1', 'string 2'), DbTuple::WITH_PARENTHESIS);;
DbStatement->bindParam(':binding', $value, Binding::Tuple);
// Real query: ( 'string 1', 'string 2' )

DbTuple class

To bind tuples you must use DbTuple class., (*12)

Binding::Double and Binding::Integer

These kind of bindings won't perform any transformation. It'll just check correct data type., (*13)

The Versions

25/11 2017

dev-master

9999999-dev

Database wrapper to escape properly, allowing meaningful queries with parametrized values

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-mysqli *

 

The Development Requires

by Pau Perez

25/11 2017

1.0.1

1.0.1.0

Database wrapper to escape properly, allowing meaningful queries with parametrized values

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-mysqli *

 

The Development Requires

by Pau Perez

11/04 2015

1.0.0

1.0.0.0

Database wrapper to escape properly, allowing meaningful queries with parametrized values

  Sources   Download

MIT

The Requires

  • php >=5.3
  • ext-mysqli *

 

The Development Requires

by Pau Perez

03/12 2014

0.1.1

0.1.1.0

Database wrapper to escape properly, allowing meaningful queries with parametrized values

  Sources   Download

proprietary

The Requires

  • ext-mysqli *

 

03/12 2014

0.1.0

0.1.0.0

Database wrapper to escape properly, allowing meaningful queries with parametrized values

  Sources   Download

proprietary

The Requires

  • ext-mysqli *