3

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

kinkee
  • 368
  • 2
  • 12
  • why would you want to generate the SQL using Select, but then run a raw query? Either run the raw query OR use the Select builder to execute it for you... – Andrew May 31 '13 at 08:38
  • You missunderstood - I wrote that I have to pass an Zend\Db\Sql\Select object, so querying the database via raw query is no alternative. – kinkee May 31 '13 at 08:43
  • 1
    The answer might be here http://stackoverflow.com/questions/15813544/zf2-zend-db-adapter-platformgetquoteidentifiersymbol – sroes May 31 '13 at 08:48
  • Thanks sroes - this directed my in the right way. – kinkee May 31 '13 at 11:35
  • http://stackoverflow.com/questions/39593975/zf2-remove-column-quotes-in-query/39594164#39594164 on the query level it's self.. – directory Sep 20 '16 at 12:31

2 Answers2

2

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.

bkilinc
  • 989
  • 2
  • 13
  • 28
0

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.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278