PHP code example of consatan / sqlbuilder

1. Go to this page and download the library: Download consatan/sqlbuilder library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

consatan / sqlbuilder example snippets



use Consatan\SQLBuilder\Bind;
use Consatan\SQLBuilder\Builder;

$sql = <<<SQL
SQL;

$builder = new Builder();

try {
    $stmt = $builder
        ->build('')
        ->build('')
        ->build('')
        ->build('')
        ->run($dbh, $sql);

    foreach ($stmt->fetchAll(\PDO::FETCH_ASSOC) as $row) {
        // do something...
    }
} catch (\InvalidArgumentException $e) {
    // 参数错误才会抛出这个异常,理论上这个异常应该在测试阶段发现
} catch (\PDOException $e) {
    // PDO 查询异常,必须捕获
}

Consatan\SQLBuilder\Builder {
    public __construct(array $config = [])]
    public build(string $label, mixed $bind = [], string $sql = ''): Builder
    public prepare(string $sql, mixed $bind = [], array $driverOptions = []): array
    public run(\PDO $dbh, string $sql, mixed $bind = [], array $driverOptions = []): \PDOStatement
}

public Builder::__construct(array $config = [])

public Builder::build(string $label, mixed $bind = [], string $sql = ''): Builder

public Builder::prepare(string $sql, mixed $bind = [], array $driverOptions = []): array

public Builder::run(\PDO $dbh, string $sql, mixed $bind = [], array $driverOptions = []): \PDOStatement

Consatan\SQLBuilder\Bind {
    public getValues(): array
    final public static int(mixed ...$bind): Bind
    final public static str(mixed ...$bind): Bind
    final public static null(mixed $val = null, mixed ...$bind): Bind
    final public static bool(mixed ...$bind): Bind
    final public static lob(mixed ...$bind): Bind
    final public static assertBindValue(mixed $value): void
    final public static assertArrayBindValue(array $array): void
    final public static assertNamedPlaceholder(string $placeholder): void
    final public static assertPDOParamType(int $type): void
}

public Bind::getValues(): array

final public static Bind::int(mixed ...$bind): Bind

final public static Bind::str(mixed ...$bind): Bind

final public static Bind::null(mixed $val = null, mixed ...$bind): Bind

final public static Bind::bool(mixed ...$bind): Bind

final public static Bind::lob(mixed ...$bind): Bind

final public static Bind::assertBindValue(mixed $bind): void

final public static Bind::assertArrayBindValue(array $array): void

final public static Bind::assertNamedPlaceholder(string $placeholder): void

final public static Bind::assertPDOParamType(int $type): void