Recommend this page to a friend! |
![]() |
Info | ![]() |
![]() |
![]() |
Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2025-05-20 (7 hours ago) ![]() | Not yet rated by the users | Total: Not yet counted | Not yet ranked |
Version | License | PHP version | Categories | |||
php-crud-api-generat 1.0 | MIT/X Consortium ... | 8 | Databases, Libraries, Web services, P... |
Description | Author | ||||||||
This package can create an API to access MySQL database record. |
|
Please read this document to learn how to create and configure a PHP REST API Web service to access MySQL database records.
Expose your MySQL/MariaDB database as a secure, flexible, and instant REST-like API. Features optional authentication (API key, Basic Auth, JWT, OAuth-ready), OpenAPI (Swagger) docs, and zero code generation.
composer create-project yourvendor/php-crud-api-generator
Copy and edit config files:
cp config/db.example.php config/db.php
cp config/api.example.php config/api.php
Edit config/db.php
:
return [
'host' => 'localhost',
'dbname' => 'your_database',
'user' => 'your_db_user',
'pass' => 'your_db_password',
'charset' => 'utf8mb4'
];
Edit config/api.php
:
return [
'auth_enabled' => false, // true to require authentication
'auth_method' => 'apikey', // 'apikey', 'basic', 'jwt', 'oauth'
'api_keys' => ['changeme123'], // API keys for 'apikey'
'basic_users' => ['admin' => 'secret'], // Users for 'basic' and 'jwt'
'jwt_secret' => 'YourSuperSecretKey',
'jwt_issuer' => 'yourdomain.com',
'jwt_audience' => 'yourdomain.com',
'oauth_providers' => [
// 'google' => ['client_id' => '', 'client_secret' => '', ...]
]
];
All requests go through public/index.php
with action
parameter.
| Action | Method | Usage Example |
|-----------|--------|------------------------------------------------------------|
| tables | GET | /index.php?action=tables
|
| columns | GET | /index.php?action=columns&table=users
|
| list | GET | /index.php?action=list&table=users
|
| read | GET | /index.php?action=read&table=users&id=1
|
| create | POST | /index.php?action=create&table=users
(form POST) |
| update | POST | /index.php?action=update&table=users&id=1
(form POST) |
| delete | POST | /index.php?action=delete&table=users&id=1
|
| openapi | GET | /index.php?action=openapi
|
| login | POST | /index.php?action=login
(JWT only) |
curl
Commandscurl http://localhost/index.php?action=tables
curl -H "X-API-Key: changeme123" "http://localhost/index.php?action=list&table=users"
curl -X POST -d "username=admin&password=secret" http://localhost/index.php?action=login
curl -H "Authorization: Bearer <token>" "http://localhost/index.php?action=list&table=users"
curl -u admin:secret "http://localhost/index.php?action=list&table=users"
./vendor/bin/phpunit
MIT
Built by BitHost. PRs/issues welcome!
![]() |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() |
||||
![]() |
||||
![]() |
||||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Lic. | License text | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Doc. | Documentation |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
![]() |
Version Control | Unique User Downloads | |||||||
100% |
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.