简体   繁体   English

phpstorm代码完成不适用于php方法

[英]Phpstorm code completion not working on php methods

For some reason code completion is worry on native php code such as bind_param(), prepare() and execute(). 出于某种原因,代码完成是担心本机php代码,例如bind_param(),prepare()和execute()。 I get this warning: method 'bind_param' not found in class. 我收到此警告:在类中找不到方法'bind_param'。 What is the problem? 问题是什么?

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;
    }

Here is the code for the custom class 这是自定义类的代码

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;
}

} }

Apparently in my DbConnect class my PHPDoc comments stated that I was returning 'database' when in fact I was returning a 'mysqli' datatype. 显然,在我的DbConnect类中,我的PHPDoc注释表明实际上是在返回“ mysqli”数据类型时,我正在返回“数据库”。 This was what was causing the error. 这就是导致错误的原因。 The simply fix to this problem was to change be PHPDoc annotation to 'mysqli' and the code completions started to work again. 解决此问题的简单方法是将PHPDoc批注更改为“ mysqli”,并且代码补全再次开始起作用。

the @return database connection handler annotation is telling PhpStorm that you're returning a type 'database'. @return database connection handler注释告诉PhpStorm您正在返回类型“数据库”。 You are actually returning a 'mysqli' object, so you should have the annotation be @return mysqli the database connection handler 您实际上是在返回“ mysqli”对象,因此应将注释设为@return mysqli the database connection handler

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM