Hi Ralph,
I am using Zend_Db_Select to help me build the query for an "advanced
search" page that contains about 20 different form elements. Through
Javascript, the user can decide which fields they want to search, so my
backend needs to be able to dynamically build the SQL query based on which
fields were selected.

The site I'm currently working on is not a ZF site (although we have plans
to migrate to ZF in the near future). The site currently uses a (very)
outdated PEAR library for its database connections (wrapping
mysql_connect()).

I am not done with the backend quite yet but so far using
Zend_Test_DbAdapter has been successful. It is building MySQL-compatible
queries but like you said it's not quoting identifiers with backticks. I can
live with this for this particular query but it may cause problems with
other queries.

I haven't tested limits yet but looking at the code it seems like it will
work with MySQL.

I'm going to take your advice and build a MySQL-compatible null adapter.
This would help to use make sure our queries are compatible with our
connection.

--
Hector


On Mon, Aug 24, 2009 at 8:32 AM, Ralph Schindler
<[email protected]>wrote:

> Hector, what is your use case?  I've thought about this a couple of times,
> and I wonder if having a null adapter as part of the Zend_Db_Adapter would
> make sense for some use cases.
>
> The thing you have to consider is that several adapters do differnet things
> when it comes to how they quote identifiers, values, and so on. Also when it
> comes to creating a limit query.
>
> One of your best options is to just create an adapter on your own that you
> can proxy to with your select object that you are interacting with. In this
> case, like Benjamin said, you could start with the adapter inside
> Zend_Test_DbAdatper and customize it with vendor-specific db query
> information as needed.
>
> -ralph
>
> Hector Virgen wrote:
>
>> Thanks, Benjamin! Do you know if it will create MySQL-compatible select
>> queries?
>>
>> --
>> Hector
>>
>>
>> On Wed, Aug 19, 2009 at 9:53 AM, Benjamin Eberlei 
>> <[email protected]<mailto:
>> [email protected]>> wrote:
>>
>>    hello hector,
>>
>>    you can use Zend_Test_DbAdapter, which is a testing adapter that
>>    does not
>>    connect to the database.
>>
>>    greetings,
>>    Benjamin
>>
>>    On Wednesday 19 August 2009 06:50:52 pm Hector Virgen wrote:
>>     > Hello,
>>     > I am currently working on an older project that is not in ZF, but
>>    I'd like
>>     > to use Zend_Db_Select to help me build some complex select
>>    queries. I don't
>>     > want to open a new connection to the database since this application
>>     > already has one open using good ol' mysql_connect().
>>     >
>>     > My question is, since Zend_Db uses lazy-loading to create the actual
>>     > connection, would it be safe to create a "dummy" Zend_Db object
>>    to build my
>>     > selects with?
>>     >
>>     > $db = Zend_Db::factory('Pdo_Mysql', array(
>>     >     'host' => '127.0.0.1',
>>     >     'username' => 'fakeuser',
>>     >     'password' => 'fakepassword',
>>     >     'dbname' => 'mydefaultdb'
>>     > ));
>>     >
>>     > $select = $db->select()
>>     > ->from('users');
>>     >
>>     > $sql = $select->toString();
>>     > *echo $sql; // this works and outputs SELECT * FROM `users`*
>>     >
>>     > $select = $db->select()
>>     > ->from('users')
>>     > *->where('username = ?', 'test'); // throws exception:
>>    SQLSTATE[HY000]
>>     > [2013] Lost connection to MySQL server at 'reading initial
>>    communication
>>     > packet', system error: 111*
>>     > It seems that quoteInto() is attempting to connect to the
>>    database. Is this
>>     > necessary? Is there a way to stub in a fake database connection
>>    in order to
>>     > use Zend_Db_Select?
>>     >
>>     > --
>>     > Hector
>>
>>
>>    --
>>    Benjamin Eberlei
>>    http://www.beberlei.de
>>
>>
>>

Reply via email to