定制 neoparla/dbescaper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

neoparla/dbescaper

最新稳定版本:1.0.1

Composer 安装命令:

composer require neoparla/dbescaper

包简介

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

README 文档

README

Build Status

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

Getting started

Install it through composer with

composer require neoparla/dbescaper

First step: connect

To create an instance just initialize it with connection data.

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

By default it will connect through port 3306.

Basic queries

To run a basic query, just DbEscaper::query.

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

Statements

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

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

You can bind following types of data.

  • Double No transform
  • Integer No transform
  • String
  • Field
  • Tuple

Binding::String

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

$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

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

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

Binding::Double and Binding::Integer

These kind of bindings won't perform any transformation. It'll just check correct data type.

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-11