代码:
<?php
//创建mysql连接
$link = mysql_connect('localhost', 'root', '123456') //用户名与密码
or die('could not connect: ' . mysql_error());
mysql_select_db('ruida') or die('could not select database');
// 执行 sql 查询
$query = 'select * from product';
$result = mysql_query($query) or die('query failed: ' . mysql_error());
// 用 html 显示结果
echo "<table>n";
while ($line = mysql_fetch_assoc($result)) {
echo "t<tr>n";
foreach ($line as $col_value) {
echo "tt<td>$col_value</td>n";
}
echo "t</tr>n";
}
echo "</table>n";
// 释放结果集
mysql_free_result($result);
// 关闭连接
mysql_close($link);
?>