converting the My_sql data into JSON

<?php
$host=”urhostname or localhost “;(if ur using a MAMP or Xampp server)
$username=”username”;
$password=”password”;
$database=”dbname”;
$table=”sample”;
mysql_connect($host,$username,$password) or die(mysql_error());
echo”connectd”;
mysql_select_db($database) or die(mysql_error());

$query=mysql_query(“SELECT * FROM $table”) or die(mysql_error());
echo”inserted”;
mysql_close();

$data=array();
while($d=mysql_fetch_assoc($query))
{

$data[]=$d;
}

echo json_encode($data);
?>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s