使用新浪云(SAE)简单部署PHP页面
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh">
<head>
<meta charset="utf-8">
<style>
body {
font: 13px / 1.4 Helvetica, arial;
color: #333;
background-color: #ccc;
}
table {
margin-top: 8px;
margin-bottom: 0px;
color: #666;
background-color: #eee;
}
</style>
<title>Books</title>
</head>
<body>
<h1>书籍信息</h1>
<table border='2'>
<tr>
<td>书名</td>
<td>价格</td>
<td>描述</td>
</tr>
<?php
#连接数据库
$db = mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT, SAE_MYSQL_USER, SAE_MYSQL_PASS);
#选择数据库
mysql_select_db(SAE_MYSQL_DB);
#设置编码方式
mysql_set_charset("utf8");
#查询语句
$query = "select * from Books";
#执行查询,得到结果
$result = mysql_query($query);
#循环输出查询结果
while($rs = mysql_fetch_array($result)){
?>
<tr>
<td><?php echo $rs["name"]. ""; ?></td>
<td><?php echo $rs["price"]. ""; ?></td>
<td><?php echo $rs["details"]. ""; ?></td>
</tr>
<?php
}
#关闭连接
mysql_close($db);
?>
</table>
</body>
</html>
下面是数据库的表:
CREATE TABLE IF NOT EXISTS `Books` (
`name` varchar(50) NOT NULL,
`price` double NOT NULL,
`details` text NOT NULL,
PRIMARY KEY (`name`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;