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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.