I am developing a small project, where some information should be stored in a MySQL database that is hosted in a PHP hosting, I wanted to know if I have a way to develop a REST service to insert the data into a MySQL database.
I am developing a small project, where some information should be stored in a MySQL database that is hosted in a PHP hosting, I wanted to know if I have a way to develop a REST service to insert the data into a MySQL database.
A simplified way to do this, I recommend, is through Slim Framework , developed in PHP, with a focus on REST distribution APIs.
Getting Started ( Font ):
1) curl -s link | php
2) Create a composer.json
file in the project root with the following code:
{
"require": {
"slim/slim": "2.*"
}
}
3) Run the command php composer.phar install
4) Include in your file index.php
o autoloader
of the framework
<?php
require 'vendor/autoload.php';
Creating "Hello World"
1) Instantiate the application of the framework through the code:
$app = new \Slim\Slim();
2) Create the route:
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});
3) Run the application:
$app->run();
Access your project with paths specified in $app->get
.
This is a very basic example of how Slim works, to get a better idea, I recommend reading documentation .
Zend, the company responsible for PHP and the famous Zend Framework, has developed a webservice 'generator' called ApiGility . I think it's the easiest way and on Youtube there are several videos on the subject.
I particularly like Yii2. In this guide they show how easy it is to create a Restful webservice