⚠️ Warning: This project is in a very early stage. Expect bugs and breaking changes. Use with caution in production environments.
A fork of the original SQLC plugin, this version generates PHP code using native PDO for type-safe database operations. It allows you to write SQL queries and automatically generates PHP classes with proper type hints and database abstraction, without requiring Doctrine DBAL.
- Generates PHP classes from SQL queries using native PDO
- Supports MySQL and SQLite
- Type-safe database operations
- Support for various SQL operations:
- SELECT queries (single and multiple results)
- INSERT operations
- UPDATE operations
- DELETE operations
- Complex joins
- Parameterized queries
- Array parameters
- Download the latest release from the releases page of this fork
- Add the plugin to your
sqlc.yamlconfiguration:
version: "2"plugins:
- name: phpwasm:
url: https://github.com/aabajyan/sqlc-gen-php/releases/download/v0.0.15/sqlc-gen-php.wasmsha256: 950c201f00b8dbe4045c09a206793cc413ff8133c1d5e512b9e57a20427b046aConfigure your SQL queries in sqlc.yaml:
sql:
- schema: sqlc/authors/mysql/schema.sqlqueries: sqlc/authors/mysql/query.sqlengine: mysql # or sqlitecodegen:
- out: src/Sqlc/MySQLplugin: phpoptions:
package: "App\\Sqlc\\MySQL"# or your preferred namespaceExample of a complete sqlc.yaml config:
version: '2'plugins:
- name: phpwasm:
url: https://github.com/aabajyan/sqlc-gen-php/releases/download/v0.0.15/sqlc-gen-php.wasmsha256: 950c201f00b8dbe4045c09a206793cc413ff8133c1d5e512b9e57a20427b046asql:
- schema: sqlc/authors/mysql/schema.sqlqueries: sqlc/authors/mysql/query.sqlengine: mysql # or sqlitecodegen:
- out: src/Sqlc/MySQLplugin: phpoptions:
package: "App\\Sqlc\\MySQL"# or your preferred namespacepackage: The PHP namespace for generated classesout: Output directory for generated code
CREATETABLEauthor (
author_id integerNOT NULL AUTO_INCREMENT PRIMARY KEY,
name textNOT NULL
) ENGINE=InnoDB;/* name: GetAuthor :one */SELECT*FROM author
WHERE author_id = ?;The plugin will generate PHP classes for the Models and Queries that you can use in your application. Usage with PDO:
useApp\Sqlc\MySQL\QueriesImpl;
$pdo = newPDO($dsn, $user, $password);
$author = (newQueriesImpl($pdo))->getAuthor(authorId: 1);- ✅ MySQL support
- ✅ SQLite support
- 🚧 PostgreSQL support (Work in Progress)
- ✅ Basic CRUD operations
- ✅ Complex queries with joins
- ✅ Type-safe parameters
- ✅ Array parameters
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.