0

I am trying to diedump the query on my index screen using this line of code:

dd(DB::table('members')->where('name', '=', 'Tycho')->toSql());

Now the problem is that when I am displaying the query on my screen I get this:

"select * from `members` where `name` = ?"

My final goal of these lines of code is that I can save offline queries and execute them when the application is online. Unless someone has a solution for this, I'll have to save the queries in a database.

danielmz02
  • 45
  • 1
  • 5

3 Answers3

2

You are seeing the ? placeholders as Laravel uses Prepared Statements.

See Ijas Ameenudeen's answer on another SO question which details how to add a toRawSql() macro on the Eloquent builder which will replace the placeholders with the bindings that you supplied to the original query.

0

This is because you are using the toSql method, you can use the getBindings method to get the values / bindings.

oneliner:

$query = DB::table('members')->where('name', '=', 'Tycho')->toSql();
// will give the raw query with bindings.
$sqlWithBindings = str_replace_array('?', $query->getBindings(), $query->toSql());

frogeyedman
  • 534
  • 1
  • 5
  • 23
0

You can try this:

    DB::enableQueryLog();
    DB::table('members')->where('name', '=', 'Tycho')->get();
    echo "<pre>";
    print_r(DB::getQueryLog());