Search code examples
phpzend-frameworkzend-db

Stop quotes from being escaped in zend where


I have simple table of hashes with 3 columns . Id is an email address.

Now, I want to retrieve the hash given id and type.

I do this:

$select = $this->getDbTable()->select();
$select->where('id=?', $id)->where('type=?', $type);

And I get

SELECT "hashes".* FROM "hashes" WHERE (id=\'randomemail@randomurl.com\') AND (type=\'email\')

instead of

SELECT "hashes".* FROM "hashes" WHERE (id='randomemail@randomurl.com') AND (type='email')

I have played around with quote and quoteInto, but it keeps escaping the quotes. Everywhere I look, it seems this should not be happening. Where could I be going wrong?

The same query works if type and id are integers though [in which case there are no quotes required]

Thanks!


Solution

  • The problem with the query was with the code after the $select was created. Even though the quotes seem escaped, the select works fine when used with fetchAll or fetchRow.

    The following snippet worked correctly,

        $select = $this->getDbTable()->select();
        $select->where('id=?', $id)->where('type=?', $type);;
        $hash = $this->getDbTable()->fetchRow($select)->toArray();
    

    even though $select->__toString() showed

    SELECT "hashes".* FROM "hashes" WHERE (id=\'someemail@gmail.com\') AND (type=\'default\') LIMIT 1