How to create a Restful web service in .Net Using MySQL?

How can I create a web service using PHP and MySQL?

Steve Lacy at Quora Visit the source

Was this solution helpful to you?

Other answers

You certainly get a lot of functionality out of a framework designed to build webservices, but in the essence a webservice is a webserver url generating data in a serialized form such as xml or, more pragmatically json. you don't need anyting fancy to achieve this, pure php is perfectly capable: <?php $data = []; die( json_encode($data) ); you can then add a routing library to have apache generate a response for pretty url like /controler/action/param1/param2if you need this functionality(an more), take a look to the microframework Sylex (http://silex.sensiolabs.org/ the next step is to read data from mysql, you will find many examples in the php PDO documentation for doing it, here is a minimalistic implemetation: <?php $dsn = 'mysql:host=localhost;dbname=testdb'; $username = 'username'; $password = 'password'; $dbh = new PDO($dsn, $username, $password); function get_data($dbh) { $sql = 'SELECT name, color, calories FROM fruit ORDER BY name'; foreach ($dbh->query($sql) as $row) { // do your data elaboration } return $data; } $data = get_data($dbh); as you can see there is nothing magic in a web service that extracs data from a database, plain PHP comes by default with all the tools needed, more complex libraries may be included into your project (only) to solve specific problems.

Tazio Mirandola

Basically you can use PHP in the backend to response any kind of data, returning text with echo, returning an array, json, xml or objects. Usually there is no problem with this because PHP can work, as I said, in the backend just returning data to a frontend site using html +  javascript usually using ajax to call the backend php function. But when you have a site in the frontend and the backend in differents domains you need to use JSONP to return data from backend (PHP) and a function in frontend catching the JSONP with a callback function to arrange the data. Or you can enable CORS to work with any kind of data, like a said in first paragraph.To avoid this behaviour, it's when you can use the web services, pieces of code to work without restrictions of domains and working without restrictions of the language you use in the frontend or in the backend.Personally I use to make web services in PHP the soap class named http://sourceforge.net/projects/nusoap/. Also there is several tutorials in internet to made it.

Alejandro Vargas

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.