A
A
Alexander Gontarev2014-07-06 11:57:10
MySQL
Alexander Gontarev, 2014-07-06 11:57:10

How to remove escaping in sql query in ZF2?

Actually, the problem is that the output is a query with escaping all field names, aliases, etc., and this does not allow adding a new value at the output.
What it's about:
an example request in zf2

$sql = new Sql(<адаптер>);
$select = $sql
                ->select()
                ->from(array('v' => 'video'))
                ->columns(array('id','title'))

the output will be something like:
SELECT `v`.`id`, `v`.`title` FROM `video` AS `v`
But if it becomes necessary to add a new value to the select'video' AS 'cat'
->columns(array('id','title', "'cat'" => "'video'"))
- you can not do it this way.
ZF2 escapes these values ​​along with the quotes, which is an error because trying to find the field "cat" in the database
how to generate a query correctly so that these values ​​​​are not escaped?
SELECT `v`.`id`, `v`.`title`, 'video' AS 'cat' FROM `video` AS `v`
- what should be the output

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
yvm, 2014-07-15
@igontarev

->columns(array('id','title',
  'cat' => new \Zend\Db\Sql\Expression('video'),
))

It?

A
Alexander Gontarev, 2014-07-06
@igontarev

this problem can be solved by adding a method
however this is not the solution to all escaping difficulties, are there any other solutions?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question