方法一:
$link = mysql_connect("192.168.1.1", "myuser", "mypass");--连接数据库
if(FALSE == $link)
{
echo "Connect database failed!";
}
$query =
"select * from a order by id";
mysql_select_db('test', $link);--选择数据库
$result = mysql_query($query);--执行查询语句
if(FALSE == $result)
{
echo "Querry failed!";
}
$i = 0;
$j = 0;
while($i++ < mysql_num_rows($result))--取总行数
{
$meta_c=0;
if($meta_c=mysql_fetch_row($result))--取每一行的结果集
{
while($j < mysql_num_fields($result))--取一行的列数
{
echo $meta_c[$j;
}
echo "
";
} // while;
$j=0;
}
mysql_free_result($result);--释放结果集
mysql_close($link);--关闭连接
?>
方法二:
$link = mysql_connect("192.168.1.1", "myuser", "mypass");--连接数据库
if(FALSE == $link)
{
echo "Connect database failed!
";
}
mysql_select_db('test', $link);--选择数据库
$result = mysql_query("select * from a order by id");--执行查询语句
if(FALSE == $result)
{
echo "Querry failed!";
}
while($row = mysql_fetch_array($result, MYSQL_NUM))--取数组里面的值,因为结果集以二维数组存放
{
foreach ($row as $col_value)--一一取值
{
echo " $col_value ";
}
}
mysql_free_result($result);--释放结果集
mysql_close($link);)--关闭连接
?>
阅读(9770) | 评论(0) | 转发(0) |