1

I am trying to write PHP that connects to a MySQL database. My debugger tells that class mysqli cannot be found. But my phpinfo() has conf.d/mysqli.ini on list of parsed .ini.

To debug this code I am using Eclipse PDT, with Xdebug. Why would the debugger not be able to find 'mysqli'??

NOTE: I am not sure if this is relevant, but this is configuration of the PHP executable:

PHP executable: /usr/bin/php5
Additional .ini:  /etc/php5/conf.d/xdebug.ini

Below is the actual error message from the console:

Fatal error: Class 'mysqli' not found in /var/www/RBDM_Project/WebContent/login.php on line 8

Call Stack:
    0.0099     333880   1. {main}() /var/www/RBDM_Project/WebContent/login.php:0

And the line 8 of the code:

 $db = new mysqli("URL","user","password","db");

UPDATE: I figured I might throw in a screenshot form phpinfo() enter image description here

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
sgp667
  • 1,797
  • 2
  • 20
  • 38
  • 1
    can you show how you are connecting to the db? – Ibu May 06 '14 at 21:22
  • Aren't class names case sensitive? Maybe it's just a simple error like that. Having a piece of code might help us spot the problem. – GolezTrol May 06 '14 at 21:22
  • Is it possible that you use the CLI version with your Eclipse and another php.ini? – René Höhle May 06 '14 at 21:23
  • Stony yes you are right, that was the default I think. I don't quite understand(YET) that .ini CLI etc. stuff So I left it as it is. – sgp667 May 06 '14 at 21:27
  • I tried to change SAPI I cannot even save changes with GCI, looks like I can only do CLI – sgp667 May 06 '14 at 21:34
  • I suppose "list of parsed .ini" is not exactly proof that the mysqli extension is being loaded. – Havenard May 06 '14 at 23:14
  • Oh and in Linux, PHP has a separate config for Apache and when its ran standalone in shell (CLI). – Havenard May 06 '14 at 23:16
  • Havenard, that makes sense I am running this on Ubuntu. So on that note I will run through my configuration to try using config for Apache – sgp667 May 06 '14 at 23:59
  • Ok I tried to use config form apache and the problem remains. I am starting to think that this might be problem with debuger instead – sgp667 May 07 '14 at 15:23
  • I have encountered this problem as well. When run from the command line, the script has no problem finding mysqli, however when run from within Eclipse with XDebug, it cannot find mysqli. – Rohn Adams Apr 25 '16 at 20:30

2 Answers2

1

These questions/recommendations might be better as a comment, but as a newbie to Stack Overflow I can't post comments.

  1. Do you have multiple versions of PHP installed? I'm only vaguely familiar with the Eclipse PDT so I'm not sure how it invokes PHP. But if you have multiple versions installed on your system, you may want to check the output of a call to phpversion to make sure the proper version of PHP is being executed.

  2. Did you compile PHP yourself? Does the configure options line in the phpinfo output show '--with-mysqli=mysqlnd'? It should since the screenshot you posted shows mysqli enabled, but at this point it couldn't hurt to check.

  3. Last suggestions, which you may have already done, verify the libraries the extension depends on are installed and your configuration in php.ini. This is an old post which you may have already seen, but it has some details on that: Fatal error: Class 'MySQLi' not found

Community
  • 1
  • 1
strwils
  • 687
  • 4
  • 12
1

You were basically right, it turned out that because I installed mysqli after libapache2-mod-php5(I think that's what its called), I had to recompile libapache2-mod-php5. For some reason that did not happened when I installed additional php modules.

Then again I am not sure it that is supposed to be done by package manager, or do I need to do it myself each time.

Long story short I reinstalled libapache2-mod-php5 and I got desired result .

sgp667
  • 1,797
  • 2
  • 20
  • 38