php连接mysql数据库实例

";
 $conn = @mysql_connect("localhost","root","root");//连接数据库   
 mysql_select_db("test",$conn);//选择数据库   
 if($conn){
	echo "连接成功
"; $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 ""; while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $users=$row["users"]; echo ""; } echo "
用户名
".$users."
"; }else{ echo "连接失败"; } ?>

 

你可能感兴趣的:(php)