Dikkie Dik wrote:
> > But this will log *every* query, right? Even ones that don't generate
> > an error? That's too much to search for just to find the ones that
> > caused an error, and I don't know if I have enough disk space anyway.
> > Is there a way to log only the error-generating ones?
>
>
> Not from MySQL itself. But any client program you write would surely be
> capable of doing that. For example, in PHP, you can query
> mysql_errno(<connection>) for the code (>0 if error encountered) and
> mysql_error(<connection>) for the message (which is truncated like you
> describe). It is your responsibility as a programmer to check for and
> handle errors.
I tried that. Unfortunately, I ran into the problem that if I input a
query with bad syntax, as soon as I call $sth->execute , the perl
script dies and I have no opportunity to check the error or do anything
else. I read through all the documentation at
http://search.cpan.org/dist/DBD-mysql/lib/DBD/mysql.pm
searching for documentation on "errors" but found nothing. How do I
keep the script going after the invalid syntax is detected?
Here for example:
>>>
my $database_handle =
DBI->connect("DBI:mysql:database=peacefire;host=localh ost",
'root', # username
'<my p***word>', # p***word
{'RaiseError' => 1 }
);
my $querystring = "SELECT FROM THIS QUERY SYNTAX IS DELIBERATELY
INVALID;";
my $sth = $database_handle->prepare($querystring);
# at this point in the code, $database_handle->{'mysql_errno'} is still
empty, I checked
$sth->execute;
# The previous line causes the script to die. How do I instead check
for the syntax error and mail it to myself?
>>>