Skip to content

Commit 784940e

Browse files
fixup of example in documentation
1 parent f8b2937 commit 784940e

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎README.md‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)