![]() |
ActiveRecord Debugging Library - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: ActiveRecord Debugging Library (/showthread.php?tid=19224) Pages:
1
2
|
ActiveRecord Debugging Library - El Forum - 06-01-2009 [eluser]Phil Sturgeon[/eluser] I recently wrote an article on how to debug your ActiveRecord queries but I think it could be even easier. Here is a rough protoype for a VERY simple debugging library that will help output ANY ActiveRecord query. Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); Theoretically (untested) you could run any of your normal commands such as get, getwhere, update, select, etc through $this->db_debug->get(); then it would work fine. For example: Code: $this->db->set('something', $variable); All of these will be logged in the CodeIgniter logs too. Totally untested, just looking for feedback. ActiveRecord Debugging Library - El Forum - 06-01-2009 [eluser]Phil Sturgeon[/eluser] Forgot to mention, this will stop it from running the command. Perhaps I could add another mode or option that would allow it to run the query using parent::query()? ActiveRecord Debugging Library - El Forum - 06-01-2009 [eluser]Yorick Peterse[/eluser] I'd suggest you change addslashes() with mysql_real_escape_string() as addslashes can forget to backslash certain bytevalues that can be used for SQL injections. The second is that I can't really see the query() function being called, or is that just me ? ActiveRecord Debugging Library - El Forum - 06-01-2009 [eluser]Phil Sturgeon[/eluser] query() is used by all of the ActiveRecord functions such as update, delete, etc as ActiveRecord is simply there to build your SQL queries for you. Therefore replacing this central function with the debugging code stops it from running the queery and sends it to scree, log, email etc instead. As for addslashes, this is not important. This query is just going into a textfile anyhow, so it probably doesn't even need anything (other than perhaps htmlentities to stop weird chars getting in there). ActiveRecord Debugging Library - El Forum - 06-01-2009 [eluser]Yorick Peterse[/eluser] [quote author="Phil Sturgeon" date="1243880290"]query() is used by all of the ActiveRecord functions such as update, delete, etc as ActiveRecord is simply there to build your SQL queries for you. Therefore replacing this central function with the debugging code stops it from running the queery and sends it to scree, log, email etc instead. As for addslashes, this is not important. This query is just going into a textfile anyhow, so it probably doesn't even need anything (other than perhaps htmlentities to stop weird chars getting in there).[/quote] *slaps face* Ofcourse, should've known that xD ActiveRecord Debugging Library - El Forum - 06-01-2009 [eluser]johnwbaxter[/eluser] Oh you should definitely make it so that it carries on running the query (or at least allow an extra variable to be passed in to switch that on and off on demand.) ActiveRecord Debugging Library - El Forum - 06-01-2009 [eluser]Phil Sturgeon[/eluser] Was wondering if there is much point, as if you want it to run you could just use db->last_query. Hmm... More opinions on that? If running the query instead of just outputting should be an option, should it be defaulted to true or false? ActiveRecord Debugging Library - El Forum - 06-01-2009 [eluser]johnwbaxter[/eluser] Well because the db->last_query does not e-mail you the sql or write it to the log file? It should probably be defaulted to outputting the output. Those were tough questions! Phew, i need a sit down. ActiveRecord Debugging Library - El Forum - 06-01-2009 [eluser]Phil Sturgeon[/eluser] Ha, true. Ok will think about the best syntax to do that and wrap this one up soon. Probably not tonight, BBQ! ActiveRecord Debugging Library - El Forum - 06-01-2009 [eluser]johnwbaxter[/eluser] oh nice, someone a few doors down from me is having one, all i can smell is relish and roasting meat. God i'm hungry now.... |