[Omaha.pm] Changing the current database in DBI

Ryan Stille rps at willconsult.com
Wed Aug 24 07:47:35 PDT 2005


I have a perl script that goes through a list of mysql databases and
does things.  It gets the list of databases from the SHOW DATABASES
command.

As I go through and issue SQL commands in each database, I use
$dbh->do("USE $database"); to change databases.

This worked fine until I added some databases with dashes in their
names.  Now when the script runs I get:

DBD::mysql::db do failed: You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right
syntax to use near '-clientvars' at line 1 at /usr/sbin/mysql_backup.pl
line 27.

I tried adding single quotes around $database, but that didn't help.  If
I use the mysql command line interface, I can use the USE command with
or without quotes, on any database, and it works fine.

Is there perhaps a DBI method I should be using to switch databases?

Thanks,
-Ryan



More information about the Omaha-pm mailing list