由于某种原因,代码完成会担心本机php代码,例如bind_param(),prepare()和execute()。我收到此警告:在类中找不到方法'bind_param'。有什么问题?
if ($this->comparePassword ( $password, $confirmPass )) {
// Generating password hash
$password_hash = PassHash::hash ( $password );
// insert query
$stmt = $this->conn->prepare ( "INSERT INTO seeker(first_name, last_name, email, password, parish) values(?, ?, ?, ?, ?)" );
$stmt->bind_param ( "sssss", $fName, $lName, $email, $password_hash, $parish );
$result = $stmt->execute ();
$stmt->close ();
// Check for successful insertion
if ($result) {
// User successfully inserted
return USER_CREATED_SUCCESSFULLY;
} else {
// Failed to create user
return USER_CREATE_FAILED;
}
} else {
return PASSWORDS_DO_NOT_MATCH;
}
} else {
// User with same email already existed in the db
return USER_ALREADY_EXISTED;
}
以下是自定义类的代码
class DbConnect {
private $conn;
function __construct() {
}
/**
* Establishing database connection
* @return database connection handler
*/
function connect() {
include_once dirname(__FILE__) . './Config.php';
// Connecting to mysql database
$this->conn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME); //EDIT TO BE PDO
// Check for database connection error
if (mysqli_connect_errno()) { //EDIT TO BE PDO
echo "Failed to connect to MySQL: " . mysqli_connect_error(); //EDIT TO BE PDO
}
// returning connection resource
return $this->conn;
}
}
答案 0 :(得分:2)
显然在我的DbConnect课程中,我的PHPDoc评论声明我正在返回'数据库'事实上,当我回到了一个' mysqli'数据类型。这是造成错误的原因。解决这个问题的简单方法是将PHPDoc注释改为“mysqli”。并且代码完成再次开始工作。
答案 1 :(得分:1)
@return database connection handler
注释告诉PhpStorm您正在返回类型'数据库'。你实际上已经回归了一个' mysqli'对象,因此您应该将注释设为@return mysqli the database connection handler