Skip to content

Instantly share code, notes, and snippets.

@memememomo
Created July 7, 2014 05:19
Show Gist options
  • Save memememomo/89c6b6739a09ce7b5a33 to your computer and use it in GitHub Desktop.
Save memememomo/89c6b6739a09ce7b5a33 to your computer and use it in GitHub Desktop.
PHP版SQL::MakerでJSON SQL Injectionの対応版を出しました ref: http://qiita.com/uchiko/items/490aee47362ca39d603a
$builder = new SQL_Maker(array('driver' => 'mysql', 'strict' => 1));
$builder->select('user', array('*'), array('name' => sql_in(array('foo', 'bar'))));
// => SELECT * FROM `user` WHERE `name` IN (?, ?)
<?php
//「http://domain/sample4.php?id[TEST]=1」というURLでアクセス
// 数値が入る想定だが、
// この場合は array('TEST' => 1) になる。
$id = $_GET['id'];
$builder = new SQL_Maker(array(
'driver' => 'mysql'
));
$table = 'user';
$column = array('id', 'name');
$where = array('id' => $id);
list($sql, $binds) = $builder->select($table, $column, $where);
// => SELECT `id`, `name` FROM `user` WHERE (`id` TEST ?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment