1

Currently I'm using Eclipse PHP IDE and try to using PDO MySQL on this IDE. The code that I'm gonna try is the PDO constructor:

$dsn = 'mysql:dbname=db_pdo;host=localhost';
$user = 'imbagila';
$password = 'mypass';

try {
    $dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}

After that, I'm gonna run that code on PHP CLI Application in IDE. But then it's return the error like this :

PHP Fatal error:  Uncaught Error: Class 'PDO' not found in
/home/imbagila/Documents/php/eclipse/myproject/index.php:8 Stack trace:
#0 {main}   thrown in /home/imbagila/Documents/php/eclipse/myproject/index.php on line 8

But when I tried at terminal (also CLI, by typing php index.php) it's return nothing, which mean it's successfully executed with no errors. Why this happens ? Can someone give the solutions so I can use PDO MySQL on my Eclipse IDE ?

  • OS : Xubuntu 18.04
  • PHP Version : 7.2
  • Eclipse PHP IDE Version : Photon Release (4.8.0)
  • Eclipse Run Configuration :
    • Runtime PHP : Installed PHP (7.2)
    • Executable path : /usr/bin/php7.2
    • PHP ini file : /etc/php/7.2/cli/php.ini
    • SAPI : CLI Version 7.2.7
imbagila
  • 513
  • 1
  • 8
  • 26

1 Answers1

0

I had the same issue, although I am using a different version of Eclipse.

Eclipse IDE for PHP Developers

Version: 2018-09 (4.9.0)

Build id: 2018-09-17-1800

(I am running Ubuntu 18.04 in a Virtualbox on Windows 10. I expect that is irrelevant.)

OS : Ubuntu 18.04

PHP Version : 7.2

Runtime PHP : Installed PHP (7.2)

Executable path : /usr/bin/php7.2

PHP ini file : /etc/php/7.2/cli/php.ini

After lots of googling, trial and error, and producing several other error messages, I found the following is working for me.

In my /etc/php/7.2/cli/php.ini, I have these extensions :

extension=mysqlnd
extension=pdo
extension=pdo_mysql

According to one post I read, the order of these is important. I haven't tested any other order, since this is working for me.

Neil E
  • 43
  • 6