PHP code example of ozh / sqltableextractor

1. Go to this page and download the library: Download ozh/sqltableextractor library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ozh / sqltableextractor example snippets



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', '[email protected]')"
);
// ['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']