PHP Query SQL Database return JSON

As a Javascript developer, I always prefer to use NodeJS as my API endpoint when interacting with a backend database. Unfortunately, it’s not always feasible to use NodeJS (especially in a shared hosting environment) and you might have to fall back to good old PHP. So here’s a quick refresher on how you can perform queries to a SQL database using PHP from an Ajax or Fetch call. Fetch Call Suppose I have the following XMLhttp request using the fetch API:
fetch  json  php  query  sql 

PHP insert into SQL database from Fetch POST

As a Javascript developer, I always prefer to use NodeJS as my API endpoint when interacting with a backend database. Unfortunately, it’s not always feasible to use NodeJS (especially in a shared hosting environment) and you might have to fall back to good old PHP. So here’s a quick refresher on how you can insert an object into an SQL database from javascript using php. If you haven’t already, check out my previous tutorial on making SQL queries from PHP using fetch API.
ajax  fetch  post  sql