1
+ [ ![ Latest Unstable Version] ( https://poser.pugx.org/mouf/magic-query/v/unstable )] ( https://packagist.org/packages/mouf/magic-query )
2
+ [ ![ License] ( https://poser.pugx.org/mouf/magic-query/license )] ( https://packagist.org/packages/mouf/magic-query )
1
3
[ ![ Scrutinizer Code Quality] ( https://scrutinizer-ci.com/g/thecodingmachine/magic-query/badges/quality-score.png?b=1.0 )] ( https://scrutinizer-ci.com/g/thecodingmachine/magic-query/?branch=1.0 )
2
4
[ ![ Build Status] ( https://travis-ci.org/thecodingmachine/magic-query.svg?branch=1.0 )] ( https://travis-ci.org/thecodingmachine/magic-query )
3
5
[ ![ Coverage Status] ( https://coveralls.io/repos/thecodingmachine/magic-query/badge.svg?branch=1.0 )] ( https://coveralls.io/r/thecodingmachine/magic-query?branch=1.0 )
@@ -24,10 +26,12 @@ $magicQuery = new MagicQuery();
24
26
// Let's pass only the "name" parameter
25
27
$result = $magicQuery->build($sql, [ "name" => "%John%" ]);
26
28
// $result = SELECT * FROM users WHERE name LIKE '%John%'
29
+ // Did you notice how the bit about the country simply vanished?
27
30
28
31
// Let's pass no parameter at all!
29
32
$result2 = $magicQuery->build($sql, []);
30
33
// $result2 = SELECT * FROM users
34
+ // The whole WHERE condition disappeared because it is not needed anymore!
31
35
```
32
36
33
37
Installation
@@ -71,7 +75,7 @@ if (isset($params['country'])) {
71
75
```
72
76
73
77
Concatenating SQL queries is ** dangerous** (especially if you forget to protect parameters).
74
- You can always use parameterized SQL queries, but you will still have to concatenate the filters.
78
+ You can always use parametrized SQL queries, but you will still have to concatenate the filters.
75
79
76
80
To avoid concatenating strings, frameworks and libraries have used different strategies. Building a full ORM (like
77
81
Doctrine or Propel) is a good idea, but it makes writing complex queries even more complex. Other frameworks like
0 commit comments