Using FORCE INDEX with zend

I am trying to find how to translate the following MySQL query into Zend Db Table Select:

SELECT ColA,ColB,ColC FROM MyTable FORCE INDEX(ColA,ColB) WHERE ColA = 'val0002' AND ColB = 'val0045' 

I am trying to use something like this:

 $select = $dbTable->select() ->from('MyTable',array('ColA','ColB') ->forceIndex(array('ColA','ColB')) ->where("ColA = 'val0002'") ->where("ColB = 'val0045'"); 

I found "forceIndex (array ('ColA', 'ColB'))" on the forum, but it does not work :(

and thanks for helping me :)

+2
mysql zend-framework zend-db
source share
2 answers

I think Zend_Db_Select does not yet support it. There seems to be a request for improvement here: http://framework.zend.com/issues/browse/ZF-7570

(The comments on the report contain some links to code that may be useful to you).

Hope this helps,

+4
source share

here is a solution that might help the concerned problem:
http://pastie.org/1354770

we can add the following two methods to the zend class "Zend_Db". Hope this helps you as it helped me (but partially).

 /** * Specify index to use * * @return Zend_Db_Select */ public function useIndex($index) { if(empty($this->_parts[self::FORCE_INDEX])) { if(!is_array($index)) { $index = array($index); } $this->_parts[self::USE_INDEX] = $index; return $this; } else { throw new Zend_Db_Select_Exception("Cannot use 'USE INDEX' in the same query as 'FORCE INDEX'"); } } /** * Force index to use * * @return Zend_Db_Select */ public function forceIndex($index) { if(empty($this->_parts[self::USE_INDEX])) { if(!is_array($index)) { $index = array($index); } $this->_parts[self::FORCE_INDEX] = $index; return $this; } else { throw new Zend_Db_Select_Exception("Cannot use 'FORCE INDEX' in the same query as 'USE INDEX'"); } } 
+1
source share

All Articles