您好,欢迎访问一九零五行业门户网

在学习的过程中Sqlhelper类中的连接总是不正确

求助。在学习的过程中sqlhelper类中的连接总是不正确
学习写一个登陆小程序。三个文件sqlhelper.class.php,loginprocess.php,adminservice.class.php
我用的是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.php
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:
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.php
checkadmin($id,$password)){
header(location:empmain.php?name=$name);
exit();
} else{
header(location:login.php?errno=1);
exit();
}
------解决方案--------------------
其它类似信息

推荐信息