Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,31 @@ string(9) "Customers"
```


How to retrieve the query's tables:
How to retrieve the query's tables (including aliases used in the query):
```php
$parser->getAllTables();
```
Output
```
array(1) {
[0]=>
string(9) "Customers"
[0]=> string(9) "Customers",
[1]=> string(5) "Alias"
}
```


How to retrieve the query's tables (without aliases used in the query):
```php
$parser->getAllTablesWithoutAliases();
```
Output
```
array(1) {
[0]=> string(9) "Customers"
}
```


### Fields
How to retrieve the query's fields:
```php
Expand Down Expand Up @@ -102,10 +115,10 @@ array(2) {
| getMethod | param $query<br> return string | Get SQL Query method |
| getFields | param $query<br> return array | Get Query fields (at the moment only SELECTINSERTUPDATE) |
| getTable | param $query<br> return string | Get SQL Query First Table |
| getTables | return array | Get SQL Query Tables |
| getTables | return array | Get SQL Query Tables (including aliases) |
| getTablesWithoutAliases | return array | Get SQL Query Tables (without aliases) |
| getJoinTables | return array | Get SQL Query Join Tables |
| hasJoin | return bool | Return if has join tables |
| getSubQueries | return array | Get all SELECT subqueries |
| hasSubQueries | return bool | Return if has subqueries |


16 changes: 16 additions & 0 deletions src/LightSQLParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,22 @@ function getAllTables() {
return array_unique($results);
}

/**
* Get SQL Query Tables without aliases
* @return array
*/
function getAllTablesWithoutAliases() {
$raw = $this->getAllTables();
$return = [];
foreach ($raw as $thistable) {
if (str_contains($thistable, " ")) {
$thistable = explode(" ", $thistable)[0];
}
$return[] = $thistable;
}
return $return;
}

/**
* Join tables.
* @return array
Expand Down