![]() |
10 年之前 | |
---|---|---|
README.md | 10 年之前 | |
api.php | 10 年之前 |
Simple PHP script that adds a very basic API to a MySQL database
Edit the following lines in the bottom of the file “api.php”:
$api = new MySQL_CRUD_API(
"localhost", // hostname
"user", // username
"pass", // password
"db", // database
false, // whitelist
array("users"=>"crudl") // blacklist
);
$api->executeCommand();
You can do all CRUD (Create, Read, Update, Delete) operations and extra List operation. Here is how:
GET http://localhost/api.php/categories
GET http://localhost/api.php/categories,users
GET http://localhost/api.php/cate*
GET http://localhost/api.php/cate*,user*
{"categories":{"columns":["id","name"],"records":[["1","Internet"],["3","Web development"]]}}
GET http://localhost/api.php/categories?page=1
GET http://localhost/api.php/categories?page=1,50
{"categories":{"columns":["id","name"],"records":[["1","Internet"],["3","Web development"]],"results":2}}
Match types supported:
GET http://localhost/api.php/categories?filter=name:Inter
GET http://localhost/api.php/categories?filter=name:Internet&match=exact
GET http://localhost/api.php/categories?filter=id:1&match=upto
GET http://localhost/api.php/categories?filter=id:2&match=lower
{"categories":{"columns":["id","name"],"records":[["1","Internet"]]}}
POST http://localhost/api.php/categories
{"id":"1","name":"Internet"}
1
GET http://localhost/api.php/categories/1
{"id":"1","name":"Internet"}
PUT http://localhost/api.php/categories/2
{"id":"1","name":"Internet networking"}
1
DELETE http://localhost/api.php/categories/2
1
Put the file “api.php” somewhere and enjoy!
MIT