How can I create a web service using PHP and MySQL?
-
How to create a web service by php&mysql
-
Answer:
If you're really determined to use PHP, then start with a well documented PHP web framework. http://kohanaframework.org/ http://www.symfony-project.org/ http://cakephp.org/ http://framework.zend.com/ they each should have a nice tutorial that will walk you through the steps to using their framework to create your site.
Steve Lacy at Quora Visit the source
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:
- How can i create a mobile application server?Best solution by Stack Overflow
- How can I parse a complex XML with PHP and CDATA?Best solution by Stack Overflow
- How can I get a web design job in Toronto?Best solution by Yahoo! Answers
- How can i create a new blog?Best solution by Yahoo! Answers
- How do I create a web based msn?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.