phith0n / ctfdbbuilder
a database query builder for CTFer
0.1.1
2018-05-27 18:47 UTC
Requires
- php: >=7.0
- pimple/pimple: ^3.2
This package is auto-updated.
Last update: 2024-04-20 03:43:09 UTC
README
一个无任何防护的PHP数据库Builder,支持Mysql/Postgresql/Sqlite。
Install
composer require phith0n/ctfdbbuilder:dev-master
Usage
<?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();
Select (SQL injection)
<?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();