Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDO Fatal error on Bluemix

Tags:

php

pdo

ibm-cloud

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:

like image 458
notme Avatar asked Aug 10 '15 13:08

notme


2 Answers

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 .

like image 133
Trix Avatar answered Sep 23 '22 21:09

Trix


just tried to replicate your problem but using composer.json as for your pasted config, it worked fine. Probably your problem could be related to a conflict between different configurations used to solve the error. My suggestion to solve your problem is to start from the starter code again, be sure that the MySQL service is binded correctly, and then replace the code with your one and configure composer.json with the libs you need. Then push it again, leaving it complete all staging activities (really important!) Let us know if you manage to solve it.

like image 39
v.bontempi Avatar answered Sep 26 '22 21:09

v.bontempi