PDA

View Full Version : Mysql errors and Perl


clinty
June 12th, 2009, 18:40
Hello.

I use MySQL and shell Scripts to make some jobs. However, Shell is not a good idead to make some queries like SELECT. So, I'm testing Perl. It's better, but I have only one question:

I use this Package (http://search.cpan.org/~capttofu/DBD-mysql-3.0008/lib/Mysql.pm)for MySQL databases. Is it possible to print a msg/stop the program/die the script when the query fail?

Example:

$q = 'SELEEEECT * FROM table;';
$link->query($q)

This query will fail because SELEEECT is not a valid MySQL command. And Perl does not print msg error.

In PHP, is that possible to do this thing:

$q = 'SELEEEECT * FROM table;';
mysql_query($q) or die(mysql_error())

Is that possible in Perl, with Mysql.pm ? I tried die() function, but noting is printed.

Thanks for your advices.

crsd
June 12th, 2009, 18:56
Did you check documentation for p5-DBD-mysql?

check EXAMPLES section at least - http://search.cpan.org/~capttofu/DBD-mysql-4.010/lib/DBD/mysql.pm#EXAMPLE

clinty
June 12th, 2009, 23:19
I do not use p5-DBD-mysql, I use http://search.cpan.org/~capttofu/DBD-mysql-3.0008/lib/Mysql.pm.