求助。在学习的过程中Sqlhelper类中的连接总是不正确
学习写一个登陆小程序。三个文件SqlHelper.class.php,loginProcess.php,AdminService.class.
我用的是zend开发工具。运行代码的时候总是报:Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in C:\wamp\www\empManage\SqlHelper.class.php on line 20

我猜想是类实例化之后构造函数的问题。
但是总是无法解决。希望有人帮我看下。非常感谢

SqlHelper.class.

//声明类成员
public $conn;
public $dbname="emp";
public $username="root";
public $password="";
public $host="localhost";
//构造函数
public function _construct(){
$this->conn=mysql_connect($this->host,$this->username,$this->password);
if (!$this->conn) {
die("连接失败".mysql_error());
}
mysql_select_db($this->dbname,$this->conn);
}

// 执行dql语句
public function excute_dql($sql){
$res=mysql_query($sql,$this->conn) or die(mysql_error());
return $res;
}

//执行dml语句
public function excute_dml($sql){
$b=mysql_query($sql,$this->conn);
if (!$b){
return 0;
}else{
if(mysql_affected_rows($this->conn)>0){
return 1;//表示执行OK
} else{
return 2;//表示执行没有行受到影响
}

}


}
//关闭数据库连接
public function close_connect(){
if (!empty($this->conn)){
mysql_close($this->conn);
}
}
}
?>
登录后复制


AdminService.class.php:

class AdminService{
public function checkAdmin($id,$password){
$sql="select * from admin where id=$id";
//创建一个SqlHelper对象
$sqlHelper=new SqlHelper();
$res=$sqlHelper->excute_dql($sql);//我把这个结果给你,你怎么处理是你的事情
if ($row=mysql_fetch_assoc($res)){
if ($password==$row['password']){
return $row['name'];
}
}
//关闭资源
mysql_free_result($res);
$sqlHelper->close_connect();
//关闭连接
return "";
}
}
?>

登录后复制


loginProcess.$id=$_POST['id'];
$password=$_POST['password'];

$adminService=new AdminService();
if($name=$adminService->checkAdmin($id,$password)){
header("Location:empMain.php?name=$name");
exit();
} else{
header("Location:login.php?errno=1");
exit();
}


------解决方案--------------------

09-15 17:20