ZF2 - \Zend\Db\Adapter\Platform :: getQuoteIdentifierSymbol()

Sha*_*nov 5 php pdo symbols identifier zend-framework2

代码如下,我的目标是使用Pdo_mysql:

use \Zend\Db\Adapter\Adapter;
use \Zend\Db\Sql\Sql;
use \Zend\Db\Sql\Expression;    

$params = array(
    'driver'   => "Pdo_mysql",
    'host'     => &$this->Registry->config[ 'sql' ][ 'host' ],
    'username' => &$this->Registry->config[ 'sql' ][ 'user' ],
    'password' => &$this->Registry->config[ 'sql' ][ 'passwd' ],
    'dbname'   => &$this->Registry->config[ 'sql' ][ 'dbname' ]
);
$this->adapter  = new \Zend\Db\Adapter\Adapter( $params );
$this->platform = $this->adapter->getPlatform();
$this->sql      = new Sql( $this->adapter );
Run Code Online (Sandbox Code Playgroud)

当我检查标识符引用符号时:

print $this->platform->getQuoteIdentifierSymbol();    // Output: "
Run Code Online (Sandbox Code Playgroud)

如您所见,双引号是符号.这当然无效矿井所有的MySQL查询,因为它用双引号("),而不是前引号(')引用的所有标识符名称(表,列等).

那么,为什么PDO-MySQL驱动程序使用Sql92符号呢?以及如何解决这个问题?

Sha*_*nov 1

此问题的唯一解决方案是创建新的 \Zend\Db\Platform\Mysql 对象,并在启动连接时将其作为第二个参数传递给 Adapter 类。这个问题暗示了自动执行此操作的方式。我不明白为什么初始化 MySQL 适配器不附加 MySQL 平台,而是附加 SQL92 平台。

  • 我建议在 GitHub 上开一个关于这个问题的问题。也许有些东西我们理解不正确,但它肯定会在那里得到更好的关注! (3认同)