Search code examples
phppdoibm-cloud

PDO Fatal error on Bluemix


I'm really stuck in making PDO working with PHP in bluemix. I can't use it, everytime I get this error:

Fatal error: Class 'PDO' not found in ...

Then i've added the options.json under .bp-config\

{
     "PHP_VERSION": "{PHP_55_LATEST}",
       "WEB_SERVER": "httpd",
     "PHP_EXTENSIONS": [ "bz2", "zlib", "openssl", "fpm", "tokenizer", "curl", "mcrypt", "mbstring", "pdo", "mysqli"]
}

then i've also tried with the php.ini under .bp-config\

display_errors = On
display_startup_errors = On
extension=pdo.so
extension=pdo_mysql.so
extension=mysqli.so
extension=mysql.so
extension=mbstring.so

and after a phpinfo(); I get:

'./configure' '--prefix=/tmp/staged/app/php' '--disable-static' '--enable-shared' '--enable-ftp=shared' '--enable-sockets=shared' '--enable-soap=shared' '--enable-fileinfo=shared' '--enable-bcmath' '--enable-calendar' '--with-kerberos' '--enable-zip=shared' '--with-bz2=shared' '--with-curl=shared' '--enable-dba=shared' '--with-cdb' '--with-gdbm' '--with-mcrypt=shared' '--with-mhash=shared' '--with-mysql=shared' '--with-mysqli=shared' '--enable-pdo=shared' '--with-pdo-sqlite=shared,/usr' '--with-pdo-mysql=shared,mysqlnd' '--with-gd=shared' '--with-jpeg-dir=/usr' '--with-freetype-dir=/usr' '--enable-gd-native-ttf' '--with-pdo-pgsql=shared' '--with-pgsql=shared' '--with-pspell=shared' '--with-gettext=shared' '--with-gmp=shared' '--with-imap=shared' '--with-imap-ssl=shared' '--with-ldap=shared' '--with-ldap-sasl' '--with-zlib=shared' '--with-xsl=shared' '--with-snmp=shared' '--enable-mbstring=shared' '--enable-mbregex' '--enable-exif=shared' '--with-openssl=shared' '--enable-fpm'

I've also tried the composer.json:

{
  "require": {
    "ext-mysqli": "*",
    "ext-pdo": "*",
    "ext-pdo_mysql": "*"
  }
}

But still, after all this steps, i'm still getting the same error since days and days :( :desperate:


Solution

  • For me the composer was not working but the options.json was.

    File options.json under .bp-config/ should contain also the driver you want to use. Otherwise the PDO itself is not able to communicate with DB.

    This is my working options.json

    {
    "PHP_EXTENSIONS": ["bz2", "pdo", "zlib", "curl", "mcrypt", "mbstring", "mysqli", "gd", "zip", "pdo_mysql", "pdo_sqlite" ]
    }
    

    From your provided phpinfo() you are able to communicate to mysql, sqlite and pgsql using PDO.

    To see if you have loaded driver run phpinfo() and look for section PDO. There should be something like this: PDO drivers mysql, sqlite .