Error message on Cron since server update: Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'

2,949 views
Skip to first unread message

Alexandre Plennevaux

unread,
Sep 8, 2016, 2:41:24 AM9/8/16
to Fat-Free Framework
Hello fellow f3ers,

A cronjob on my F3 application keeps raising this issue:

 
Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'


the cronjob:
php /path/to/public/index.php /cron


The server setup: PHP Version 5.6.23 (fpm-cgi) Ubuntu 14.04  Apache 2.4.18, mysql 5.6.32

The line provoking the error is FatFreeFramework's SQL php class:

function __construct($dsn,$user=NULL,$pw=NULL,array $options=NULL) {
    $fw
=\Base::instance();
    $this
->uuid=$fw->hash($this->dsn=$dsn);
   
if (preg_match('/^.+?(?:dbname|database)=(.+?)(?=;|$)/is',$dsn,$parts))
        $this
->dbname=$parts[1];
   
if (!$options)
        $options
=array();
   
if (isset($parts[0]) && strstr($parts[0],':',TRUE)=='mysql')
        $options
+=array(\PDO::MYSQL_ATTR_INIT_COMMAND=>'SET NAMES '.
            strtolower
(str_replace('-','',$fw->get('ENCODING'))).';');
    $this
->pdo=new \PDO($dsn,$user,$pw,$options);
    $this
->engine=$this->pdo->getattribute(\PDO::ATTR_DRIVER_NAME);
}


What I've tried :

After reading Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' in Undefined class constant (PHP 5.5.3) I've tried adding the extensions in the php.ini, to no avail.

 extension=pdo.so
 extension=pdo_mysql.so


This SO post seems to indicate that the constant is not necessary but the thread was never closed. 


I also tried forcing utf8 when initiatling the connection:


$db=new DB\SQL( 'mysql:host='.DB_HOST.';port=3306;dbname='.DB_NAME.';charset=utf8', DB_USER, DB_PASSWORD );


But still: the error message keeps pouring in my inbox.

Advises welcome.


Thanks,

Alex.

ikkez

unread,
Sep 8, 2016, 9:32:54 AM9/8/16
to Fat-Free Framework
Have you checked the correct php.ini file? the CLI php is a different than the regular php.ini for apache2 or nginx.
have a look at /etc/php5/cli/php.ini

Alexandre Plennevaux

unread,
Sep 8, 2016, 3:16:58 PM9/8/16
to Fat-Free Framework
Dear Ikkez,

That is indeed a good advice.

php -i |grep php\.ini

gives me /etc/php/7.0/cli/php.ini

whereas the non-cli version is php5, weird.

anyways, adding the pdo extensions at the end of that file
;extension=pdo.so
;extension=pdo_mysql.so
;extension=php_pdo_mysql.so

It throws the following errors:

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/pdo_mysql.so' - /usr/lib/php/20151012/pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP
Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/php_pdo_mysql.so' - /usr/lib/php/20151012/php_pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0


So I looked in /usr/lib/php/20151012 folder and indeed the mysql extension was not there

apt-get install php7.0-mysql

and now, all seems to be working okay.

Thank you for your help !!!

Alexandre Plennevaux

unread,
Sep 8, 2016, 4:10:30 PM9/8/16
to Fat-Free Framework
Well, I spoke too fast... When i test using the command line, I don't have any error, but I keep receiving emails via the cronjob.
Reply all
Reply to author
Forward
0 new messages