php连接数据库

<?php

/**
 * @author goby.com
 * @copyright 2008
 */

  header("Content-Type: text/html; charset=GBK");
$conn = @mysql_connect("localhost","root","seebig");//连接数据库
mysql_select_db("jiaoliu",$conn);//选择数据库
if($conn){

    $sql = "insert into jiaoliu(title) values('你好')";
    mysql_query("SET NAMES 'gbk'"); //处理乱码
  // mb_internal_encoding('gbk');
    mysql_query($sql,$conn);
    echo "连接成功!";
    //显示数据
    $sql2 = "select * from jiaoliu order by id desc";
    $result=mysql_query($sql2,$conn);//执行sql
    $re_num = mysql_num_rows($result);//获取记录数
	echo $re_num;
    while($d=mysql_fetch_row($result)){
    	echo "<li>".$d[1]."</li>";
    }
}else{
	echo "失败";
}

?>

 

你可能感兴趣的:(html,sql,PHP,mysql)