0

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.

Community
  • 1
  • 1
Manish Giri
  • 3,562
  • 8
  • 45
  • 81

2 Answers2

2

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.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • Apologies for not being clearer earlier. I am just following the sequence as is followed in the book, which goes from using MySQL to MySQLi to PDO. Also, the book uses `$mysqli->error()` instead of `$link->error()`. As `$mysqli` seemed like an undeclared variable, I figured it would've been a typo and used `$link` instead. Was that the problem? – Manish Giri Aug 30 '15 at 11:35
  • Thanks, it's good advice. I'll switch to the manual. I could not understand even a line of how PDOs were explained in the book. – Manish Giri Aug 30 '15 at 22:04
0

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.

axiac
  • 68,258
  • 9
  • 99
  • 134