首页 / PHP / php – 在课堂上找不到的方法
php – 在课堂上找不到的方法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 在课堂上找不到的方法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1846字,纯文字阅读大概需要3分钟。
内容图文
![php – 在课堂上找不到的方法](/upload/InfoBanner/zyjiaocheng/707/50dce109db3c47db93429c4daf91db8b.jpg)
我正在进行登录功能,但遇到了一个我无法弄清楚的错误.
这是我的Model Login类:
class Login {
private $username;
private $password;
private $cxn; //database object
function __construct($username,$password)
{
//set data
$this->setData($username, $password);
//connect DB
$this->connectToDB();
// get Data
}
function setData($username, $password)
{
$this->username = $username;
$this->password = $password;
}
private function connectToDB()
{
include 'Database.php';
$connect = '../include/connect.php';
$this->cxn = new database($connect);
}
function getData()
{
$query = "SELECT * FROM anvandare WHERE anvandarnamn = '$this->username' AND losenord ='$this->'password'";
$sql = mysql_query($query);
if(mysql_num_rows($sql)>0)
{
return true;
}
else
{
throw new Exception("Anv?ndarnamnet eller L?senordet ?r fel. F?rs?k igen.");
}
}
function close()
{
$this->cxn->close(); //Here is the error it says "Method 'close' not found in class
}
}
最后一个函数给出错误“方法’关闭”在类中找不到”,“在主题类中找不到引用方法”.
这是我的数据库类:
class Database {
private $host;
private $user;
private $password;
private $database;
function __construct($filename)
{
if(is_file($filename)) include $filename;
else throw new exception("Error!");
$this->host=$host;
$this->user=$user;
$this->password=$password;
$this->database=$database;
$this->connect();
}
private function connect()
{
//Connect to the server
if(!mysql_connect($this->host, $this->user, $this->password))
throw new exception("Error, not connected to the server.");
//Select the database
if(!mysql_select_db($this->database))
throw new exception("Error, no database selected");
}
function close()
{
mysql_close();
}
}
这些途径是正确的,所以不是这样.可能是什么错误?
解决方法:
PhpStorm无法确定$this-> cxn字段的类型.您可以通过简单的PHPDoc注释提供typehint来提供帮助:
/** @var Database */
private $cxn; //database object
内容总结
以上是互联网集市为您收集整理的php – 在课堂上找不到的方法全部内容,希望文章能够帮你解决php – 在课堂上找不到的方法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。