<?php
header("Content-Type: text/html; charset=GBK");
echo "你好<br>";
$conn = @mysql_connect("localhost","root","root");//连接数据库
mysql_select_db("test",$conn);//选择数据库
if($conn){
echo "连接成功<br>";
$sql = "insert into test(users) values('mars')";
mysql_query("SET NAMES 'GBK'");//处理乱码
mysql_query($sql,$conn);
echo "插入条数为";
$recode="select users from test";
$result=mysql_query($recode,$conn);
$re_num = mysql_num_rows($result);//获取记录数
echo $re_num;
echo "<table border=1><tr><td>用户名</td></tr>";
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$users=$row["users"];
echo "<tr><td>".$users."</td></tr>";
}
echo "</table>";
}else{
echo "连接失败";
}
?>