Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Doctrine syntax error with field named "order"

I have the following ajax call

var prev_sibling = $(this).prev().attr("value");
var next_sibling = $(this).next().attr("value");
var order = (prev_sibling + next_sibling)/2; 
var data = {PID:element_id, TGID:parent_id, ORD:order};
$.ajax({
        type: "POST",
        data: data,
        url:"{{ path('v2_pm_patents_dragpatents') }}",
        cache: false
});

And in my action I get the order and set it like this

$order = $request->get('ORD');
$patent->setOrder($order);

but the ajax call give me thew following error

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 'order = '750' WHERE id = '0d0c0810-bc75-11e1-96a5-9787dec335c2'' at line 1 (500 Internal Server Error)

I get the post data correctly and the query which gives me these records is also working fine.

Where is the problem?

Any ideas?

Thanks in advance

like image 410
Zoha Ali Khan Avatar asked Jun 30 '12 23:06

Zoha Ali Khan


1 Answers

The problem is order being a reserved word in MySQL. If you are using doctrine you can tell it to escape reserved words in the mapping like so:

/** @Column(name="`order`", type="integer") */
private $order;

http://docs.doctrine-project.org/en/latest/reference/basic-mapping.html#quoting-reserved-words

like image 119
MDrollette Avatar answered Oct 18 '22 02:10

MDrollette