title: Laravel DB::statement is not able to prepare values properly for the queries that involves column expressions
body: <p>I wanna know the problem that is arising between DB::statement and DB::unprepared queries, So apparently DB::statement methods are not functioning with queries that do expressions on columns itself, something like this:</p>
  
  <blockquote>
    <p>UPDATE tags SET ? = ? + 2 WHERE ? > ? AND user_id = ? AND tree_id = ?</p>
  </blockquote>
  
  <p>This results into SQL as:</p>
  
  <blockquote>
    <p>UPDATE tags SET rgt = rgt + 2 WHERE rgt > 2 AND user_id = 1 AND tree_id = 1</p>
  </blockquote>
  
  <p>^This query when used within mysql interpreter works absolutely fine but shits brick with laravel's DB::statement method (it works fine with unprepared method btw). </p>
  
  <p>Whats the reason behind this mismatch?</p>
  
  <p>The error it pops up with is <code>SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax</code> which is weird because its correct syntax and already works fine with mysql.</p>
  
  <p>So the statement method is doing this:</p>
  
  <pre><code>    {
          return $this-&gt;run($query, $bindings, function ($query, $bindings) {
              if ($this-&gt;pretending()) {
                  return true;
              }
              $statement = $this-&gt;getPdo()-&gt;prepare($query);
              $this-&gt;bindValues($statement, $this-&gt;prepareBindings($bindings));
              $this-&gt;recordsHaveBeenModified();
              return $statement-&gt;execute();
          });
      }
  </code></pre>
  
  <p>While the unprepared one:</p>
  
  <pre><code>    {
          return $this-&gt;run($query, [], function ($query) {
              if ($this-&gt;pretending()) {
                  return true;
              }
              $this-&gt;recordsHaveBeenModified(
                  $change = ($this-&gt;getPdo()-&gt;exec($query) === false ? false : true)
              );
              return $change;
          });
      }
  </code></pre>
  
  <p>I think the issue is arriving at the <code>prepare</code> method.</p>
  
  <p>Issue References elsewhere that couldn't pinpoint the problem either:</p>
  
  <p>User suggesting that unprepared method should be used for the advanced queries? This query is as basic as it can possibly get: <a href="https://laracasts.com/discuss/channels/general-discussion/raw-queries-1?page=0" rel="nofollow noreferrer">https://laracasts.com/discuss/channels/general-discussion/raw-queries-1?page=0</a></p>
  
  <p>Another user suggesting to use unprepared instead of breaking down to simpler queries: <a href="https://laracasts.com/discuss/channels/laravel/why-does-my-raw-query-not-work-inside-laravel-db?page=2" rel="nofollow noreferrer">https://laracasts.com/discuss/channels/laravel/why-does-my-raw-query-not-work-inside-laravel-db?page=2</a></p>
  
  <p>Bonus Question:
  Moreover, if you know any Eloquent way of handling this query, it'd be awesome! (In the sense how to handle column level expressions via native, where, update, etc methods.)</p>
  
  <p>Edit:
  This question is not a duplicate to <a href="https://stackoverflow.com/questions/20113025/how-to-do-update-query-on-laravel-fluent-using-dbraw">How to do update query on laravel fluent using db::raw</a> because it still involves hardcoding the column value. <code>DB::raw('column * 2')</code></p>
  
  <p>My question is purely from not doing any hardcoding statement and let laravel do the bindings.</p>
  
  <p>For example: This query - </p>
  
  <pre><code>DB::update(DB::raw(
              'UPDATE tags SET ? = ? ? ? WHERE ? &gt;= ? AND user_id = ? AND tree_id = ?'),
              [$flag, $flag, $operator, $integer, $flag, $controlIndex, $user_id, $tree_id]
          );
  </code></pre>
  
  <p>produces error as follows: <code>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 '? = ? ? ? WHERE ? &gt;= ? AND user_id = ? AND tree_id = ?' at line 1 (SQL: UPDATE tags SET rgt = rgt + 2 WHERE rgt &gt;= 1 AND user_id = 1 AND tree_id = 1)
  </code></p>
  
  <p>Just look at the SQL query: <code>UPDATE tags SET rgt = rgt + 2 WHERE rgt &gt;= 1 AND user_id = 1 AND tree_id = 1</code> - This is completely legit and works if put in mysql interpreter!</p>