Mysql errors

I am using mysql as database with dbi/dbd.

If some error occurs while inserting data in mysql, how to display it or trap it in perl program?
Who is Participating?
thoellriConnect With a Mentor Commented:

are you using perl on Unix or Windows? If you're on UNIX you will have a command called 'perldoc' in the same location where your 'perl' executable is installed. Just type 'perldoc' and let me know what happens. By the way the same should be true for Windows as well. If you happen to have the ActiveState distribution installed you also have a Start-menu entry which points to the "Online Documentation". Try it - you should see a list of all the installed modules in the left most frame after activating the online documentation for ActiveState's perl.

The number of arguments to execute() depends on the SQL code (or statement) you're trying to execute. In my case the code had two "?" which were replaced by "$arg1" and "$arg2". Read the DBI documentation and it'll make sense.

Well you can just paste the code in the there, but I bet you will have troubles.

Again read DBI's documentation and it will all make sense.

Look here for DBI related information:

The DBI homepage

DBI examples by Jeffrey William Baker

Hope this helps

That's totally up to you, but I do have code in place which does something like this:

   $sth=$dbh->prepare("SQL code ...") || errorExit "$DBH::errstr";
   $sth->execute($arg1,$arg2) || errorExit "$DBH::errstr";

where errorExit() is a subroutine that gets the current error message from the failed operation and outputs a line to the error_log identifying the error situation. The user will see a "failed" message and is requested to retry the operation.

Look at the 'perldoc DBI ' pages.

Hope this helps
tripatAuthor Commented:
Thanks for your suggestions.

Pl tell me exact location of
'perldoc DBI'.

Also, I am not passing any parameters in execute statement.

Do I need to download any additional library for it or just paste this code in my program.

thanks agian
All Courses

From novice to tech pro — start learning today.