CodeIgniter Forums
Show line number that triggered database error. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Show line number that triggered database error. (/showthread.php?tid=22124)



Show line number that triggered database error. - El Forum - 08-30-2009

[eluser]nicholas.byfleet[/eluser]
I am about ready to pull my hair out. When there is a database error, does anyone know how to print the line # and file that triggered the database error. I am building quite a complicated application and the standard error is practically useless for debugging purposes. Your input would be greatly appreciated. Thanks.


Show line number that triggered database error. - El Forum - 08-30-2009

[eluser]kulldox[/eluser]
I'm doing a little trick for solving such issues.
I'm placing the following code in every method of my controllers:
Code:
log('debug',__FILE__.', '.__LINE__.', '.__CLASS__.'/'.__METHOD__.'/'.__FUNCTION__.'');

This way I know at least what happened before or after that DB error.

Hope this helps.

Sure to this will be sent to log files Smile


Show line number that triggered database error. - El Forum - 08-30-2009

[eluser]InsiteFX[/eluser]
You can find all of this in the CodeIgniter users guide.

users guide error handling

Enjoy
InsiteFX


Show line number that triggered database error. - El Forum - 08-30-2009

[eluser]nicholas.byfleet[/eluser]
Thanks for the link, however this only explains how to show an error. I am trying to find a way to display the line # and file of the controller or model that actually triggered the error. Does that make sense?


Show line number that triggered database error. - El Forum - 08-31-2009

[eluser]InsiteFX[/eluser]
There are no line numbers that you can display unless you create them.

Why not just use a log file and output the the function name.

Enjoy
InsiteFX


Show line number that triggered database error. - El Forum - 08-31-2009

[eluser]kulldox[/eluser]
You could actually do something I wrote before for DB, for ex after every mysql query:

Code:
// here goes the query itself
// then check if there is any error
if(mysql_error()){
    // log the filename and line nuber and all the stuff to the log file
    log_message('debug',__FILE__.', '.__LINE__.', '.__CLASS__.'/'.__METHOD__.'/'.__FUNCTION__.'');
}

Something like this should do the trick.

Or you can use transactions like in the user guide here http://ellislab.com/codeigniter/user-guide/database/transactions.html


Show line number that triggered database error. - El Forum - 04-21-2012

[eluser]Rob Corley[/eluser]
Have a look at this quick and dirty solution:-

http://stackoverflow.com/questions/10259964/get-actual-line-number-or-filename-for-database-error-in-codeigniter