php-crud-api

Single file PHP script that adds a REST API to a SQL database

What is php-crud-api?

Single file PHP script that adds a REST API to a SQL database

Overview of php-crud-api

What it is

PHP-CRUD-API is a single-file PHP script that adds a REST API to a MySQL/MariaDB, PostgreSQL, SQL Server or SQLite database. It is the TreeQL reference implementation in PHP.

Key features

  • Composer install or single PHP file, easy to deploy
  • Supports POST variables as input (x-www-form-urlencoded)
  • Supports a JSON object or JSON array as input (batch insert)
  • Sanitize and validate input using type rules and callbacks
  • Permission system for databases, tables, columns and records
  • Multi-tenant single and multi database layouts
  • Multi-domain CORS support for cross-domain requests
  • Support for reading joined results from multiple tables
  • Search support on multiple criteria
  • Pagination, sorting, top N list and column selection
  • Relation detection with nested results (belongsTo, hasMany and HABTM)
  • Atomic increment support via PATCH (for counters)
  • Binary fields supported with base64 encoding
  • Spatial/GIS fields and filters supported with WKT and GeoJSON
  • Mapping table and column names to support legacy systems
  • Generate API documentation using OpenAPI tools
  • Authentication via API key, JWT token or username/password
  • Database connection parameters may depend on authentication
  • Support for reading database structure in JSON
  • Support for modifying database structure using REST endpoint
  • Security enhancing middleware is included
  • Standard compliant: PSR-4, PSR-7, PSR-12, PSR-15 and PSR-17

Use cases

PHP-CRUD-API can be used to quickly create a REST API for any existing SQL database without writing any code. It is suitable for building backend services for web and mobile applications, prototyping, and integrating with frontend frameworks like React Admin via the ra-data-treeql data provider. It also supports multi-tenant database layouts and can be used as a storage layer for authentication libraries.

Getting started

Download the api.php file from the latest release and upload it to your webserver. For local development, run PHP's built-in web server:php -S localhost:8080Test the script by opening:http://localhost:8080/api.php/records/posts/1Don't forget to modify the configuration at the bottom of the file.

License and pricing

This project is open source under the MIT license. No pricing information is provided.

Based on the project's public README and repository metadata.

Add this badge to your README

Featured on YunoDB Badge styles & help

Maintain this project? Show that it is featured on YunoDB.

Markdown[![Featured on YunoDB](https://yunodb.com/badge/mevdscheephp-crud-api.svg)](https://yunodb.com/tools/mevdscheephp-crud-api?utm_source=github&utm_medium=badge)
HTML<a href="https://yunodb.com/tools/mevdscheephp-crud-api?utm_source=github&utm_medium=badge"><img src="https://yunodb.com/badge/mevdscheephp-crud-api.svg" alt="Featured on YunoDB" height="20"></a>