Search code examples
phppdoconnectionibm-cloudcleardb

Access to ClearDB on Bluemix with PHP and PDO


I'm trying to create a Bluemix Application using PHP and ClearDB (using PDO to connect).

When I try to access the server using my localhost (WAMP) I can get the connection successful message. When I simply copy and past the code on Bluemix, I get the following error:

Fatal error: Class 'PDO' not found in /home/vcap/app/htdocs/includes/db.php on line 43

I'm sure that my credentials works because I used the same credentials to connect via MySQL Workbench. I'm sure that my syntax is correct because I can connect using localhost (WAMP).

I searched and found that I need to activate the PDO as PHP Extensions (I already see this post Activating PHP extensions in Bluemix but no success).

Some configuration files:

.bp-config -> php -> php.ini

extension=pdo.so
extension=pdo_sqlite.so
extension=pdo_mysql.so
extension=sqlite.so
extension=mysqli.so
extension=mysql.so
extension=mbstring.so
extension=php_pdo.dll
extension=php_pdo_mysql.dll
display_errors = On
display_startup_errors = On
error_reporting = On

.bp-config -> options.json

{ 
   "PHP_EXTENSIONS": ["bz2", "zlib", "openssl", "fpm", "tokenizer", "curl", "mcrypt", "mbstring", "PDO", "pdo_mysql", "mysql", "mysqli"]
 }

line 43 from /home/vcap/app/htdocs/includes/db.php

 $this->conn = new PDO($strcon, $this->user, $this->password)

Server Logs

Someone can help me to fix it? Thanks!


Solution

  • I could solve it (with the help of @Jeff and @ Marc), here is the solution:

    The only thing I needed was:

    .bp-config>options.json

    {
      "PHP_EXTENSIONS": ["bz2", "zlib", "openssl", "fpm", "tokenizer", "curl", "mcrypt", "mbstring", "pdo", "pdo_mysql", "mysql", "mysqli"]
    }