File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -42,14 +42,22 @@ echo SqlParser\Utils\Formatter::format($query, array('type' => 'html'));
4242### Parsing and building SQL query
4343
4444``` php
45- $parsed = new SqlParser\Parser($query) ;
45+ require __DIR__."/vendor/autoload.php" ;
4646
47- // you can now inspect or change query
48- var_dump( $parser->statements[0] );
47+ $query1 = "select * from a";
48+ $parser = new SqlParser\Parser($query1 );
4949
50- // and build it again
50+ // inspect query
51+ var_dump($parser->statements[0]); // outputs object(SqlParser\Statements\SelectStatement)
52+
53+ // modify query by replacing table a with table b
54+ $table2 = new \SqlParser\Components\Expression("", "b", "", "");
55+ $parser->statements[0]->from[0] = $table2;
56+
57+ // build query again from an array of object(SqlParser\Statements\SelectStatement) to a string
5158$statement = $parser->statements[0];
52- $statement->build()
59+ $query2 = $statement->build();
60+ var_dump($query2); // outputs string(19) "SELECT * FROM `b` "
5361```
5462
5563## More information
You can’t perform that action at this time.
0 commit comments