CakePHP 3.0: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax

I faced saving data to database using Form in CakePHP 3.0. In backend i am using MySql database. Here is my experiences

A Form of deposit entiry. add.ctp of DepositsController

 //A CakePHP Form
echo $this->Form->create($deposit);
echo $this->Form->input('date');
echo $this->Form->input('profile_id', ['options' => $profiles]);
echo $this->Form->input('amnt');
echo $this->Form->input('desc');
echo $this->Form->input('user_id', ['options' => $users]);
echo $this->Form->button(__('Submit'));
echo  $this->Form->end();

Here is my add function of DepositController

public function add() {
    $deposit = $this->Deposits->newEntity();
    if ($this->request->is('post')) {
        $deposit = $this->Deposits->patchEntity($deposit, $this->request->data);
        if ($this->Deposits->save($deposit)) {
            $this->Flash->success(__('The member deposit has been saved.'));
            return $this->redirect(['action' => 'index']);
        } else {
            $this->Flash->error(__('The member deposit could not be saved. Please, try again.'));
        }
    }
    $profiles = $this->Deposits->Profiles->find('list', ['limit' => 200]);
    $users = $this->Deposits->Users->find('list', ['limit' => 200]);
    $this->set(compact('deposit', 'profiles', 'users'));
}

When i submitted the the Form i found below Database syntex Error

Error: 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 'desc, user_id, created, modified) VALUES ('2015-06-06', 7, '3211', 'some text', 1,' at line 1

And SQL Query was showing:

INSERT INTO member_deposits (date, profile_id, amnt, desc, user_id, created, modified) VALUES (:c0, :c1, :c2, :c3, :c4, :c5, :c6)

I spent plenty of time resolving the issue by Googling and from Similar Post, no luck, but after spending a day i found to get resolve simply configuring quoteIdentifiers to true.

quoteIdentifiers is by default set to false at config/app.php under Datasources of your cake project.

The Problem arises due to the column name of my database table and the reserved word of Mysql is same, which is desc - it is reserved word by mysql. This problem will also resolve if you change the reserved words to anything. Thanks http://dev.mysql.com/doc/refman/5.0/en/keywords.html

Comments

The Problem arises due to column name of my database table, which is desc - it is reserved word by mysql. This problem will also resolve if you change the reserved words to anything. Thanks http://dev.mysql.com/doc/refman/5.0/en/keywords.html

Admin on 6/6/15

Have you say: