ZF2 Remove column quotes in query

╄→гoц情女王★ 提交于 2019-12-11 06:52:05

问题


Since a while I am trying to remove the quotes of my mysql query in a ZF2 application. I need to remove the quotes to make this query works, testing the query over command line succeeded by removing the quotes around GEODIST().

$adapter = $serviceLocator->get('SphinxSearch\Db\Adapter\Adapter');
$sql     = new Sql($adapter);
$select  = new Select;
$select  ->columns(array('*', 'distance' => 'GEODIST(23.3556740442177, 2.9525189115381, latitude, longitude)'))
         ->from('table_name')
         ->where(array('distance > ?' => 250000))
         ->order('distance ASC')
         ->limit(25);

        echo $select->getSqlString(new SphinxQL());

Outputs

SELECT *, `GEODIST(23.3556740442177, 2.9525189115381, latitude, longitude)` AS `distance` FROM `table_name` ORDER BY `distance` ASC LIMIT 0,25

回答1:


I've found the follow solution to make this work by resetting the query with a simple replacer.

$statement = $sql->prepareStatementForSqlObject($select);
$statement ->setSql(str_replace('`', '', $statement->getSql()));

This did the job for me.



来源:https://stackoverflow.com/questions/39593975/zf2-remove-column-quotes-in-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!