Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PHP Code to Fetch SQL Data and Convert to Json API

Today most of the sites are working using API script. After the launch of AngularJS and some other great FrameWork. Developers were started to simplify website development using that Framework. Most of the Frameworks need API to fetch data from Database.  This thread will help you to convert SQL data to JSON API.

First of all you need to connect with your database.

PHP Code:
$database mysql_select_db("DBNAME HERE");

After connecting with the database you have to fetch data from the SQL that you need to convert into the JSON API.

PHP Code:
include 'config.php';
$query=mysql_query("SELECT * FROM `message`");
 $message['message'][] = $row;

The above code will convert the SQL Data from "message" table to JSON API. The "config.php" page will connect the PHP program with the Database.

Now open the page. You can see the result there.

Forum Jump:

Users browsing this thread: 1 Guest(s)