[SOLVED] How to get last SQL 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: [SOLVED] How to get last SQL error (/showthread.php?tid=25451) |
[SOLVED] How to get last SQL error - El Forum - 12-12-2009 [eluser]fMertins[/eluser] Hi, I´m using CI without debug database, so when a SQL error occurs, I detect it with something like this (model): Code: $bdok = $this->db->insert('table', $this->mapObj2Array($usua)); Insted of seeing the CI database error page. Then I check for TRUE/FALSE, works fine :-) If got error, gonna have something like this in error file log: ERROR - 2009-12-12 10:29:32 --> Query error: Table 'foo' doesn't exist What I´m trying to do is show this error to user in a view, is it possible to get only the error message, without any format/HTML tags? Something like PHP MySQL function mysql_error()? Thank you! [SOLVED] How to get last SQL error - El Forum - 12-12-2009 [eluser]überfuzz[/eluser] Can't see the point... If there's a mysql error it might be good to know. Use true or false to check whether the query returns anything or not. [SOLVED] How to get last SQL error - El Forum - 12-12-2009 [eluser]fMertins[/eluser] [quote author="überfuzz" date="1260646136"]Can't see the point... If there's a mysql error it might be good to know. Use true or false to check whether the query returns anything or not.[/quote] Hi, thanks for replying :-) I like to show my own page with some messages and the SQL string error. Insted of only know if query was OK or not OK (TRUE/FALSE) would be nice to show the error to user. Something like the DB CI error page, but with my own view (template). [SOLVED] How to get last SQL error - El Forum - 12-12-2009 [eluser]bretticus[/eluser] I assume you are using the mysql driver (the default.) I don't believe error suppression will deactivate mysql_error() from working: Code: echo mysql_errno() . ": " . mysql_error(). "\n"; Worth trying. I also assume when you say "without debug" you mean you have disabled it in the configuration: Code: $db['default']['db_debug'] = FALSE; (which is not the default.) [SOLVED] How to get last SQL error - El Forum - 12-14-2009 [eluser]fMertins[/eluser] Nice, it works! Thank you! |