开发者

Doctrine Update by DQL + field with parenthesis: "(" and ")"

I have a doctrine update query to save my data:

$customer = Doctrine_Query::create()

->update('Customer')

->set('fax',"'". $this->getRequest()->getParam('fax')."'")

->where('id ='.$this->getRequest()->getPara开发者_StackOverflow中文版m('id'))

->execute();

The problem is that the field fax has parenthesis and doctrine returns an error in the query because of these parenthesis "(" and ")".

Somebody knows a solution for this? Thank's


$customer = Doctrine_Query::create()
    ->update('Customer')
    ->set('fax', '?', $this->getRequest()->getParam('fax'))
    ->where('id = ?', $this->getRequest()->getParam('id'))
    ->execute();


Not familiar with Doctrine, but what if you escape the parenthesis?

$fax = $this->getRequest()->getParam('fax');
$fax = str_replace(array('(',')'), array('\(','\)'), $fax);

// ...
->set('fax',"'". $fax ."'");

Edit, and it might also be good to sanitize the input to only include numbers, parenthesis and maybe dashes:

// replace everything not 0-9, (, ) or - with nothing
$fax = preg_replace('/[^0-9\(\)\-]/','',$fax);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜