Tutorial :Doctrine Update by DQL + field with parenthesis: “(” and “)”



Question:

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()->getParam('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


Solution:1

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


Solution:2

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

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »