一个无任何防护的PHP数据库Builder,支持Mysql/Postgresql/Sqlite。
composer require phith0n/ctfdbbuilder:dev-master
<?php
include 'vendor/autoload.php';
$connect = new \CTFDBBuilder\Connection('mysql', [
'driver' => 'mysql', // Db driver
'host' => 'localhost',
'database' => 'your-database',
'username' => 'root',
'password' => 'your-password',
'charset' => 'utf8mb4', // Optional
'options' => [ // PDO constructor options, optional
\PDO::ATTR_TIMEOUT => 5,
\PDO::ATTR_EMULATE_PREPARES => false,
],
]);
$builder = $connect->getBuilder();
<?php
$article = $builder->table('articles')->where('id', '=', $_GET['id'])->first();
<?php
$article = $builder->table('users')->where('age', '>', $_GET['age'])->first();
<?php
$article = $builder->table('users')->orderBy('age', 'desc')->get();
<?php
$article = $builder->table('users')->select('COUNT() AS `cnt`')->first();
<?php
$article = $builder->table('users')->where('username', $_POST['username'])->where('password', md5($_POST['password']))->first();