cOnn=mysql_connect("localhost","like","admin");
mysql_select_db("test");
if(!$this->conn) die("fail to connect the mysql database");
}
public function queryInfor($receiver){
$arr=array();
$receiver=iconv("utf-8","gbk",$receiver);
$query="select * from `comm` where recever='$receiver' order by id desc";
mysql_query("set names gbk");
$result=mysql_query($query,$this->conn) or die("fuck error");
while($row=mysql_fetch_row($result)){
$arr[]=$row;
}
if(count($arr)>5){//保存的信息超过五条,就删除掉多余信息
for($i=count($arr)-1;$i>4;$i--){
mysql_query("delete from `comm` where id={$arr[$i][0]}") or die("fail to delete the extra information");
unset($arr[$i]);
}
}
mysql_free_result($result);
for($i=0;$iconn) or die("fuck error");
while($row=mysql_fetch_row($result)){
$arr[]=$row;
}
if(count($arr)>5){//保存的信息超过五条,就删除掉多余信息
for($i=count($arr)-1;$i>4;$i--){
mysql_query("delete from `comm` where id={$arr[$i][0]}") or die("fail to delete the extra information");
unset($arr[$i]);
}
}
mysql_free_result($result);
for($i=0;$iconn);
$query="insert into `comm`(sendor,time,recever,content)values('$sender','$timestamp','$receiver','$content')";
mysql_query($query,$this->conn) or die("insert error");
}
public function getSenderAll($name){
$arr= array();
$name=iconv("utf-8","gbk",$name);
$query="select user from `rege` where 1 order by id desc";
mysql_query("set names gbk",$this->conn);
$result=mysql_query($query,$this->conn) or die("no data in database");
while($row=mysql_fetch_row($result)){
$arr[]=$row[0];
}
for($i=0;$iconn) or die("注销失败");
}
public function checkPassword($name,$password=null){
$name=iconv("utf-8","gbk",$name);
$queryP="select * from `rege` where user='$name' and password='$password' limit 1";
$queryQ="select * from `rege` where user='$name' limit 1";
mysql_query("set names gbk",$this->conn);
if($password!=null){
mysql_query($queryP,$this->conn) or die("ass error");
if(mysql_affected_rows($this->conn)>0){
$result=mysql_query("select status from `rege` where user='$name'");
$row=mysql_fetch_row($result);
if($row[0]) {
$this->infor="该用户已经登录";
return false;
}
$query="update `rege` set status=true where user='$name'";
mysql_query($query,$this->conn);
return true;
}else{
$this->infor="用户名或密码错误";
return false;
}
}
else {
mysql_query($queryQ,$this->conn) or die("sorry error");
if(mysql_affected_rows($this->conn)>0){
$this->infor="该用户名已被注册";
return false;
}
return true;
}
}
public function regerster($name,$pwd){
$name=iconv("utf-8","gbk",$name);
$query="INSERT INTO `rege`(`user`,`password`) VALUES ('$name','$pwd')";
mysql_query("set names gbk",$this->conn);
mysql_query($query,$this->conn) or die("注册失败");
$this->infor="注册成功";
}
public function close(){
mysql_close($this->conn);
}
}