ZF2 删除查询中的列引号 [英] ZF2 Remove column quotes in query

查看:46
本文介绍了ZF2 删除查询中的列引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一段时间我试图在 ZF2 应用程序中删除我的 mysql 查询的引号.我需要删除引号以使此查询正常工作,通过删除 GEODIST() 周围的引号成功通过命令行测试查询.

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());

输出

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

推荐答案

我找到了以下解决方案,通过使用简单的替换器重置查询来完成这项工作.

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()));

这对我有用.

这篇关于ZF2 删除查询中的列引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆