![]() |
Database Error: Show Line Number - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: Database Error: Show Line Number (/showthread.php?tid=34253) Pages:
1
2
|
Database Error: Show Line Number - El Forum - 09-23-2010 [eluser]wilso417[/eluser] I have a huge site that is using a lot of AJAX and many queries. It is really difficult me to debug database errors without knowing which file and line the query failed. I cannot find a way to turn this on. Any ideas? Database Error: Show Line Number - El Forum - 09-24-2010 [eluser]John_Betong[/eluser] A bit more information would be helpful. Can you show a typical error. Is it your code, GIGO? Are you checking for results? If you are not using a log file then you should. Try this: Code: // Test for YOUR_EXPECTED RESULT Also take a look at the help file on Transactions. Database Error: Show Line Number - El Forum - 09-24-2010 [eluser]wilso417[/eluser] Here is my code: $this->db->select('junk'); $this->db->from('news'); $this->db->where('id', $content_id); Here is my database error that gets outputted on screen: A Database Error Occurred Error Number: 1054 Unknown column 'junk' in 'field list' SELECT `junk` FROM (`news`) WHERE `id` = '160' I would like that error to have the following as well: content_m.php line 360 I have a lot of queries in one page load and it's not easier for me to track down which one is causing an error. Database Error: Show Line Number - El Forum - 09-26-2010 [eluser]John_Betong[/eluser] [quote author="wilso417" date="1285359007"]Here is my code: $this->db->select('junk'); $this->db->from('news'); $this->db->where('id', $content_id); Here is my database error that gets outputted on screen: A Database Error Occurred Error Number: 1054 Unknown column 'junk' in 'field list' SELECT `junk` FROM (`news`) WHERE `id` = '160' I would like that error to have the following as well: content_m.php line 360 I have a lot of queries in one page load and it's not easier for me to track down which one is causing an error.[/quote] I do not understand why you should search for the 'junk' field if it does not exist? I think it is a case of GIGO (Garbage In, Garbage Out). Clean up your input and you should have less errors. Database Error: Show Line Number - El Forum - 09-27-2010 [eluser]billmce[/eluser] If you're developing on localhost check out Xdebug. Database Error: Show Line Number - El Forum - 09-27-2010 [eluser]wilso417[/eluser] I used 'junk' just to give you an example. The question I was trying to get at was below that. My issue is sometimes I have 10+ queries on one page load in multiple models, libraries, etc. and I get a query error and I cannot find which query caused the error. So I was trying to see if I could get CI to output the line number and file on a query error. Is this not possible? Database Error: Show Line Number - El Forum - 09-27-2010 [eluser]John_Betong[/eluser] Try this: Code: function sql_error($method, $line, $sql) Database Error: Show Line Number - El Forum - 09-27-2010 [eluser]wilso417[/eluser] The issue with that is I have to add that if statement to every single query I write. I want the CI database class to do this automatically on query error. Database Error: Show Line Number - El Forum - 09-27-2010 [eluser]John_Betong[/eluser] >>> The issue with that is I have to add that if statement to every single query I write. >>> I want the CI database class to do this automatically on query error. I have just unsuccessfully tried the database.php configuration but could not get it to work on my Localhost. Give it a try and see if it works on you computer. // config/database.php // ['db_debug'] TRUE/FALSE - Whether database errors should be displayed. I also tried PHP try/catch but that did not work. I also tried setting the PHP error_level(0); and that did not work. I would be tempted to test for the $query and act upon the result. Database Error: Show Line Number - El Forum - 09-27-2010 [eluser]wilso417[/eluser] Yes, I have ['db_debug'] = TRUE; That will show me my database error but will not give me the file/line number. I am thinking I would have to somehow extend the db class to accommodate this. I'm just surprised there is not a built in way to do this in CI. |