Saturday, November 19, 2011

web services using php as JSON format


Create a php file with following code:

$hostname="localhost";
$username="bhoopendra";
$password="";
$database="my_db";
$table='comment';
$con=mysql_connect($hostname, $username, $password) or die(mysql_error());
mysql_select_db($database, $con) or die(mysql_error());
$result=mysql_query("SELECT * FROM ".$table) or die(mysql_error());

while($row = mysql_fetch_assoc($result)) {
$data[]=$row;
 
}

$file=fopen("web.xml", "w");
if(fwrite($file,json_encode($data))){
//header('location: web.xml');
}

No comments:

Post a Comment