承接 nkt/flame 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

nkt/flame

Composer 安装命令:

composer require nkt/flame

包简介

The PDO wrapper with comfortable API for placeholders

README 文档

README

Build Status Coverage Status

The PDO wrapper with comfortable API for placeholders

Installation

Flame requires php 5.4+ and PDO extension.

composer require nkt/flame:~1.0

Usage

<?php

use Flame\Connection;
use Flame\Grammar\MysqlGrammar;

$db = new Connection('mysql:dbname=hello_world', 'user', 'password', [], new MysqlGrammar());
$db->prepare(...);

Idea

Write placeholders types directly in the query

For example:

SELECT * FROM goods g WHERE g.price BETWEEN f:minPrice AND f:maxPrice;
SELECT * FROM users u WHERE u.username = s:username; -- :username also bind as string
SELECT * FROM orders o WHERE o.id = i:id;
SELECT * FROM users u WHERE u.registered >= d:date;

Difference between native PDO placeholders

Unlike PDO you can re-use the same placeholder as long as necessary. Also you have to specifying the type of the placeholder just once.

$users = $flame->prepare(
    'SELECT * FROM users WHERE age >= i:age OR (registered < d:registered AND age = :age)'
)->execute(['age' => $age]);

You don't need cast every integer values, Flame do it for you.

$stmt = $flame->prepare('SELECT * FROM users WHERE id = i:id)');
$users = $stmt->execute(['id' => $_POST['id']]);

Every query execution Flame tests value is null and if it is, change placeholder type to PDO::PARAM_NULL.

$stmt = $flame->prepare('INSERT INTO users VALUES(s:username, d:last_login))');
$users = $stmt->execute(['username' => 'John Doe', 'last_login' => null]);

Flame add new types: date and time. You can bind this data as DateTime, string or int.

Placeholder types

Placeholder Type
s string
i integer
f float
b boolean
l blob
d datetime
t time

Query builder

Flame also provide powerful query builder. Connection provide base wrappers:

  • Connection::select(string $column...)
  • Connection::update(string $table, array $columns)
  • Connection::insert(string $table, array $columns)

Every sql statement provides by method with same name in camelCase.

Examples:

$posts = $db->prepare(
    $db->select('p.id', 'p.title', 'p.content')
       ->from('posts p')
       ->join('post_tags pt', 'p.id', 'pt.post_id')
       ->join('tags t', 't.id', 'pt.tag_id')
       ->where(function ($e) {
           $e->equal('t.name', ':tag');
       })
)->execute(['tag' => $tag]);

$db->prepare($db->insert('users', [
        'username'   => ':name',
        'password'   => ':pass',
        'registered' => 'd:now'
    ]))->execute([
        'name' => $name,
        'pass' => $pass,
        'now'  => new \DateTime()
   ]);

License

MIT

统计信息

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

GitHub 信息

  • Stars: 21
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-04-20

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固