php数据库链接

废话不多说直接上代码:

<?php 

header("Content-type:text/html;charset=utf-8");
$con = mysql_connect("localhost","root","")or die("链接失败");
$resorce = mysql_select_db("test",$con) or die("数据库失败");

mysql_query("set names utf8",$con);
$str = "SELECT age FROM user";
$result = mysql_query($str) ;
if ($result) {
    /*while ($rows = mysql_fetch_object($result)) {
        
    }
*/
    echo mysql_num_rows($result);
}else{
    echo mysql_error();    
}

?> 

posted @ 2014-10-30 11:14  heimanba  阅读(76)  评论(0)    收藏  举报