Zend Framework 2 Double Quotes in Queries

2019-07-05 16:27发布

问题:

I'm using the Zend Framework 2 for application developement. The whole application is based on a IBM Informix database.

The database configuration looks something like this:

return array(
'db' => array(
    'driver'         => 'Pdo',
    'dsn'            => 'dsn:connection:string',
    'driver_options' => array(
    ),
),
'service_manager' => array(
    'factories' => array(
        'Zend\Db\Adapter\Adapter' => 'Zend\Db\Adapter\AdapterServiceFactory',
    ),
),
);

When querying the database by instantiating an Zend\Db\Sql\Select object, the queries are always getting quoted, which should not happen because Informix can't handle the query anymore.

Expected Querystring:

SELECT column1, column2 FROM table

Zend-generated Querystring:

SELECT "column1", "column2" from "table"

After some research I found similar cases, but neither solution was acceptable. The problem here is, that I have to pass an Zend\Db\Sql\Select object, so querying the database with raw sql via $dbAdapter->query($sql) is not possible.

Is there maybe a way to disable quotation(in the database configuration, e.g.)?

Some tipps would be very appreciated. Thanks in advance

回答1:

you can disable quoting identifiers. like this

use Zend\Db\Adapter\Adapter as DbAdapter;

// DB2 Connection
$adapter = new DbAdapter(array(
    'driver' => 'IbmDb2',
    'database' => '*LOCAL',
    'username' => '',
    'password' => '',
    'driver_options' => array(
        'i5_naming' => DB2_I5_NAMING_ON,
        'i5_libl' => 'LIB1 LIB2 LIB3'
    ),
    'platform_options' => array('quote_identifiers' => false)
);

taken from Zend Framework documentation.



回答2:

If you want Informix to recognize that notation, you need to set the environment variable DELIMIDENT so that the server knows to treat such double-quoted strings a identifiers instead of as strings.

There are a variety of ways to do it; which is best depends on your system. It looks like you're using Windows rather than Unix. There's a SETNET32 utility which could set the environment variable. On Unix (not sure about Windows), you could add DELIMIDENT 1 to $HOME/.informix or to $INFORMIXDIR/etc/informixrc (aconventional, but should work). You can set an env var by shell; you may be able to specify it as a connection-attribute.

Windows is not my area of expertise.