Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to get get the sql out put ?
  • I am using following line of code to get some data from database

      $mymembership = Model_Membership::find()->where( array( array("service_id","=", $id)),array("user_id","=",Arr::get($auth->get_user_id(), 1)))->related(array('type'))->get();;


    How can I see the sql stament generated from above code? Because I need to run the run the sql stamement in phpmyadmin to test some outputs (Not for this)
  • HarroHarro
    Accepted Answer
    You can try DB::last_query(), but with ORM you're never sure what the last query was.

    If that doesn't work, enable the profiler in your app/config/config.php, and enable DB profiling in your db.php. The profiler will show all queries executed, with a query analysis (if on MySQL) and execution time info.
  • Thank you for the help. It worked for me
  • To get the query for a specific Model simpy use query() (instead of find()) and then
    echo $mymembership->get_query()->compile();

    PS: Not sure, but you can even try with the find method and then simply call get_query()->compile
  • find() returns the result of a get() or get_one() operation, so it executes the query directly, there is no option to get the intermediate SQL before execution.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion