{"id":50768706,"url":"https://github.com/lightning1377/php-sql-intellisense","last_synced_at":"2026-06-11T16:02:48.890Z","repository":{"id":234441455,"uuid":"788902620","full_name":"lightning1377/php-sql-intellisense","owner":"lightning1377","description":"VS Code extension that adds schema-aware MySQL IntelliSense, hovers, linting, and quick SQL execution for PHP projects.","archived":false,"fork":false,"pushed_at":"2026-05-26T20:52:01.000Z","size":838,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-11T06:10:05.664Z","etag":null,"topics":["autocomplete","database","developer-tools","intellisense","linting","mysql","php","typescript","vscode-extension"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lightning1377.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-04-19T10:07:16.000Z","updated_at":"2026-05-26T20:52:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"eb8727a8-a0c9-4f60-8241-61c97682140e","html_url":"https://github.com/lightning1377/php-sql-intellisense","commit_stats":null,"previous_names":["lightning1377/php-sql-intellisense"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/lightning1377/php-sql-intellisense","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightning1377%2Fphp-sql-intellisense","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightning1377%2Fphp-sql-intellisense/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightning1377%2Fphp-sql-intellisense/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightning1377%2Fphp-sql-intellisense/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lightning1377","download_url":"https://codeload.github.com/lightning1377/php-sql-intellisense/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lightning1377%2Fphp-sql-intellisense/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34206492,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-11T02:00:06.485Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["autocomplete","database","developer-tools","intellisense","linting","mysql","php","typescript","vscode-extension"],"created_at":"2026-06-11T16:02:48.290Z","updated_at":"2026-06-11T16:02:48.885Z","avatar_url":"https://github.com/lightning1377.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQL-PHP IntelliSense\n\n[![Visual Studio Marketplace Installs](https://badgen.net/vs-marketplace/i/Siavash.php-sql-intellisense?color=blue\u0026icon=vscode)](https://marketplace.visualstudio.com/items?itemName=Siavash.php-sql-intellisense)\n\nSQL-PHP IntelliSense helps PHP projects write MySQL queries with schema-aware completions, lightweight linting, field hovers, and a quick action for running selected SQL.\n\nThe extension connects to your MySQL database, reads table and column metadata, and uses that schema while you edit SQL strings in PHP files.\n\n\u003cimg src=\"images/php_mysql.png\" alt=\"SQL-PHP IntelliSense icon\" width=\"240\"\u003e\n\n## Features\n\n- Table-name completion in supported MySQL query strings.\n- Field-name completion when the source table can be inferred.\n- Diagnostics for table and field names that do not exist in the connected database.\n- Hover information for known fields, including the MySQL column type.\n- Command palette actions for connecting to MySQL, linting the active file, and clearing stored credentials.\n- Code action for running a selected SQL query and viewing results in a VS Code webview.\n\n## Supported PHP Patterns\n\nSQL extraction currently targets string literals passed to these static calls:\n\n```php\nDatabase::prepare(\"SELECT id, name FROM users\");\nDatabase::getResults(\"SELECT * FROM users\");\nDatabase::getValue(\"SELECT email FROM users WHERE id = :id\");\nDatabase::getRow(\"SELECT * FROM users WHERE id = :id\");\nDatabase::PrepareExecuteTC(\"SELECT * FROM users\");\n```\n\nCurrent limitations:\n\n- Queries must be quoted string literals.\n- The extension is optimized for MySQL.\n- Advanced SQL syntax, aliases, and dynamically constructed queries may not always be understood.\n\n## IntelliSense in Action\n\nBelow is a conceptual example of the completions, diagnostics, and hovers in action:\n\n```php\n// 1. Table Name Completion\nDatabase::prepare(\"SELECT * FROM |\");\n//                               ^ Autocomplete triggers: suggests tables ('users', 'products', 'orders')\n\n// 2. Field Name Completion\nDatabase::prepare(\"SELECT users.| FROM users\");\n//                              ^ Autocomplete triggers: suggests fields from 'users' table\n\n// 3. Diagnostics \u0026 Error Highlighting\nDatabase::prepare(\"SELECT invalid_field FROM users\");\n//                        ~~~~~~~~~~~~~ Diagnostic Error: Field name 'invalid_field' not found in table 'users'\n```\n\n## Underlying Logic \u0026 Algorithmic Design\n\nTo provide fast and context-aware SQL tooling directly within PHP files, the extension implements the following pipeline:\n\n1. **SQL Extraction (Pattern Matching):**\n   The extension scans the PHP files using optimized regular expressions matching specific static query execution patterns (such as `Database::prepare(...)`).\n2. **Context Resolution (Lexical Parsing):**\n   When autocompletion is triggered, a custom lexical parser evaluates the SQL string preceding the cursor. It tracks whitespace, punctuation, and keyword structures to identify whether the cursor is in a `table` context or a `field` context, and automatically maps aliases to their respective tables.\n3. **AST Construction (SQL Parsing):**\n   The extension passes extracting queries to `node-sql-parser` to construct an Abstract Syntax Tree (AST). By analyzing this AST, it resolves the referenced tables and fields to validate query correctness.\n4. **Schema Inspection \u0026 Caching:**\n   Using the configured connection credentials, the extension queries the MySQL database's schema metadata. It caches table names and field maps in-memory to ensure autocomplete suggestions and hover info are displayed with sub-millisecond response times.\n\n## Requirements\n\n- Visual Studio Code `1.84.0` or newer.\n- Access to a MySQL database whose schema should power completions and linting.\n\n## Setup\n\n1. Install the extension.\n2. Open VS Code settings and configure:\n    - `SQL-PHP.Intellisense.database.host`\n    - `SQL-PHP.Intellisense.database.port`\n    - `SQL-PHP.Intellisense.database.name`\n3. Run `SQL-PHP: Connect to MySQL Database` from the command palette.\n4. Enter the database username and password when prompted.\n\nCredentials are stored with VS Code SecretStorage. Run `SQL-PHP: Delete Database Credentials` to clear them.\n\n## Commands\n\n| Command                                | Description                                                          |\n| -------------------------------------- | -------------------------------------------------------------------- |\n| `SQL-PHP: Connect to MySQL Database`   | Connects to the configured MySQL database and loads schema metadata. |\n| `SQL-PHP: Lint MySQL Queries`          | Lints SQL queries in the active PHP document.                        |\n| `SQL-PHP: Delete Database Credentials` | Removes the stored username and password.                            |\n\n## Extension Settings\n\n| Setting                              | Default     | Description                            |\n| ------------------------------------ | ----------- | -------------------------------------- |\n| `SQL-PHP.Intellisense.database.host` | `localhost` | MySQL server host name or IP address.  |\n| `SQL-PHP.Intellisense.database.port` | `3306`      | MySQL server port.                     |\n| `SQL-PHP.Intellisense.database.name` | empty       | Name of the MySQL database to inspect. |\n\n## Development\n\n```sh\nnpm install\nnpm run compile\nnpm run lint\nnpm test\n```\n\nPackage the extension locally with:\n\n```sh\nnpm run vsce\n```\n\nFor manual installation from a VSIX file, see the [VSIX installation guide](docs/SQL-PHP%20Extension%20Guide.pdf).\n\n## Roadmap\n\n- Configurable PHP function/method patterns for SQL extraction.\n- Better support for single-quoted and multiline SQL strings.\n- Workspace-wide linting for PHP files.\n- Broader SQL parser coverage for joins, aliases, and dynamic query fragments.\n\n## Contributing\n\nIssues and pull requests are welcome on the [GitHub repository](https://github.com/lightning1377/php-sql-intellisense).\n\n## License\n\nMIT\n\n## Support the Project ⭐\n\nWith over **5,000+ active installations** on the VS Code Marketplace, this extension is driven entirely by community utility. If this tool saves you a few context-switches or protects you from a broken query deployment today, please consider supporting its ongoing development:\n\n- **Star this repository** to improve its visibility on GitHub so other developers can discover it.\n- **Leave a review** on the [VS Code Marketplace](https://marketplace.visualstudio.com/items?itemName=Siavash.php-sql-intellisense\u0026ssr=false#review-details) sharing your favorite feature or setup.\n\n### Feedback \u0026 Contributing\n\nFound a bug or have a feature request? Please feel free to open an issue or submit a pull request. Your feedback helps make local SQL context mapping better for everyone.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flightning1377%2Fphp-sql-intellisense","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flightning1377%2Fphp-sql-intellisense","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flightning1377%2Fphp-sql-intellisense/lists"}