0

For some reason code completion is worry on native php code such as bind_param(), prepare() and execute(). I get this warning: method 'bind_param' not found in class. 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;
}

}

16
  • Might be related: stackoverflow.com/a/12583095 Commented Dec 14, 2014 at 3:18
  • the code works fine but for some reason the code completion not working. it works with everything thing else such as with zend, sublime etc. Commented Dec 14, 2014 at 3:21
  • Did you see the link I gave you above? Commented Dec 14, 2014 at 3:22
  • is not it suppose to pick up the native php methods from the interpreter? Commented Dec 14, 2014 at 3:23
  • read it already that only tell the editor to not show it as a warning. It does not make the auto-complete work for php methods Commented Dec 14, 2014 at 3:25

2 Answers 2

2

Apparently in my DbConnect class my PHPDoc comments stated that I was returning 'database' when in fact I was returning a 'mysqli' datatype. 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.

Sign up to request clarification or add additional context in comments.

Comments

1

the @return database connection handler annotation is telling PhpStorm that you're returning a type 'database'. You are actually returning a 'mysqli' object, so you should have the annotation be @return mysqli the database connection handler

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.