本文目录一览:
怎么用PHP语言来显示MySQL数据库内容
一般的结构如下:
<?php
if (mysql_connect('127.0.0.1', 'root', '123456')) { // 注意密码
$sql = 'select * from try.ty limit 100'; // 限制100,怕太多了
if ($res = mysql_query($sql)) {
echo '<table>';
while ($row = mysql_fetch_row($res)) {
echo '<tr><td>' . implode('</td><td>', $row) . '</td></tr>';
}
mysql_free_result($res);
echo '</table>';
} else {
echo '执行数据库查询失败,SQL语句:' . $sql . '<br>错误信息:' . mysql_error();
}
mysql_close();
} else {
echo '数据库连接失败,错误信息:' . mysql_error();
}
?>
PHP如何读取MYSQL并显示出来
$conn = mysql_connect('localhost', 'root', 'root') or die("error connecting");
mysql_query("set names 'utf8'");
mysql_select_db('lxw'); // 打开数据库
$sql = "select id, pagename, isgroup, pagegroupid from author where id > 20 order by isgroup desc"; // SQL语句
$result = mysql_query($sql, $conn); // 查询
while ($row = mysql_fetch_array($result)) {
}
mysql_close($conn); // 关闭MySQL连接
给你推荐一个 MySQL 操作类:medoo
如何在PHP中调用MYSQL数据并将其显示在页面中?
$conn = mysql_connect('localhost', 'username', 'userpassword');
$db_selected = mysql_select_db("你的数据库名", $conn);
$sql = "select * from pre_forum_forum where fid=xxx";
$result = mysql_fetch_array(mysql_query($sql, $conn));
// $result['posts'] 就是你需要的值了
怎么用php显示mysql 数据表数据
<html>
<head>
<title>浏览表中记录</title>
</head>
<body>
<center>
<?php
$db_host = "localhost"; // MYSQL服务器名
$db_user = "root"; // MYSQL用户名
$db_pass = ""; // MYSQL用户对应密码
$db_name = "test"; // 要操作的数据库
// 使用 mysql_connect() 函数对服务器进行连接,如果出错返回相应信息
$link = mysql_connect($db_host, $db_user, $db_pass) or die("不能连接到服务器" . mysql_error());
mysql_select_db($db_name, $link); // 选择相应的数据库,这里选择 test 库
$sql = "select * from test1"; // 先执行 SQL 语句显示所有记录以与插入后相比较
$result = mysql_query($sql, $link); // 使用 mysql_query() 发送 SQL 请求
echo "当前表中的记录有:";
echo "<table border=1>"; // 使用表格格式化数据
echo "<tr><td>ID</td><td>姓名</td><td>邮箱</td><td>电话</td><td>地址</td></tr>";
while ($row = mysql_fetch_array($result)) { // 遍历 SQL 语句执行结果把值赋给数组
echo "<tr>";
echo "<td>" . $row['id'] . "</td>"; // 显示 ID
echo "<td>" . $row['name'] . "</td>"; // 显示姓名
echo "<td>" . $row['mail'] . "</td>"; // 显示邮箱
echo "<td>" . $row['phone'] . "</td>"; // 显示电话
echo "<td>" . $row['address'] . "</td>"; // 显示地址
echo "</tr>";
}
echo "</table>";
?>
</center>
</body>
</html>