0
votes

I am learning PHP and was working with MySQL upto this point. When I started using prepared statements, I switched over to MySQLi instead, but I got an error in my IDE(phpStorm): Method error not found in class mysqli.

I looked at the related questions here on SO and found an answer in the question Fatal error: Class 'MySQLi' not found. I used the sudo apt-get install php5-mysqlnd command, and from the terminal commands it appeared that mysqlnd package was installed successfully.

Here's a screen grab:
enter image description here

After it completed, I ran this command (from a post I found somewhere): php -m | grep -i mysql and got the output mysql mysqli mysqlnd pdo_mysql.

It appeared that the package was installed, but I still get the same error in phpstorm, as it says in this screen grab:

enter image description here

Ultimately, is MySQLi finally installed? Do I need to re-configure PHPStorm somehow? I went to "language and frameworks" under settings, but didn't find anything new there to configure.

My PHP version is (I think) PHP version: 5.5.9-1ubuntu4.11.

2

2 Answers

2
votes

Do I need to re-configure PHPStorm somehow?

All you actually need is to read the error message.
It doesn't say that mysqli is not installed. It rather says that mysqli itself is all right, but there is a problem accessing a non-existent method. Which is indeed never existed.

When I started using prepared statements, I switched over to MySQLi instead

You should have switched to PDO instead.

Was that the problem?

The problem is the book you are reading. Which is using non-existent methods and full of typos. If you want to learn some PHP extension, learn it from manual page.

0
votes

Your code reads:

if (! $link) {
    die("Connection failed: ".$link->error());
}

The class mysqli doesn't have any method named error(). It has a property named $error but that's is a totally different thing.

But wait! There is more!

When is the die() statement executed in the code above? When $link is NULL. Does NULL have a method named error()? I sincerely doubt.

Ultimately, is MySQLi finally installed?

The answer is in the question, in the php -m part. If you see mysqli in the output of php -m | grep -i mysql then it is installed and ready to work.