PHPackages                             ozh/sqltableextractor - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. ozh/sqltableextractor

ActiveLibrary[Database &amp; ORM](/categories/database)

ozh/sqltableextractor
=====================

Extract table names from SQL queries (SELECT, INSERT, UPDATE, JOIN, subqueries)

v1.0.1(5mo ago)15MITPHPPHP &gt;=7.4CI passing

Since Jan 21Pushed 5mo agoCompare

[ Source](https://github.com/ozh/SQLTableExtractor)[ Packagist](https://packagist.org/packages/ozh/sqltableextractor)[ RSS](/packages/ozh-sqltableextractor/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (3)Used By (0)

SQLTableExtractor
=================

[](#sqltableextractor)

A lightweight PHP library to extract table names from SQL queries.

Features
--------

[](#features)

- ✅ Supports SELECT, INSERT, UPDATE queries
- ✅ Handles all JOIN types (INNER, LEFT, RIGHT, FULL, CROSS)
- ✅ Extracts tables from subqueries
- ✅ Removes SQL comments and string literals
- ✅ Cleans table names (backticks, quotes, database prefixes)
- ✅ Manages table aliases
- ✅ Zero dependencies

Installation
------------

[](#installation)

```
composer require --prefer-dist ozh/sqltableextractor
```

Usage
-----

[](#usage)

```
use Ozh\SQLTableExtractor\SqlTableExtractor;
$extractor = new SqlTableExtractor();

$query = "SELECT u.*, o.* FROM users u LEFT JOIN orders o ON u.id = o.user_id";
$tables = $extractor->extractTables($query);

## Examples
print_r($tables);
// Output: ['users', 'orders']
```

```
$extractor = new SqlTableExtractor();
$tables = $extractor->extractTables(

// Simple SELECT
$tables = $extractor->extractTables("SELECT * FROM users WHERE id = 1");
// ['users']

// Multiple JOINs
$tables = $extractor->extractTables(
    "SELECT * FROM table1 t1
     INNER JOIN table2 t2 ON t1.id = t2.id
     LEFT JOIN table3 t3 ON t2.id = t3.id"
);
// ['table1', 'table2', 'table3']

// INSERT
    "INSERT INTO customers (name, email) VALUES ('John', 'john@example.com')"
);
// ['customers']

// UPDATE with subquery
$tables = $extractor->extractTables(
    "UPDATE products SET price = 100
     WHERE category_id IN (SELECT id FROM categories WHERE name = 'Electronics')"
);
// ['products', 'categories']

// Database prefix
$tables = $extractor->extractTables("SELECT * FROM `mydb`.`users`");
// ['users']
```

Requirements
------------

[](#requirements)

- PHP 7.4 or higher

License
-------

[](#license)

Do whatever the hell you want with it. Or,
MIT License - See [LICENSE](LICENSE) file for details

###  Health Score

31

—

LowBetter than 66% of packages

Maintenance71

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

164d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/223647?v=4)[྅༻ Ǭɀħ ༄༆ཉ](/maintainers/ozh)[@ozh](https://github.com/ozh)

---

Top Contributors

[![ozh](https://avatars.githubusercontent.com/u/223647?v=4)](https://github.com/ozh "ozh (3 commits)")

---

Tags

mysqlsqlsql-parsertablesparsermysqlsqlextractortables

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ozh-sqltableextractor/health.svg)

```
[![Health](https://phpackages.com/badges/ozh-sqltableextractor/health.svg)](https://phpackages.com/packages/ozh-sqltableextractor)
```

###  Alternatives

[doctrine/dbal

Powerful PHP database abstraction layer (DBAL) with many features for database schema introspection and management.

9.7k605.0M6.8k](/packages/doctrine-dbal)[greenlion/php-sql-parser

A pure PHP SQL (non validating) parser w/ focus on MySQL dialect of SQL

64112.4M103](/packages/greenlion-php-sql-parser)[catfan/medoo

The lightweight PHP database framework to accelerate development

5.0k1.6M204](/packages/catfan-medoo)[phpmyadmin/sql-parser

A validating SQL lexer and parser with a focus on MySQL dialect.

48252.2M78](/packages/phpmyadmin-sql-parser)[ifsnop/mysqldump-php

PHP version of mysqldump cli that comes with MySQL

1.3k6.0M77](/packages/ifsnop-mysqldump-php)[cycle/orm

PHP DataMapper ORM and Data Modelling Engine

1.3k918.4k79](/packages/cycle-orm)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
