@@ -10,20 +10,37 @@ How does it work?
1010Easy! You write the query with all possible parameters.
1111
1212``` php
13+ use Mouf\Database\MagicQuery;
14+
1315$sql = "SELECT * FROM users WHERE name LIKE :name AND country LIKE :country";
1416
1517// Get a MagicQuery object.
1618$magicQuery = new MagicQuery();
1719
1820// Let's pass only the "name" parameter
1921$result = $magicQuery->build($sql, [ "name" => "%John%" ]);
20- // $result = SELECT * FROM users WHERE name LIKE '%John'
22+ // $result = SELECT * FROM users WHERE name LIKE '%John% '
2123
2224// Let's pass no parameter at all!
2325$result2 = $magicQuery->build($sql, []);
2426// $result2 = SELECT * FROM users
2527```
2628
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+
2744Why should I care?
2845------------------
2946
@@ -68,3 +85,22 @@ version of the php-sql-parser library) and then changed into a tree.
6885The magic happens on the tree where the node containing unused parameters
6986are simply discarded. When it's done, the tree is changed back to SQL and
7087"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