• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What's the fastest way to view the queries that AR is submitting to the MySQL database?

#1
[eluser]Craig N[/eluser]
This is driving me slightly nuts - I wrote a simple delete function in my model that for some odd reason isn't working. It's below:

Code:
function delete_entry($id){
        $this->db->where('id',$id);
        $this->db->delete('candidates');
        return ($this->db->affected_rows() > 0) ? TRUE : FALSE;
    }

I've also tried $this->db->delete('candidates',array('id'=>$id)) and $this->db->query("DELETE * FROM candidates WHERE id='$id'"). Neither of those work either. Adding data and updating data using the same model and db table works fine, so I know it's connecting to the db. I've also echo'd out the id of the item to be deleted to make sure that's passing correctly (it is).

It's gotta be something simple, and I'm thinking that being able to actually see the queries that AR is producing would help figure it out. Any help is appreciated Smile

#2
[eluser]FinalFrag[/eluser]
My advice would be to log in on your phpMyAdmin (if you have it on the server) and to try the query from the SQL tab there. If something goes wrong, phpMyAdmin will return you the exact error.

As for how to view the AR queries, I can't help you... I actually think it's not possible.

Hope this helps...

#3
[eluser]Craig N[/eluser]
Yeah, I did that too and it worked fine in phpmyadmin. It's such a simple thing which is why I'm so stumped by it. Argh! lol I could probably modify the AR class to allow for a debug mode that displays db queries, just figured I'd ask if there was already a way to do this.

Thanks for the response Smile

#4
[eluser]Pascal Kriete[/eluser]
Give $this->db->last_query(); a try Wink .

#5
[eluser]johnwbaxter[/eluser]
Or turn on the profiler which will show you the sql for all queries run on that page.

#6
[eluser]Craig N[/eluser]
Sweet, danke! I assume the profiler's in the config file?

*edit - found it. $this->output->enable_profiler(TRUE) just in case anyone else wants to use it. Thanks again Smile

#7
[eluser]johnwbaxter[/eluser]
No problem, i use the profiler a lot, but i also use $this->db->last_query with the log_message() function to have sql in my logs instead of on the front end visible to users.

The choice is yours.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.