我尝试在PDO连接上使用压缩,连接到MariaDb。但是,当我尝试获取属性时,我收到错误:
SQLSTATE[IM001]: Driver does not support this function: driver does not support that attribute
我正在使用PHP 7.0.15-0ubuntu0.16.04.4
和MariaDb mysql Ver 15.1 Distrib 10.0.29-MariaDB
我创建连接的代码如下:
protected function connect($host, $user, $pass, $dbName, $port = null, $useCompression = false)
{
//Already connected? Just return true.
if ($this->connected) return true;
$dsn = "mysql:charset=utf8mb4;host=$host;dbname=$dbName";
if ($port) $dsn .= ";port=$port";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_EMULATE_PREPARES => false,
PDO::MYSQL_ATTR_COMPRESS => $useCompression
];
// Setup DB connection
$this->db = new PDO($dsn, $user, $pass, $options);
$this->connected = true;
}
我在PHPUnit测试中获得了对PDO对象($pdo
)的引用,然后尝试这个:
$this->assertTrue($pdo->getAttribute(\PDO::MYSQL_ATTR_COMPRESS));
这会导致本文开头的错误。
为什么会出现此错误?根据{{3}},自PHP 5.3.11以来这应该可行。
答案 0 :(得分:0)
PDO::MYSQL_ATTR_COMPRESS
只是约束。
要使用压缩服务器,客户端必须允许它。