@@ -10,20 +10,37 @@ How does it work?
10
10
Easy! You write the query with all possible parameters.
11
11
12
12
``` php
13
+ use Mouf\Database\MagicQuery;
14
+
13
15
$sql = "SELECT * FROM users WHERE name LIKE :name AND country LIKE :country";
14
16
15
17
// Get a MagicQuery object.
16
18
$magicQuery = new MagicQuery();
17
19
18
20
// Let's pass only the "name" parameter
19
21
$result = $magicQuery->build($sql, [ "name" => "%John%" ]);
20
- // $result = SELECT * FROM users WHERE name LIKE '%John'
22
+ // $result = SELECT * FROM users WHERE name LIKE '%John% '
21
23
22
24
// Let's pass no parameter at all!
23
25
$result2 = $magicQuery->build($sql, []);
24
26
// $result2 = SELECT * FROM users
25
27
```
26
28
29
+ Installation
30
+ ------------
31
+
32
+ Simply use the composer package:
33
+
34
+ ``` json
35
+ {
36
+ "require" : {
37
+ "mouf/magic-query" : " ~1.0"
38
+ },
39
+ "minimum-stability" : " dev" ,
40
+ "prefer-stable" : true
41
+ }
42
+ ```
43
+
27
44
Why should I care?
28
45
------------------
29
46
@@ -68,3 +85,22 @@ version of the php-sql-parser library) and then changed into a tree.
68
85
The magic happens on the tree where the node containing unused parameters
69
86
are simply discarded. When it's done, the tree is changed back to SQL and
70
87
"shazam!", your SQL query is purged of useless parameters!
88
+
89
+ Is it a MySQL only tool?
90
+ ------------------------
91
+
92
+ No. By default, your SQL is parsed and then rewritten using the MySQL dialect, but you use any kind of dialect
93
+ known by Doctrine DBAL. Magic-query optionally uses Doctrine DBAL. You can pass a ` Connection ` object
94
+ as the first parameter of the ` MagicQuery ` constructor. Magic-query will then use the matching dialect.
95
+
96
+ For instance:
97
+
98
+ ``` php
99
+ $config = new \Doctrine\DBAL\Configuration();
100
+ $connectionParams = array(
101
+ 'url' => 'sqlite:///somedb.sqlite',
102
+ );
103
+ $conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
104
+
105
+ $magicQuery = new \Mouf\Database\MagicQuery($conn);
106
+ ```
0 commit comments