<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><!--这里很重要,得加上-->
<?php
//连接数据库
$con = mysql_connect("localhost","root","John_here"); //本机root John_here
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
//定位数据库
mysql_select_db("Tb3", $con); //数据库名为Tb3
//设置数据库查询编码
mysql_query("SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary", $con);
//执行查询语句
$result = mysql_query("SELECT * FROM os_users");
//显示数据
while($row = mysql_fetch_array($result))
{
echo $row[0] . "--- " . $row['email']."--- " .$row['Address']; //数据库表中的字段
echo "<br />";
}
//关闭数据库
mysql_close($con)
?>
本文展示了一个使用PHP连接数据库并从os_users表中检索数据的例子。通过建立数据库连接、选择数据库、设置字符集和执行SQL查询等步骤,成功获取并展示了用户数据。
1万+

被折叠的 条评论
为什么被折叠?



