Is there a way to split an SQL command into it's parts?

Viewed 37

ie:

SELECT * FROM table WHERE blah JOIN test AS t2 ON (table.id = test.id) GROUP BY user ORDER BY id

into:

[
    "SELECT" => "*",
    "FROM" => ["table" => "table", "AS" => "table"],
    "WHERE" => "blah",
    "JOIN" => ["table" => "test", "AS" => "t2", "ON" => "(table.id = test.id)"],
    "GROUP BY" => "user",
    "ORDER BY" => ["field" => "id", "order" => "ASC"],
]

Is there a way to get how MYSQLI/PHP sees it, or would I have to make a parser myself which isn't guaranteed to parse it the same way

1 Answers
Related