json 实现客户端和服务器端的数据交互

/**
 * json application
 * @author:    loosboo
 * @email:    [email protected]
 * @date:    2007.12.25
*  @reference:   http://tech.ddvip.com/2007-08/118771525832600.html
 *
 */
/*
--
-- 表的结构 `feeds`
--

CREATE TABLE `feeds` (
  `id` int(11) NOT NULL auto_increment,
  `url` varchar(50) NOT NULL,
  `title` varchar(100) NOT NULL,
  `viewed` varchar(1000) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;

--
-- 导出表中的数据 `feeds`
--

INSERT INTO `feeds` VALUES (1, 'www.blah.com/story1.html', 'JSON is sweeping AJAX world', '0');
INSERT INTO `feeds` VALUES (2, 'www.blah.com/story2.html', 'JSON is great', '0');
*/

$hostname = "localhost";
$database = "ajax_db";
$username = "root";
$password = "123";

$sql="select * from feeds";
$rows = array();
mysql_connect(localhost, $username, $password);
mysql_select_db($database) or die("Unable to select database");
$result = mysql_query($sql);
while($row = mysql_fetch_object($result))
{
    $rows[] = $row;
}
$return = json_encode($rows);
echo $return;
mysql_close();
?>

 



json application




get data by json!



你可能感兴趣的:(json 实现客户端和服务器端的数据交互)