问题
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