我尝试使用Doctrine将旧版MySQL查询迁移到TYPO3 8.7。
旧版SQL语句:
SELECT
tt_address.*,
( 6371.41 * acos( cos( radians('.$lat.') ) * cos( radians(tt_address.tx_geosearch_lat ) ) * cos( radians(tt_address.tx_geosearch_lng ) - radians('.$lng.') ) + sin( radians('.$lat.') ) * sin( radians(tt_address.tx_geosearch_lat ) ) ) ) AS distance
FROM tt_address
我尝试使用TYPO3 8.7:
$statement = $queryBuilder
->select(
'tt_address.*',
'( 6371.41 * acos( cos( radians(' . $queryBuilder->createNamedParameter($lat, \PDO::PARAM_STR) . ') ) * cos( radians(tt_address.tx_geosearch_lat ) ) * cos( radians(tt_address.tx_geosearch_lng ) - radians(' . $queryBuilder->createNamedParameter($lng, \PDO::PARAM_STR) . ') ) + sin( radians(' . $queryBuilder->createNamedParameter($lat, \PDO::PARAM_STR) . ') ) * sin( radians(tt_address.tx_geosearch_lat ) ) ) ) AS distance'
)
->from('tt_address')
这导致SQL查询完全损坏:
SELECT `tt_address`.*,
`( 6371`.`41 * acos( cos( radians(48.0818583) ) * cos( radians(tt_address`.`tx_geosearch_lat ) ) * cos( radians(tt_address`.`tx_geosearch_lng ) - radians(11.9879884) ) + sin( radians(48.0818583) ) * sin( radians(tt_address`.`tx_geosearch_lat ) ) ) )` AS `distance`
FROM `tt_address`
有关如何解决此问题的任何指针?
答案 0 :(得分:1)
我不确定querybuilder是否可行。不过,我会通过连接来做到这一点:
$connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable($tableName);
$row = $connection->executeQuery('select * from ' . $tableName . ' where uid = 1')->fetchAll();
答案 1 :(得分:0)
您可以使用addSelectLiteral()
进行查询:
$statement = $queryBuilder
->select(
'tt_address.*'
)
->addSelectLiteral('
6371.41 * acos(
cos(
radians(' . $queryBuilder->createNamedParameter($lat, \PDO::PARAM_STR) . ')
) * cos(
radians(tt_address.tx_geosearch_lat)
) * cos(
radians(tt_address.tx_geosearch_lng) - radians(' . $queryBuilder->createNamedParameter($lng, \PDO::PARAM_STR) . ')
) + sin(
radians(' . $queryBuilder->createNamedParameter($lat, \PDO::PARAM_STR) . ')
) * sin(
radians(tt_address.tx_geosearch_lat)
)
) AS distance
')
->from('tt_address')