A PHP-based SQL query analyzer that helps identify potential issues and optimize your SQL queries. The tool checks for common SQL anti-patterns and provides suggestions for improvement.
- Detects common SQL issues and anti-patterns
- Customizable rule-based analysis
- Simple web interface
- RESTful API endpoint for programmatic access
- Supports multiple SQL query analysis rules
- PHP 8.0 or higher
- Composer (Dependency Manager for PHP)
- Web server (Apache/Nginx) or PHP's built-in development server
- If you want run server by Docker, just need Docker desktop in your computer.
-
Clone the repository
git clone https://github.com/TinBui99/sql-analyzer.git cd sql-analyzer -
Docker setup
docker compose up -d --build
-
Install dependencies
docker exec -it {{container_name}} bash composer installThen open
http://localhost:8090in your browser.
- Open the application in your web browser
- Enter your SQL query in the provided text area
- (Optional) Select specific rules to apply
- Click "Analyze" to check for issues
You can also use the analyzer programmatically via the API:
# Using cURL
curl -X POST http://your-domain/analyze \
-d "sql=SELECT * FROM users WHERE id = 1" \
-d "rules[]=SelectStarRule&rules[]=NoIndexRule"Response Format:
{
"success": true,
"issue": ["Issue description 1", "Issue description 2"],
"warning": ["Warning message 1"],
"error": []
}The analyzer comes with several built-in rules:
- SelectStarRule: Warns against using
SELECT *in queries - MissingWhereClauseRule: Identifies queries without a WHERE clause on UPDATE/DELETE
- NoIndexRule: Checks for missing indexes on filtered columns
- LimitOffsetRule: Warns about potential performance issues with large OFFSET values
- Create a new rule class in
app/Rules/that implementsRuleInterface - Add your rule class to the
$availableRulesarray inSqlAnalyzer.php - The rule will be automatically loaded and available for use
For support, please open an issue in the GitHub repository.
