我从数据库表tableA
获取一些数据,需要在div标记内返回'name'
列。
$divtag1 = '<div style="color:#1569C7; font-weight:bold">';
$select = $this->select()
->from(array('ta' => 'tableA'),
array('ta.id',
'name' => new Zend_Db_Expr("concat($divtag1 . ta.name . '</div>')"),
'date' => new Zend_Db_Expr("date(ta.date)")
));
$result = $this->getAdapter()->fetchAll($select);
我收到错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '
. ta.name . '
') AS `name`, da'
问题是concat()函数正在解释$ divtag1中的引号本身,我不希望这样。 有人可以帮助我做到这一点吗?
感谢您的帮助。
答案 0 :(得分:2)
尝试
'name' => new Zend_Db_Expr("concat('$divtag1', ta.name, '</div>')"),
答案 1 :(得分:0)
有两处更正:
最终解决方案是:
$divtag1 = '<div style="color:#1569C7; font-weight:bold">';
$select = $this->select()
->from(array('ta' => 'tableA'),
array('ta.id',
'name' => new Zend_Db_Expr("concat($divtag1 , ta.name , '</div>')"),
'date' => new Zend_Db_Expr("date(ta.date)")
));
$result = $this->getAdapter()->fetchAll($select);