PHP and MySQL
When creating dynamic websites (can be personal, a web application, etc.) is it advisable to use API request calls instead of MySQL requests?
An example in my function getArticles()is whether I should use a native MySQL query, for example:
getArticles()
$sql = 'SELECT id, title, content FROM r_articles' $result = mysql_query($sql) or die ('.. bla bla');
Or simply do a GET request: http://mysite.com/api/articles. Then (assuming the response is in JSON) format the response.
http://mysite.com/api/articles
NOTE: The API, of course, must be created first.
It completely depends on the type of your site. If you are building a small project with only a web interface, stay with your mysql calls.
, , . Android iPhone , api . API- . -, , .
:
, . , ( / ..), , , - "Article", , , .
, , , GET PHP script . , , , , .
, , SQL, / ( SOAP JSON , :). , , , , - API- API- , , , .
, . , API, , API , -, . , , , .
PS Depending on the expected size of your service / website, you may want to put this API on your subdomain (api.website.com).