未定义的类常量'MYSQL_ATTR_INIT_COMMAND'(php 5.6+)

时间:2016-09-06 12:24:01

标签: php mysql fat-free-framework

cronjob不断提出这个问题

Undefined class constant 'MYSQL_ATTR_INIT_COMMAND'

cronjob:

php /path/to/public/index.php /cron

我的服务器: PHP 5.6.23版(Apache Handler) Ubuntu 14.04

引发错误的行是FatFreeFramework的SQL php类:

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);
}

看完之后 Undefined class constant 'MYSQL_ATTR_INIT_COMMAND' in Undefined class constant (PHP 5.5.3) 我试过在php.ini中添加扩展,但没有用。

 extension=pdo.so
 extension=pdo_mysql.so

This SO post似乎表明该常量不是必需的,但线程从未关闭过。建议欢迎。

0 个答案:

没有答案