Skip to content

Commit 148a814

Browse files
committed
Merge branch 'master' of github.com:mevdschee/php-crud-api
2 parents d55163d + b609462 commit 148a814

File tree

5 files changed

+91
-3
lines changed

5 files changed

+91
-3
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33
.settings/
44
phpunit.phar
55
tests/config.php
6+
.idea/
7+
vendor
8+
composer.lock
9+
tests/sqlite.db
10+
.DS_Store
11+
log.txt

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,15 @@ Related projects:
99

1010
- [PHP-API-AUTH](https://github.com/mevdschee/php-api-auth): Authentication add-on supporting JWT or username/password.
1111
- [PHP-SP-API](https://github.com/mevdschee/php-sp-api): Single file PHP script that adds a REST API to a SQL database.
12-
- [Vue-CRUD-UI](https://github.com/nlware/vue-crud-ui): Single file Vue.js script that adds a UI to a PHP-CRUD-API project.
12+
- [PHP-CRUD-UI](https://github.com/mevdschee/PHP-crud-ui): Single file PHP script that adds a UI to a PHP-CRUD-API project.
13+
- [VUE-CRUD-UI](https://github.com/nlware/vue-crud-ui): Single file Vue.js script that adds a UI to a PHP-CRUD-API project.
14+
15+
There are also ports of this script in:
16+
[Java](https://github.com/mevdschee/java-crud-api/blob/master/src/main/java/com/tqdev/CrudApiHandler.java),
17+
[Go](https://github.com/mevdschee/go-crud-api/blob/master/api.go),
18+
[C# .net core](https://github.com/mevdschee/core-data-api/blob/master/Program.cs) and
19+
[Node.js](https://github.com/mevdschee/js-crud-api/blob/master/app.js).
20+
These implementations are a proof-of-concept and do only support basic REST CRUD functionality.
1321

1422
## Requirements
1523

@@ -1028,6 +1036,38 @@ string(6) "/posts"
10281036

10291037
If it does not, something is wrong on your hosting environment.
10301038

1039+
## Composer Installation
1040+
1041+
You can use [Composer](https://getcomposer.org/) to install. Include the library in your composer.json file:
1042+
1043+
```json
1044+
{
1045+
"require": {
1046+
"mevdschee/php-crud-api": "dev-master"
1047+
}
1048+
}
1049+
```
1050+
1051+
Run `composer install` and then to use the library in your own code like this:
1052+
1053+
```php
1054+
<?php
1055+
1056+
include './vendor/autoload.php';
1057+
1058+
// DB Connection
1059+
$api = new PHP_CRUD_API(array(
1060+
'dbengine'=>'MySQL',
1061+
'hostname'=>'localhost',
1062+
'username'=>'',
1063+
'password'=>'',
1064+
'database'=>'',
1065+
'charset'=>'utf8'
1066+
));
1067+
$api->executeCommand();
1068+
1069+
```
1070+
10311071
## License
10321072

10331073
MIT

composer.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "mevdschee/php-crud-api",
3+
"type": "library",
4+
"description": "Single file PHP script that adds a REST API to a SQL database.",
5+
"keywords": [
6+
"api-server",
7+
"restful",
8+
"mysql",
9+
"geospatial",
10+
"sql-server",
11+
"postgresql",
12+
"php-api",
13+
"postgis",
14+
"crud",
15+
"rest-api",
16+
"openapi",
17+
"swagger"
18+
],
19+
"homepage": "https://github.com/mevdschee/php-crud-api",
20+
"license": "MIT",
21+
"authors": [
22+
{
23+
"name": "Maurits van der Schee",
24+
"email": "[email protected]",
25+
"homepage": "https://github.com/mevdschee"
26+
}
27+
],
28+
"require": {
29+
"php": ">=5.3.0"
30+
},
31+
"autoload": {
32+
"files": ["api.php"]
33+
}
34+
}

tests/blog_postgresql.sql

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ DROP TABLE IF EXISTS events CASCADE;
2929
DROP VIEW IF EXISTS tag_usage;
3030
DROP TABLE IF EXISTS products CASCADE;
3131

32+
--
33+
-- Enables the Postgis extension
34+
--
35+
36+
CREATE EXTENSION IF NOT EXISTS postgis;
37+
3238
--
3339
-- Name: categories; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
3440
--
@@ -131,7 +137,8 @@ CREATE TABLE products (
131137
name character varying(255) NOT NULL,
132138
price decimal(10,2) NOT NULL,
133139
properties jsonb NOT NULL,
134-
created_at timestamp NOT NULL
140+
created_at timestamp NOT NULL,
141+
deleted_at timestamp NULL
135142
);
136143

137144
--

tests/blog_sqlite.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ CREATE TABLE `products` (
107107
`name` text(255) NOT NULL,
108108
`price` text(12) NOT NULL,
109109
`properties` json NOT NULL,
110-
`created_at` datetime NOT NULL
110+
`created_at` datetime NOT NULL,
111+
`deleted_at` datetime NULL
111112
);
112113

113114
INSERT INTO `products` (`id`, `name`, `price`, `properties`, `created_at`) VALUES (1, 'Calculator', '23.01', '{"depth":false,"model":"TRX-120","width":100,"height":null}', '1970-01-01 01:01:01');

0 commit comments

Comments
 (0)