zonuexe/tetosql

简单安全的SQL模板

0.5.5 2022-09-02 16:14 UTC

This package is auto-updated.

Last update: 2024-08-30 01:17:33 UTC


README

Test lang:PHP 8.1 lang:PHP 5.4

PHP数据对象(PDO)包装器和SQL模板

特性

  • PDO包装器
  • 查询模板
    • 类型安全
    • 值序列

手册

日语:为忧郁的SQL准备的,或者和PDO做好朋友,垫高枕头好好睡觉

语法

类型

  • @int - 整数值(-9223372036854775808 <= n <=9223372036854775807
  • @int[] - 整数序列
  • @string - 字符串
  • @string[] - 字符串序列
  • @lob - 大对象
  • @ascdesc - "ASC""DESC""asc""desc"

示例

<?php

namespace MyApp;

use Teto\SQL\Query;

$conn = new \PDO('sqlite:/tmp/db.sq3', null, null, [\PDO::ATTR_PERSISTENT => true]);
$data = Query::execute(
    $conn,
    <<<'SQL'
        SELECT * FROM `users`
        WHERE `status` IN (:statuses@int[])
        LIMIT :offset@int, :limit@int
    SQL,
    [
        ':statuses' => [1, 3],
        ':offset'   => 60,
        ':limit'    => 30,
    ]
)->fetch(\PDO::FETCH_ASSOC);

版权

TetoSQL 采用 Mozilla公共许可证版本2.0

Simple and secure SQL templating
Copyright (c) 2019 USAMI Kenta <tadsan@zonu.me>

PxvSql

TetoSQL 是从 pixiv Inc. 的私有库 PxvSql 分支(并调整)而来的。

PHP手册

PDOInterface.phpPDOStatementInterface.php 基于 PHP手册(英文)

版权 © 1997 - 2016 由PHP文档组所有。此材料只能根据Creative Commons Attribution 3.0许可证或更高版本的条件分发。Creative Commons Attribution 3.0许可证的副本与手册一起分发。最新版本可在» http://creativecommons.org/licenses/by/3.0/找到。