Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] How to get last SQL error
#1

[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!
#2

[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.
#3

[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).
#4

[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. Smile

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.)
#5

[eluser]fMertins[/eluser]
Nice, it works! Thank you!




Theme © iAndrew 2016 - Forum software by © MyBB