<?php
header('content-type:text/html;charset=utf8');
class mysql{
var $hname;
var $uname;
var $uwpd;
var $port;
var $charset;
var $dbname;
public function __construct($hostname,$uname,$uwpd,$port,$charset,$dbname)//构造函数
{
$this->hname=$hostname;
$this->uname=$uname;
$this->uwpd=$uwpd;
$this->port=$port;
$this->charset=$charset;
$this->dbname=$dbname;
}
public function connect()
{
mysql_connect($this->hname,$this->uname,$this->uwpd);
mysql_set_charset($this->charset);
mysql_select_db($this->dbname);
}
public function query($sql)
{
return mysql_query($sql);
}
public function num_rows($sql)
{
$query=mysql_query($sql);
return mysql_num_rows($query);
}
public function Allfetch($sql)
{
$arr=array();
$query=mysql_query($sql);
while($rs=mysql_fetch_assoc($query))
{
$arr[]=$rs;
}
return $arr;
}
public function fetch($sql)
{
$rs=array();
$query=mysql_query($sql);
return $rs=mysql_fetch_assoc($query);
}
}
$db=new mysql('localhost','root','root','3306','utf8','zhuce');
$db->connect();
$sql="select * from admin where 1 ";
?>
<table border="1">
<tr>
<td>用户名:</td>
<td>密码:</td>
</tr>
<?php
while($db->Allfetch($sql)){
?>
<tr>
<td><?php echo $arr['user']; ?></td>
<td><?php echo $arr['pwd']; ?></td>
</tr>
<?php }?>
</table>
phper_linuxer