PHP and MySQL
In building dynamic websites (can be personal, web app, etc..), is it suitable to use API request calls, instead of MySQL queries?
Example in my function getArticles()
, should I use a native MySQL query like:
$sql = 'SELECT id, title, content
FROM r_articles'
$result = mysql_query($sql) or die ('.. bla bla');
Or, just execute a GET request to: http://mysite.com/api/articles
. Then (supposed to be the response is in JSON) format the response.
NOTE: The API of course is to be created first.
PHP: PHP is an open-source development platform and a server-side scripting language offering versatility during development of dynamic websites.
Many of the most popular web and cloud companies use REST APIs for their applications, including Facebook, YouTube, Twitter, and Google.
Dynamic websites rely on both client-side and server-side scripting languages such as JavaScript, PHP or ASP.net. When a user accesses a dynamic website, the site can be changed through a code that is run in the browser and/or on the server.
That depends fully on the type of your site. If you're building a small project with just the webinterface, stay with your mysql calls.
If you're doing a site which shall grow big and serve more than one service, e.g. an android/iPhone application is already planned out, build the api and let both applications use it. APIs are great for scalability and serving to a lot of customers. However, for a web representation e.g. for your locals dentist its simply overhead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With