db_merge() PDO error
The syntax error comes from key being a MySQL reserved keyword.
The best solution is to not use these keywords as identifiers.
 Otherwise the workaround is to enclose them in backticks.

It may work like this:

  [...]
  -&gt;insertFields(array(
           'uid' =&gt; $this-&gt;user-&gt;uid,
            'tid' =&gt; $data['tid'],
            '`key`'    =&gt; $key,
            'value'    =&gt; $value
    ) )
   [...]


However this fails at cross-database compatibility since the backtick is a MySQL-only syntax. Better rename the column if possible.