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.

2 Answers 2

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.

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

2 Comments

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?
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.
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.

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.